/* POSTPONED
         * /// <summary>
         * /// Creates a local composition set of copies from visual representations of an external composition.
         * /// This manages the referencing of domain based content (idea and table-structure definitions, formats, markers, etc.).
         * /// </summary>
         * public IEnumerable<VisualRepresentation> CreateLocalCompositionCopies(IEnumerable<VisualRepresentation> ExternalCompositionRepresentations)
         * {
         *  // Detect Idea definitions
         *  // Detect Table-Structure definitions
         *
         *
         * }
         *
         * public void ExtendLocalDomainFromExternal(Domain ExternalDomain)
         * {
         *
         * }
         *
         * public class DomainExtensionEquivalences
         * {
         *  public List<ConceptDefinition, ConceptDefinition> ConceptDefinitions; // Local instance, external instance.
         * } */

        /* POSTPONED: This is to obtain recursive composing interrelated content.
         * // It could be later used for entire subgraph cloning, but
         * // consider mapping visual-relationships as subgraph also may contain Views
         * // and therefore interrelated visual-representations
         * public void DetermineInterrelatedIdeas(Idea SourceIdea, IList<Capsule<Idea, Idea>> InterrelationsMap)
         * {
         *  // Return if already considered
         *  if (InterrelationsMap.Any(cap => SourceIdea == cap.Value0))
         *      return;
         *
         *  // Register source Idea
         *  InterrelationsMap.Add(Capsule.Create(SourceIdea, (Idea)null));
         *
         *  // Evaluate associations
         *  foreach (var AssociatedIdea in SourceIdea.AssociatingLinks.Select(link => link.AssociatedIdea))
         *      DetermineInterrelatedIdeas(AssociatedIdea, InterrelationsMap);
         *
         *  // Evaluate composites
         *  foreach (var CompositeIdea in SourceIdea.CompositeIdeas)
         *      DetermineInterrelatedIdeas(CompositeIdea, InterrelationsMap);
         * } */

        public VisualRepresentation AppendShortcut(View TargetView, VisualRepresentation OriginalRepresentation, double DeltaX, double DeltaY)
        {
            var NewPosition = new Point(OriginalRepresentation.MainSymbol.BaseCenter.X + DeltaX,
                                        OriginalRepresentation.MainSymbol.BaseCenter.Y + DeltaY);

            return(AppendShortcut(TargetView, OriginalRepresentation.RepresentedIdea, NewPosition));
        }
示例#2
0
 public void LoadAssets(Dictionary <string, GameObject> assets)
 {
     foreach (string name in assets.Keys)
     {
         _assetDictionary [name] = new VisualRepresentation(assets [name]);
         //yield return null; //slightly annoying to use
     }
     //yield break;
 }
        private static string DetermineTargetRepresentations(View TargetView, Point TargetPosition, ExtensionPanel ExtraOptions, List <Idea> TargetIdeas,
                                                             VisualRepresentation TargetRep, IEnumerable <string> FilePaths)
        {
            string Selection = null;

            if (TargetRep != null)
            {
                TargetIdeas.Clear();
                TargetIdeas.Add(TargetRep.RepresentedIdea);

                if (ExtraOptions != null)
                {
                    Selection = Display.DialogMultiOption("Paste...", "", null, ExtraOptions, true, null,
                                                          new SimplePresentationElement("In selection", PASTE_IN_SELECTEDIDEAS, "Paste into the selected Idea(s).",
                                                                                        Display.GetLibImage("accept.png")));
                    if (Selection.IsAbsent())
                    {
                        return(null);
                    }
                }
            }
            else
            {
                var ConceptDefs = TargetView.OwnerCompositeContainer.CompositeContentDomain.ConceptDefinitions.ToArray();

                Selection = Display.DialogMultiOption("Paste...", "Select Concept type to Create", null, ExtraOptions, true, null, ConceptDefs);
                if (Selection.IsAbsent())
                {
                    return(null);
                }

                if (Selection != VisualComplement.__ClassDefinitor.TechName)
                {
                    TargetIdeas.Clear();
                    var ConceptDef = ConceptDefs.First(cd => cd.TechName == Selection);

                    if (FilePaths == null)
                    {
                        var NewConcept = CreateConceptForPaste(TargetView, TargetPosition, ConceptDef, true);
                        TargetIdeas.Add(NewConcept);
                    }
                    else
                    {
                        FilePaths.ForEachIndexing(
                            (filepath, index) =>
                        {
                            var NewConcept  = CreateConceptForPaste(TargetView, TargetPosition, ConceptDef, index == 0);
                            NewConcept.Name = Path.GetFileNameWithoutExtension(filepath);
                            TargetIdeas.Add(NewConcept);
                        });
                    }
                }
            }

            return(Selection);
        }
示例#4
0
        public override void Initialize()
        {
            OriginRepresentation    = null;
            OriginLocation          = Display.NULL_POINT;
            TargetRepresentation    = null;
            TargetLocation          = Display.NULL_POINT;
            WasKeyShiftPressed      = false;
            WasKeyCtrlPressed       = false;
            IsConnecting            = false; // Very important to clear prior to restart
            PointingConnectorFormat = null;

            base.Initialize();

            var Loader = Display.GetResource <TextBlock>("CursorLoaderArrowIdea");   // Trick for assign custom cursors.

            Display.GetCurrentWindow().Cursor = Loader.Cursor;

            PointingAssistant.Start(this.ContextEngine.CurrentView, this.RelationshipDef.GetSampleDrawing(true), true, Cursors.Cross);
        }
示例#5
0
        public override bool Continue(MouseEventArgs Parameter, bool IsDefinitive = true)
        {
            var Go = base.Continue(Parameter, IsDefinitive);

            if (!Go)
            {
                return(false);
            }

            TargetLocation       = Parameter.GetPosition(this.ContextEngine.CurrentView.PresenterControl);
            TargetRepresentation = this.ContextEngine.GetPointedRepresentation(TargetLocation, false);

            if (IsDefinitive && TargetRepresentation != null)
            {
                var CreationResult = CreateMarker(this.ContextEngine, this.MarkerDef, this.ContextEngine.CurrentView, TargetRepresentation);

                if (CreationResult.WasSuccessful)
                {
                    var CapturedTargetRep = TargetRepresentation;  // Needed because TargetRepresentation is overwritten by fast mouse movement

                    this.ContextEngine.CurrentView.Presenter
                    .PostCall(pres =>       // Post-called in order to be executed after the symbol heading-content area is established (on first draw).
                    {
                        pres.OwnerView.Manipulator.ApplySelection(CapturedTargetRep.MainSymbol);
                    });
                }
                else
                {
                    Console.WriteLine("Cannot create Marker: " + CreationResult.Message.AbsentDefault("?"));
                    this.Terminate();
                    return(false);
                }
            }

            /* Stop the command...
             * this.Terminate(true, Parameter);
             * return false;
             */

            // Continue the command...
            return(true);
        }
        // IMPORTANT: This method is only for creating the Visual-Symbol parts of the representations.
        // Later, the appropriate interconnections should be added.
        public VisualRepresentation AppendClone(View TargetView, VisualRepresentation OriginalRepresentation,
                                                double DeltaX, double DeltaY)
        {
            var NewPosition = new Point(OriginalRepresentation.MainSymbol.BaseCenter.X + DeltaX,
                                        OriginalRepresentation.MainSymbol.BaseCenter.Y + DeltaY);
            VisualRepresentation Result = null;

            if (OriginalRepresentation is ConceptVisualRepresentation)
            {
                var OriginalConceptRep = OriginalRepresentation as ConceptVisualRepresentation;
                var ConceptRepCreation = ConceptCreationCommand.CreateConceptAndRepresentationCopy(OriginalConceptRep, TargetView, NewPosition);
                if (ConceptRepCreation == null || !ConceptRepCreation.WasSuccessful)
                {
                    Console.WriteLine("Cannot append new Concept. Problem: {0}", ConceptRepCreation.Message);
                    return(null);
                }

                Result = ConceptRepCreation.Result;
            }
            else
            {
                var OriginalRelationshipRep = OriginalRepresentation as RelationshipVisualRepresentation;
                var RelationshipRepCreation = RelationshipCreationCommand.CreateRelationshipAndRepresentationCopy(OriginalRelationshipRep, TargetView, NewPosition);
                if (RelationshipRepCreation == null || !RelationshipRepCreation.WasSuccessful)
                {
                    Console.WriteLine("Cannot append new Relationship. Problem: {0}", RelationshipRepCreation.Message);
                    return(null);
                }

                Result = RelationshipRepCreation.Result;
            }

            Result.RepresentedIdea.AddToComposite(TargetView.OwnerCompositeContainer);

            return(Result);
        }
        public VisualRepresentation AppendShortcut(View TargetView, Idea OriginalIdea, Point Position)
        {
            VisualRepresentation Result = null;

            if (OriginalIdea is Concept)
            {
                var RefConcept = (Concept)OriginalIdea;
                Result = ConceptCreationCommand.CreateConceptVisualRepresentation(RefConcept, TargetView, Position, true, true);
            }
            else
            {
                var RefRelationship = (Relationship)OriginalIdea;
                if (RefRelationship.RelationshipDefinitor.Value.IsSimple && RefRelationship.RelationshipDefinitor.Value.HideCentralSymbolWhenSimple)
                {
                    Console.WriteLine("Shortcut omitted for simple Relationship with its Symbol hidden.");
                }
                else
                {
                    Result = RelationshipCreationCommand.CreateRelationshipVisualRepresentation(RefRelationship, TargetView, Position, true);
                }
            }

            return(Result);
        }
示例#8
0
        /// <summary>
        /// Determines whether a working relationship being created/extended can support the creation of a new link.
        /// </summary>
        private static OperationResult <bool> EvaluateLinkability(RelationshipDefinition Definitor, VisualRepresentation OriginRepresentation, VisualRepresentation TargetRepresentation,
                                                                  Relationship PotentialOriginRelationship, Relationship PotentialTargetRelationship, Relationship WorkingRelationship,
                                                                  bool IsForRelink = false)
        {
            OperationResult <bool> CanLink = OperationResult.Success(true);

            if (WorkingRelationship == PotentialOriginRelationship)
            {
                if (!IsForRelink &&
                    WorkingRelationship.RelationshipDefinitor.Value.IsSimple &&
                    WorkingRelationship.Links.Count > 1)
                {
                    CanLink = OperationResult.Failure <bool>("Simple source working relationship already has origin and target connected.");
                }

                /*!? CANCELLED: Inhibits connect a Relationship (thinking that this will extend that Rel links)
                 * if (!IsForRelink
                 *  && CanLink.Result && PotentialTargetRelationship != null
                 *  && PotentialTargetRelationship.RelationshipDefinitor.Value.IsSimple
                 *  && PotentialTargetRelationship.Links.Count > 1)
                 *  CanLink = OperationResult.Failure<bool>("Simple destination working relationship already has origin and target connected."); */

                if (CanLink.Result && TargetRepresentation != null)
                {
                    foreach (var SourceLink in PotentialOriginRelationship.Links.Where(link => link.RoleDefinitor.RoleType != ERoleType.Target))
                    {
                        CanLink = Definitor.CanLink(SourceLink.AssociatedIdea.IdeaDefinitor, TargetRepresentation.RepresentedIdea.IdeaDefinitor);
                        if (CanLink.Result)
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                if (!IsForRelink &&
                    WorkingRelationship.RelationshipDefinitor.Value.IsSimple &&
                    WorkingRelationship.Links.Count > 1)
                {
                    CanLink = OperationResult.Failure <bool>("Simple destination relationship already has origin and target connected.");
                }

                /*!? CANCELLED: Inhibits connect a Relationship (thinking that this will extend that Rel links)
                 * if (!IsForRelink
                 *  && CanLink.Result && PotentialOriginRelationship != null
                 *  && PotentialOriginRelationship.RelationshipDefinitor.Value.IsSimple
                 *  && PotentialOriginRelationship.Links.Count > 1)
                 *  CanLink = OperationResult.Failure<bool>("Simple source relationship already has origin and target connected."); */

                if (CanLink.Result && OriginRepresentation != null)
                {
                    foreach (var DestinationLink in PotentialTargetRelationship.Links.Where(link => link.RoleDefinitor.RoleType == ERoleType.Target))
                    {
                        CanLink = Definitor.CanLink(OriginRepresentation.RepresentedIdea.IdeaDefinitor, DestinationLink.AssociatedIdea.IdeaDefinitor);
                        if (CanLink.Result)
                        {
                            break;
                        }
                    }
                }
            }

            return(CanLink);
        }
示例#9
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));
        }
示例#10
0
        public override bool Continue(MouseEventArgs Parameter, bool IsDefinitive = true)
        {
            var Go = base.Continue(Parameter, IsDefinitive);

            if (!Go)
            {
                return(false);
            }

            if (this.WorkingView == null)
            {
                this.WorkingView = this.ContextEngine.CurrentView;
            }

            if (this.WorkingView != this.ContextEngine.CurrentView)
            {
                this.Terminate();
                return(false);
            }

            this.TargetLocation       = Parameter.GetPosition(this.WorkingView.PresenterControl);
            this.TargetRepresentation = this.ContextEngine.GetPointedRepresentation(this.TargetLocation, true);
            var TargetObject = this.ContextEngine.GetPointedVisualObject(this.TargetLocation, 2.0);

            // IMPORTANT: Get the snapped position AFTER obtain the pointed representation
            if (this.WorkingView.SnapToGrid)
            {
                this.TargetLocation = this.WorkingView.GetGridSnappedPosition(TargetLocation, false);
            }

            this.WasKeyShiftPressed = (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift));
            this.WasKeyCtrlPressed  = (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl));

            if (this.TargetRepresentation != null &&
                !(this.TargetRepresentation.RepresentedIdea.IdeaDefinitor.PreciseConnectByDefault ||
                  this.WasKeyCtrlPressed))
            {
                this.TargetLocation = this.TargetRepresentation.MainSymbol.BaseCenter;
            }

            if (IsDefinitive)   // If selecting a target representation...
            {
                //T Console.WriteLine("Pointed VisObj={0}", TargetObject.ToStringAlways("<NULL>"));

                PointingAssistant.ClearConnector();

                if (!this.IsConnecting)
                {
                    /* Better at definitive target (?)
                     * this.WasKeyCtrlPressed = (Keyboard.IsKeyDown(Key.LeftCtrl)  || Keyboard.IsKeyDown(Key.RightCtrl));
                     * this.WasKeyShiftPressed = (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)); */

                    this.OriginLocation       = Parameter.GetPosition(this.WorkingView.PresenterControl);
                    this.OriginRepresentation = this.ContextEngine.GetPointedRepresentation(this.OriginLocation, true);

                    // IMPORTANT: Get the snapped position AFTER obtain the pointed representation
                    if (this.WorkingView.SnapToGrid)
                    {
                        this.OriginLocation = this.WorkingView.GetGridSnappedPosition(this.OriginLocation, false);
                    }

                    if (this.OriginRepresentation == null)   // Exit if nothing pointed at the beginning
                    {
                        return(true);
                    }

                    if (!this.OriginRepresentation.RepresentedIdea.IdeaDefinitor.PreciseConnectByDefault &&
                        !this.WasKeyCtrlPressed)
                    {
                        this.OriginLocation = this.OriginRepresentation.MainSymbol.BaseCenter;
                    }

                    this.IsConnecting = true;
                    return(true);
                }

                if (this.OriginRepresentation == this.TargetRepresentation)
                {
                    return(true);
                }

                // Needed to discard cancellation from a previous mouse-right-button click.
                this.RestartAfterTermination = true;

                if (this.TargetRepresentation == null && TargetObject != null && TargetObject is VisualComplement)
                {
                    var Complement = (VisualComplement)TargetObject;

                    // NOTE: This don't work if pointing to a complement with null background (it is not seen).
                    if (Complement.CanGroup &&
                        (!Complement.Target.IsGlobal &&
                         Complement.Target.OwnerLocal.OwnerRepresentation.RepresentedIdea.IdeaDefinitor.CanAutomaticallyCreateGroupedConcepts &&
                         Complement.Target.OwnerLocal.OwnerRepresentation.RepresentedIdea.IdeaDefinitor.AutomaticGroupedConceptDef != null))
                    {
                        // PENDING: Create grouped Concept and use it as target-representation.
                        var ConceptDef = Complement.Target.OwnerLocal.OwnerRepresentation.RepresentedIdea.IdeaDefinitor.AutomaticGroupedConceptDef;

                        var Position = this.TargetLocation;

                        if (Complement.IsComplementGroupLine)
                        {
                            var Direction = Complement.GetPropertyField <Orientation>(VisualComplement.PROP_FIELD_ORIENTATION);

                            if (Direction == Orientation.Vertical)
                            {
                                Position = new Point(Complement.BaseCenter.X,
                                                     this.TargetLocation.Y + ((ConceptDef.DefaultSymbolFormat.InitialHeight / 2.0) *
                                                                              (this.TargetLocation.Y >= Complement.Target.OwnerLocal.BaseCenter.Y
                                                                               ? 1.0 : -1.0)));
                            }
                            else
                            {
                                Position = new Point(this.TargetLocation.X + ((ConceptDef.DefaultSymbolFormat.InitialWidth / 2.0) *
                                                                              (this.TargetLocation.X >= Complement.Target.OwnerLocal.BaseCenter.X
                                                                               ? 1.0 : -1.0)),
                                                     Complement.BaseCenter.Y);
                            }
                        }

                        var Creation = ConceptCreationCommand.CreateConcept(this.WorkingView.VisualizedCompositeIdea, ConceptDef,
                                                                            this.WorkingView, Position);
                        if (Creation.WasSuccessful)
                        {
                            this.TargetRepresentation = Creation.Result.VisualRepresentators.First();
                        }
                    }
                }

                var OrigRep = this.OriginRepresentation;
                var TargRep = this.TargetRepresentation;
                var OrigLoc = this.OriginLocation;
                var TargLoc = this.TargetLocation;

                // Allows extend Relationship from alternate origin.
                // Notice that the target (later used as origin) must be not-null.
                if ((Keyboard.IsKeyDown(Key.LeftAlt)) &&
                    !this.WasKeyShiftPressed && TargRep != null)
                {
                    var TmpRep = OrigRep;
                    OrigRep = TargRep;
                    TargRep = TmpRep;

                    var TmpLoc = OrigLoc;
                    OrigLoc = TargLoc;
                    TargLoc = TmpLoc;
                }

                // NOTE: TargetRepresentation can be null, so the intermediate MainSymbol can be created with no targets yet.

                var CreationResult = CreateRelationship(this.WorkingView.VisualizedCompositeIdea,
                                                        this.RelationshipDef,
                                                        this.WorkingView,
                                                        OrigRep, OrigLoc,
                                                        TargRep, TargLoc,
                                                        !this.WasKeyShiftPressed,                                // Extend from origin.
                                                        !(Keyboard.IsKeyDown(Key.RightAlt) &&                    // IMPORTANT: This crashes if applied to a Simple-and-hiding-central-symbol Relationship
                                                          !(this.RelationshipDef.IsSimple &&
                                                            this.RelationshipDef.HideCentralSymbolWhenSimple))); // Extend Relationship, else create Rel. from Rel.

                this.WasKeyShiftPressed = false;
                this.WasKeyCtrlPressed  = false;

                if (CreationResult.WasSuccessful)
                {
                    bool CanSelect = !this.RelationshipDef.HideCentralSymbolWhenSimple;

                    // If a True boolean was passed, indicating to edit-in-place and can select...
                    bool CanEditInPlace = (CreationResult.Parameters.InterpretItem <bool>() && CanSelect);

                    this.OriginRepresentation = CreationResult.Result.VisualRepresentators[0];

                    // Re-start linking from Relationship Central/Main-Symbol center.
                    this.OriginLocation = this.OriginRepresentation.MainSymbol.BaseCenter;

                    this.WorkingView.Presenter
                    .PostCall(pres =>       // Post-called in order to be executed after the symbol heading-content area is established (on first draw).
                    {
                        var Symbol = CreationResult.Result.VisualRepresentators[0].MainSymbol;
                        if (CanSelect)
                        {
                            pres.OwnerView.Manipulator.ApplySelection(Symbol);
                        }

                        if (CanEditInPlace)
                        {
                            pres.OwnerView.EditInPlace(Symbol);
                        }
                    });

                    // PENDING: Also quit if role is non multi-connectable
                    if (this.RelationshipDef.IsSimple)
                    {
                        var RelationshipRep = CreationResult.Context as RelationshipVisualRepresentation;

                        if (RelationshipRep != null)
                        {
                            if (RelationshipRep.VisualConnectorsCount > 1)
                            {
                                return(false);
                            }
                            else
                            if (!RelationshipDef.HideCentralSymbolWhenSimple)
                            {
                                RelationshipRep.MainSymbol.IsAutoPositionable = false;
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    this.IsConnecting = false;
                    Console.WriteLine("Cannot create/change Relationship: " + CreationResult.Message.AbsentDefault("?"));
                    this.Terminate();

                    return(false);
                }
            }
            else    // Else, if just pointing...
            {
                if (this.IsConnecting && this.OriginRepresentation != null)
                {
                    if (this.PointingConnectorFormat == null)
                    {
                        this.PointingConnectorFormat = new VisualConnectorsFormat(this.RelationshipDef.OwnerDomain.LinkRoleVariants.First(), Plugs.None,
                                                                                  this.RelationshipDef.OwnerDomain.LinkRoleVariants.First(), Plugs.SimpleArrow,
                                                                                  DefaultPointingConnectorBrush);
                    }

                    var OrigPlug = Plugs.None;
                    var TargPlug = Plugs.SimpleArrow;

                    if ((Keyboard.IsKeyDown(Key.LeftAlt)) &&
                        !this.WasKeyShiftPressed)
                    {
                        var TmpPlug = OrigPlug;
                        OrigPlug = TargPlug;
                        TargPlug = TmpPlug;
                    }

                    var GraphicPointer = MasterDrawer.CreateDrawingConnector(OrigPlug, TargPlug,
                                                                             this.PointingConnectorFormat.LineBrush, this.PointingConnectorFormat.LineThickness,
                                                                             this.PointingConnectorFormat.LineDash, this.PointingConnectorFormat.LineJoin,
                                                                             this.PointingConnectorFormat.LineCap, this.PointingConnectorFormat.PathStyle,
                                                                             this.PointingConnectorFormat.PathCorner, this.PointingConnectorFormat.MainBackground,
                                                                             this.PointingConnectorFormat.Opacity,
                                                                             this.TargetLocation, this.OriginLocation);
                    PointingAssistant.PutConnector(GraphicPointer);

                    this.RestartAfterTermination = true;
                }
            }

            // Continue the command...
            return(true);
        }
示例#11
0
        CreateMarker(EntityEditEngine Engine, MarkerDefinition Definitor, View TargetView, VisualRepresentation TargetRepresentator = null)
        {
            General.ContractRequiresNotNull(Engine, Definitor, TargetView);

            Engine.StartCommandVariation("Create Marker");

            var NewMarker = CreateMarkerAssignment(Engine, Definitor);

            if (NewMarker != null)
            {
                var RedisplayView = false;

                if (!TargetView.ShowMarkers)

                /* if (Display.DialogMessage("Attention", "View is not currently showing Markers.\nDo you want to show them?",
                 *                        EMessageType.Question, MessageBoxButton.YesNo, MessageBoxResult.Yes) == MessageBoxResult.Yes) */
                {
                    TargetView.ShowMarkers = true;
                    RedisplayView          = true;
                }

                if (TargetRepresentator == null)
                {
                    foreach (var Representator in TargetView.SelectedRepresentations)
                    {
                        Representator.RepresentedIdea.Markings.Add(NewMarker);
                        if (!RedisplayView)
                        {
                            Representator.Render();
                        }
                    }
                }
                else
                {
                    TargetRepresentator.RepresentedIdea.Markings.Add(NewMarker);
                    if (!RedisplayView)
                    {
                        TargetRepresentator.Render();
                    }
                }

                if (RedisplayView)
                {
                    TargetView.ShowAll();
                }
            }

            if (TargetRepresentator != null)
            {
                TargetRepresentator.RepresentedIdea.UpdateVersion();
            }

            Engine.CompleteCommandVariation();

            return(OperationResult.Success(NewMarker));
        }
        private static ExtensionPanel CreatePastingExtraOptions(ExtensionPanel ExtraOptions, VisualRepresentation TargetRep, IEnumerable <string> FilePaths)
        {
            ExtraOptions = ExtensionPanel.Create()
                           .AddGroupPanel("Pasting options...")
                           .AddSelectableOption(PASTE_AS_MAINCONTENT, "As main content", true,
                                                "The pasted object is intended as Summary (when text) or Pictogram (if image).")
                           .AddSelectableOption(PASTE_AS_DETAIL, "As detail", false,
                                                "The pasted object must be appended as detail.");

            if (TargetRep == null && FilePaths.CountsAtLeast(2))
            {
                ExtraOptions.AddSwitchOption(PASTE_MULTI_TARGETS, "Create multiple targets", true, "Create multiple targets (Concepts or Complements), one per each source file.");
            }

            var ButtonPasteAsComplement = new PaletteButton("As Text/Image Complement", Domain.ComplementDefImage.Pictogram);

            ButtonPasteAsComplement.MinHeight = 32;
            ButtonPasteAsComplement.Summary   = "Paste as a Text/Image Complement in the background";
            ButtonPasteAsComplement.Click    +=
                ((sender, args) =>
            {
                var OwnerWindow = ButtonPasteAsComplement.GetNearestVisualDominantOfType <Window>();
                if (OwnerWindow == null)
                {
                    return;
                }

                Display.SelectedOptionText = VisualComplement.__ClassDefinitor.TechName;
                OwnerWindow.Close();
            });
            ExtraOptions.Children.Add(ButtonPasteAsComplement);
            return(ExtraOptions);
        }