/// <summary>
 /// Constructs an instance of a <see cref="ContextMenuControlGraphic"/> with the specified initial context menu actions.
 /// </summary>
 /// <param name="namespace">The namespace to qualify the <paramref name="site"/>.</param>
 /// <param name="site">The action model site for the context menu (see <see cref="ActionPath.Site"/>).</param>
 /// <param name="actions">The set of actions on the context menu.</param>
 /// <param name="subject">The subject graphic.</param>
 public ContextMenuControlGraphic(string @namespace, string site, IActionSet actions, IGraphic subject)
     : base(subject)
 {
     _namespace = @namespace;
     _site      = site;
     _actions   = actions;
 }
Esempio n. 2
0
 protected override Validation <string, Humanoid> CreateService(
     string key,
     string displayName,
     MorphableRace race,
     IEnumerable <IAttribute> attributes,
     IPairedEyeSight vision,
     ILocomotion locomotion,
     Skeleton skeleton,
     IActionSet actions,
     IAnimationManager animationManager,
     KinematicBody node,
     ILoggerFactory loggerFactory)
 {
     return(new Humanoid(
                key,
                displayName,
                race,
                Sex,
                attributes,
                vision,
                locomotion,
                skeleton,
                animationManager,
                actions,
                Optional(Markers).Flatten(),
                node,
                loggerFactory));
 }
        public static bool StartAimAnnotationTool(IImageViewer currentImageViewer)
        {
            if (currentImageViewer == null)
            {
                return(false);
            }

            var        actionPath = new ActionPath(BUTTON_ACTION_PATH, new ResourceResolver(typeof(AimAnnotationTool), true));
            IActionSet actionSet  = currentImageViewer.ExportedActions.Select(action => action.Path.LocalizedPath == actionPath.LocalizedPath);

            if (actionSet != null)
            {
                foreach (IAction action in actionSet)
                {
                    ClickAction clickAction = action as ClickAction;
                    if (clickAction != null)
                    {
                        clickAction.Click();
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 4
0
        public RRTPlanner(
            double goalBias,
            int maximumNumberOfIterations,
            IWorldDefinition world,
            Random random,
            TimeSpan timeStep,
            IGoal goal)
        {
            if (goalBias > 0.5)
            {
                throw new ArgumentOutOfRangeException($"Goal bias must be at most 0.5 (given {goalBias}).");
            }

            this.goalBias = goalBias;
            this.maximumNumberOfIterations = maximumNumberOfIterations;
            this.vehicleModel      = world.VehicleModel;
            this.motionModel       = world.MotionModel;
            this.track             = world.Track;
            this.collisionDetector = world.CollisionDetector;
            this.random            = random;
            this.timeStep          = timeStep;
            this.goal    = goal;
            this.actions = world.Actions;

            distances = new DistanceMeasurement(track.Width, track.Height);

            ExploredStates = exploredStates;
        }
Esempio n. 5
0
		/// <summary>
		/// Constructs an instance of a <see cref="ContextMenuControlGraphic"/> with the specified initial context menu actions.
		/// </summary>
		/// <param name="namespace">The namespace to qualify the <paramref name="site"/>.</param>
		/// <param name="site">The action model site for the context menu (see <see cref="ActionPath.Site"/>).</param>
		/// <param name="actions">The set of actions on the context menu.</param>
		/// <param name="subject">The subject graphic.</param>
		public ContextMenuControlGraphic(string @namespace, string site, IActionSet actions, IGraphic subject)
			: base(subject)
		{
			_namespace = @namespace;
			_site = site;
			_actions = actions;
		}
Esempio n. 6
0
        public WayPointsFollowingRRTPlanner(
            double goalBias,
            int maximumNumberOfIterations,
            IVehicleModel vehicleModel,
            IMotionModel motionModel,
            ITrack track,
            ICollisionDetector collisionDetector,
            Random random,
            TimeSpan timeStep,
            IActionSet actions,
            IReadOnlyList <IGoal> wayPoints)
        {
            if (goalBias > 0.5)
            {
                throw new ArgumentOutOfRangeException($"Goal bias must be at most 0.5 (given {goalBias}).");
            }

            this.goalBias = goalBias;
            this.maximumNumberOfIterations = maximumNumberOfIterations;
            this.vehicleModel      = vehicleModel;
            this.motionModel       = motionModel;
            this.track             = track;
            this.collisionDetector = collisionDetector;
            this.random            = random;
            this.timeStep          = timeStep;
            this.wayPoints         = wayPoints;
            this.actions           = actions;

            distances        = new DistanceMeasurement(track.Width, track.Height);
            wayPointsReached = 0;

            ExploredStates = exploredStates;
        }
Esempio n. 7
0
 /// <summary>
 /// Returns a set that corresponds to the union of this set with another set.
 /// </summary>
 public IActionSet Union(IActionSet other)
 {
     List<IAction> union = new List<IAction>();
     union.AddRange(this);
     union.AddRange(other);
     return new ActionSet(union);
 }
Esempio n. 8
0
		private static void UpdateMouseButtonIconSet(IActionSet actions, XMouseButtons mouseButton)
		{
			foreach (IAction action in actions)
			{
				if (action is Action && action.IconSet is MouseButtonIconSet)
					((Action) action).IconSet = new MouseButtonIconSet(action.IconSet, mouseButton);
			}
		}
Esempio n. 9
0
        /// <summary>
        /// Returns a set that corresponds to the union of this set with another set.
        /// </summary>
        public IActionSet Union(IActionSet other)
        {
            List <IAction> union = new List <IAction>();

            union.AddRange(this);
            union.AddRange(other);
            return(new ActionSet(union));
        }
 protected override IActionSet CreateToolActions()
 {
     if (_toolSet == null)
     {
         _toolSet = new ToolSet(new KeyImageClipboardComponentToolExtensionPoint(), new ClipboardToolContext(this));
     }
     return(_actionSet ?? (_actionSet = new ActionSet(_toolSet.Actions)));
 }
Esempio n. 11
0
 protected override void OnPresentationImageSelected(object sender, PresentationImageSelectedEventArgs e)
 {
     base.OnPresentationImageSelected(sender, e);
     if (_selectedPresentationImage != this.SelectedPresentationImage)
     {
         _selectedPresentationImage = this.SelectedPresentationImage;
         _actions = null;
     }
 }
Esempio n. 12
0
		protected override void OnPresentationImageSelected(object sender, PresentationImageSelectedEventArgs e)
		{
			base.OnPresentationImageSelected(sender, e);
			if (_selectedPresentationImage != this.SelectedPresentationImage)
			{
				_selectedPresentationImage = this.SelectedPresentationImage;
				_actions = null;
			}
		}
        /// <summary>
        /// Gets the context menu <see cref="ActionModelNode"/> based on the current state of the mouse.
        /// </summary>
        public virtual ActionModelNode GetContextMenuModel(IMouseInformation mouseInformation)
        {
            IActionSet actions = this.GetExportedActions("basicgraphic-menu", mouseInformation);

            if (actions == null || actions.Count == 0)
            {
                return(null);
            }
            return(ActionModelRoot.CreateModel(this.ContextMenuNamespace, "basicgraphic-menu", actions));
        }
Esempio n. 14
0
 private static void UpdateMouseButtonIconSet(IActionSet actions, XMouseButtons mouseButton)
 {
     foreach (IAction action in actions)
     {
         if (action is Action && action.IconSet is MouseButtonIconSet)
         {
             ((Action)action).IconSet = new MouseButtonIconSet(action.IconSet, mouseButton);
         }
     }
 }
        public void SelectActionModel(string @namespace, string site, IActionSet actionSet)
        {
            var actionModelId = string.Format(@"{0}:{1}", @namespace, site);

            if (!_componentHosts.ContainsKey(actionModelId))
            {
                var component = new ActionModelConfigurationComponent(@namespace, site, actionSet, Host.DesktopWindow);
                _componentHosts.Add(actionModelId, new HostImplementation(this, component));
            }
            ActiveComponentHost = _componentHosts[actionModelId];
        }
        public override void Start()
        {
            base.Start();

            _toolContext = new StudyFilterToolContext(this);
            _toolset     = new ToolSet(new StudyFilterToolExtensionPoint(), _toolContext);
            _actions     = _toolset.Actions;

            // restore columns from settings
            _columns.Deserialize(_settings.Columns);
        }
Esempio n. 17
0
 protected abstract Validation <string, TCharacter> CreateService(
     string key,
     string displayName,
     TRace race,
     IEnumerable <IAttribute> attributes,
     TVision vision,
     TLocomotion locomotion,
     Skeleton skeleton,
     IActionSet actions,
     IAnimationManager animationManager,
     KinematicBody node,
     ILoggerFactory loggerFactory);
Esempio n. 18
0
 /// <summary>
 /// Returns a set that corresponds to the union of this set with another set.
 /// </summary>
 public IActionSet Union(IActionSet other)
 {
     //This is done for reasons of efficiency. Populating an array of know size is way faster
     //than populating a list that keeps having to adjust its size.
     var union = new IAction[other.Count + Count];
     _actions.CopyTo(union);
     int index = Count;
     foreach (var action in other)
         union[index++] = action;
     
     return new ActionSet(union);
 }
Esempio n. 19
0
        /// <summary>
        /// Called by the host to initialize the application component.
        /// </summary>
        public override void Start()
        {
            base.Start();

            _resolver = new ApplicationThemeResourceResolver(GetType(), true);
            ActionSet  deleteToolActions = new ActionSet(GetDeleteActions());
            var        toolActions       = CreateToolActions();
            IActionSet allActions        = toolActions != null?toolActions.Union(deleteToolActions) : deleteToolActions;

            _toolbarModel     = ActionModelRoot.CreateModel(ToolActionsNamespace, _toolbarSite, allActions);
            _contextMenuModel = ActionModelRoot.CreateModel(ToolActionsNamespace, _menuSite, allActions);

            _items.BindingList.ListChanged += OnBindingListChanged;
        }
        public override void Stop()
        {
            // save columns to settings
            _settings.Columns = _columns.Serialize();

            _actions = null;
            _toolset.Dispose();
            _toolset     = null;
            _toolContext = null;

            _table.Filter();

            base.Stop();
        }
Esempio n. 21
0
        /// <summary>
        /// Gets a set of exported <see cref="IAction"/>s.
        /// </summary>
        /// <param name="site">The action model site at which the actions should reside.</param>
        /// <param name="mouseInformation">The mouse input when the action model was requested, such as in response to a context menu request.</param>
        /// <returns>A set of exported <see cref="IAction"/>s.</returns>
        public override IActionSet GetExportedActions(string site, IMouseInformation mouseInformation)
        {
            IResourceResolver resolver   = new ApplicationThemeResourceResolver(this.GetType(), true);
            string            @namespace = typeof(RoiCalloutGraphic).FullName;

            List <IAction> actions    = new List <IAction>();
            MenuAction     hideAction = new MenuAction(@namespace + ":toggle", new ActionPath(site + "/MenuShowAnalysis", resolver), ClickActionFlags.None, resolver);

            hideAction.GroupHint  = new GroupHint("Tools.Measurements.Display");
            hideAction.Label      = SR.MenuShowAnalysis;
            hideAction.Checked    = this.ShowAnalysis;
            hideAction.Persistent = true;
            hideAction.SetClickHandler(this.ToggleShowAnalysis);
            actions.Add(hideAction);

            if (AllowRename)
            {
                MenuAction renameAction = new MenuAction(@namespace + ":rename", new ActionPath(site + "/MenuRename", resolver), ClickActionFlags.None, resolver);
                renameAction.GroupHint  = new GroupHint("Tools.Measurements.Properties");
                renameAction.Label      = SR.MenuRename;
                renameAction.Persistent = true;
                renameAction.SetClickHandler(this.Rename);
                actions.Add(renameAction);
            }

            IActionSet actionSet = new ActionSet(actions);

            if (this.ShowAnalysis)
            {
                var analyzerActionSets = GetAnalyzersExportedActions(site, mouseInformation);

                if (analyzerActionSets != null)
                {
                    foreach (var set in analyzerActionSets)
                    {
                        actionSet = actionSet.Union(set);
                    }
                }
            }

            IActionSet other = base.GetExportedActions(site, mouseInformation);

            if (other != null)
            {
                actionSet = actionSet.Union(other);
            }

            return(actionSet);
        }
Esempio n. 22
0
        private void DisposeSlaveTools()
        {
            this._actionSet   = null;
            this.SelectedTool = null;

            if (_toolSet != null)
            {
                foreach (T tool in _toolSet.Tools)
                {
                    this.OnToolDisposing(tool);
                }
                _toolSet.Dispose();
                _toolSet = null;
            }
        }
Esempio n. 23
0
		/// <summary>
        /// Builds an in-memory action model from the specified XML model and the specified set of actions.
        /// </summary>
        /// <remarks>
        /// The actions will be ordered according to the XML model.  Any actions that are not a part of the
        /// XML model will be added to the memory model and inserted into the XML model based on a 'group hint'.
		/// The XML model is automatically persisted, and new models that have never before been persisted
		/// will be added.
		/// </remarks>
        /// <param name="namespace">A namespace to qualify the site.</param>
        /// <param name="site">The site.</param>
        /// <param name="actions">The set of actions to include. This set should be prefiltered on <paramref name="site"/>.</param>
        /// <returns>An <see cref="ActionModelNode"/> representing the root of the action model.</returns>
        public ActionModelRoot BuildAndSynchronize(string @namespace, string site, IActionSet actions)
        {
			// do one time initialization
			if(_actionModelXmlDoc == null)
				Initialize();

			string actionModelID = string.Format("{0}:{1}", @namespace, site);

			IDictionary<string, IAction> actionMap = BuildActionMap(actions);

			XmlElement xmlActionModel = Synchronize(actionModelID, actionMap);
			ActionModelRoot modelRoot = Build(site, xmlActionModel, actionMap);

			return modelRoot;
		}
Esempio n. 24
0
        /// <summary>
        /// Builds a map of action IDs to actions.
        /// </summary>
        /// <param name="actions">the set of actions from which to build a map</param>
        /// <returns>a map of action IDs to actions</returns>
        private static IDictionary <string, IAction> BuildActionMap(IActionSet actions)
        {
            var actionMap = new Dictionary <string, IAction>();

            foreach (IAction action in actions)
            {
                actionMap[action.ActionID] = action;

                foreach (var formerActionId in action.FormerActionIDs)
                {
                    actionMap[formerActionId] = action;
                }
            }

            return(actionMap);
        }
Esempio n. 25
0
        /// <summary>
        /// Returns a set that corresponds to the union of this set with another set.
        /// </summary>
        public IActionSet Union(IActionSet other)
        {
            //This is done for reasons of efficiency. Populating an array of know size is way faster
            //than populating a list that keeps having to adjust its size.
            var union = new IAction[other.Count + Count];

            _actions.CopyTo(union);
            int index = Count;

            foreach (var action in other)
            {
                union[index++] = action;
            }

            return(new ActionSet(union));
        }
Esempio n. 26
0
        /// <summary>
        /// Builds an in-memory action model from the specified XML model and the specified set of actions.
        /// </summary>
        /// <remarks>
        /// The actions will be ordered according to the XML model.  Any actions that are not a part of the
        /// XML model will be added to the memory model and inserted into the XML model based on a 'group hint'.
        /// The XML model is automatically persisted, and new models that have never before been persisted
        /// will be added.
        /// </remarks>
        /// <param name="namespace">A namespace to qualify the site.</param>
        /// <param name="site">The site.</param>
        /// <param name="actions">The set of actions to include. This set should be prefiltered on <paramref name="site"/>.</param>
        /// <returns>An <see cref="ActionModelNode"/> representing the root of the action model.</returns>
        public ActionModelRoot BuildAndSynchronize(string @namespace, string site, IActionSet actions)
        {
            // do one time initialization
            if (_actionModelXmlDoc == null)
            {
                Initialize();
            }

            string actionModelID = string.Format("{0}:{1}", @namespace, site);

            IDictionary <string, IAction> actionMap = BuildActionMap(actions);

            XmlElement      xmlActionModel = Synchronize(actionModelID, actionMap);
            ActionModelRoot modelRoot      = Build(site, xmlActionModel, actionMap);

            return(modelRoot);
        }
Esempio n. 27
0
        /// <summary>
        /// Builds the action model for the specified site.
        /// </summary>
        private ActionModelNode BuildActionModel(string site)
        {
            string @namespace = typeof(DesktopWindow).FullName;

            IActionSet actions = this.DesktopTools.Actions;

            if (this.ActiveWorkspace != null)
            {
                actions = actions.Union(this.Workspaces.ActiveWorkspace.Actions);
                if (this.ActiveWorkspace.Component is IApplicationComponent)
                {
                    @namespace = ((IApplicationComponent)this.ActiveWorkspace.Component).GlobalActionsNamespace;
                }
            }

            return(ActionModelRoot.CreateModel(@namespace, site, actions));
        }
Esempio n. 28
0
        /// <summary>
        /// Gets a set of exported <see cref="IAction"/>s.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This mechanism is useful when a particular component defines generally useful <see cref="IAction"/>s
        /// without requiring specific knowledge of the action model sites that the client code uses.
        /// </para>
        /// <para>
        /// Overriding implementations should generally call the base implementation and invoke a <see cref="IActionSet.Union"/>
        /// with any new actions the derived class wishes to provide in order to maintain full functionality of any
        /// control graphics further down in the chain.
        /// </para>
        /// </remarks>
        /// <param name="site">The action model site at which the actions should reside.</param>
        /// <param name="mouseInformation">The mouse input when the action model was requested, such as in response to a context menu request.</param>
        /// <returns>A set of exported <see cref="IAction"/>s.</returns>
        public virtual IActionSet GetExportedActions(string site, IMouseInformation mouseInformation)
        {
            IActionSet actions = new ActionSet();

            foreach (IGraphic graphic in this.EnumerateChildGraphics(true))
            {
                IExportedActionsProvider controlGraphic = graphic as IExportedActionsProvider;
                if (controlGraphic != null)
                {
                    IActionSet otherActions = controlGraphic.GetExportedActions(site, mouseInformation);
                    if (otherActions != null)
                    {
                        actions = actions.Union(otherActions);
                    }
                }
            }
            return(actions);
        }
Esempio n. 29
0
        /// <summary>
        /// Called by the host to initialize the application component.
        /// </summary>
        public override void Start()
        {
            base.Start();

            ClipboardToolContext toolContext = new ClipboardToolContext(this);

            _toolSet = new ToolSet(new ClipboardToolExtensionPoint(), toolContext);

            _resolver = new ApplicationThemeResourceResolver(GetType(), true);
            ActionSet  toolActions       = new ActionSet(_toolSet.Actions);
            ActionSet  deleteToolActions = new ActionSet(GetDeleteActions());
            IActionSet allActions        = toolActions.Union(deleteToolActions);

            _toolbarModel     = ActionModelRoot.CreateModel(typeof(ClipboardComponent).FullName, _toolbarSite, allActions);
            _contextMenuModel = ActionModelRoot.CreateModel(typeof(ClipboardComponent).FullName, _menuSite, allActions);

            _items.BindingList.ListChanged += OnBindingListChanged;
        }
Esempio n. 30
0
        /// <summary>
        /// Gets a set of exported <see cref="IAction"/>s.
        /// </summary>
        /// <param name="site">The action model site at which the actions should reside.</param>
        /// <param name="mouseInformation">The mouse input when the action model was requested, such as in response to a context menu request.</param>
        /// <returns>A set of exported <see cref="IAction"/>s.</returns>
        public override IActionSet GetExportedActions(string site, IMouseInformation mouseInformation)
        {
            IActionSet actions = base.GetExportedActions(site, mouseInformation);

            _lastContextMenuPoint = mouseInformation.Location;

            if (!_canAddRemoveVertices)
            {
                return(actions);
            }

            if (!base.Subject.HitTest(Point.Round(_lastContextMenuPoint)))
            {
                return(actions);
            }

            int  count = this.Subject.Points.Count;
            bool hit   = base.ControlPoints.HitTest(Point.Round(_lastContextMenuPoint));

            IResourceResolver resolver   = new ApplicationThemeResourceResolver(this.GetType(), true);
            string            @namespace = typeof(VerticesControlGraphic).FullName;

            MenuAction insertAction = new MenuAction(@namespace + ":insert", new ActionPath(site + "/MenuInsertVertex", resolver), ClickActionFlags.None, resolver);

            insertAction.GroupHint  = new GroupHint("Tools.Graphics.Edit");
            insertAction.Label      = SR.MenuInsertVertex;
            insertAction.Persistent = true;
            insertAction.SetClickHandler(this.PerformInsertVertex);

            MenuAction deleteAction = new MenuAction(@namespace + ":delete", new ActionPath(site + "/MenuDeleteVertex", resolver), ClickActionFlags.None, resolver);

            deleteAction.GroupHint  = new GroupHint("Tools.Graphics.Edit");
            deleteAction.Label      = SR.MenuDeleteVertex;
            deleteAction.Visible    = hit && count > 1;
            deleteAction.Persistent = true;
            deleteAction.SetClickHandler(this.PerformDeleteVertex);

            return(actions.Union(new ActionSet(new IAction[] { insertAction, deleteAction })));
        }
        public override IActionSet GetExportedActions(string site, ClearCanvas.ImageViewer.InputManagement.IMouseInformation mouseInformation)
        {
            IResourceResolver resolver   = new ResourceResolver(this.GetType(), true);
            string            @namespace = this.GetType().FullName;

            MenuAction hideAction = new MenuAction(@namespace + ":toggle", new ActionPath(site + "/MenuSetMarkupColorForUser", resolver), ClickActionFlags.None, resolver);

            //hideAction.GroupHint = new GroupHint("Tools.Measurements.Display");
            hideAction.Label      = "Set User Markup Color";
            hideAction.Persistent = true;
            hideAction.SetClickHandler(OpenAimMarkupColorOptions);

            IActionSet actions = new ActionSet(new IAction[] { hideAction });
            IActionSet other   = base.GetExportedActions(site, mouseInformation);

            if (other != null)
            {
                actions = actions.Union(other);
            }

            return(actions);
        }
Esempio n. 32
0
        public Humanoid(
            string key,
            string displayName,
            MorphableRace race,
            Sex sex,
            IEnumerable <IAttribute> attributes,
            IPairedEyeSight vision,
            ILocomotion locomotion,
            Skeleton skeleton,
            IAnimationManager animationManager,
            IActionSet actions,
            IEnumerable <Marker> markers,
            KinematicBody node,
            ILoggerFactory loggerFactory) : base(
                key,
                displayName,
                race,
                sex,
                attributes,
                vision,
                locomotion,
                skeleton,
                animationManager,
                actions,
                markers,
                node,
                loggerFactory)
        {
            var groups = Race.MorphGroups.Find(Sex).Flatten().Freeze();
            var morphs = groups.Flatten().Map(d => d.CreateMorph(this, LoggerFactory)).Freeze();

            if (Logger.IsEnabled(LogLevel.Debug))
            {
                morphs.Iter(m => this.LogDebug("Found morph '{}'.", m));
            }

            Morphs = new MorphSet(groups, morphs);
        }
        public HybridAStarPlanner(
            TimeSpan timeStep,
            IWorldDefinition world,
            IReadOnlyList <IGoal> wayPoints,
            bool greedy = false)
        {
            this.timeStep  = timeStep;
            this.greedy    = greedy;
            this.wayPoints = wayPoints;

            vehicleModel      = world.VehicleModel;
            motionModel       = world.MotionModel;
            track             = world.Track;
            actions           = world.Actions;
            collisionDetector = world.CollisionDetector;

            discretizer = new StateDiscretizer(
                positionXCellSize: vehicleModel.Width / 2,
                positionYCellSize: vehicleModel.Width / 2,
                headingAngleCellSize: 2 * Math.PI / 36);

            ExploredStates = exploredStates;
        }
Esempio n. 34
0
        public ActionModelConfigurationComponent(string @namespace, string site, IActionSet actionSet, IDesktopWindow desktopWindow, bool flatActionModel)
        {
            _namespace     = @namespace;
            _site          = site;
            _desktopWindow = desktopWindow;

            if (_desktopWindow is DesktopWindow)
            {
                DesktopWindow concreteDesktopWindow = (DesktopWindow)_desktopWindow;
                if (_site == DesktopWindow.GlobalMenus || _site == DesktopWindow.GlobalToolbars)
                {
                    actionSet = actionSet.Union(concreteDesktopWindow.DesktopTools.Actions);
                }
            }

            _actionModel         = ActionModelSettings.DefaultInstance.BuildAbstractActionModel(_namespace, _site, actionSet.Select(a => a.Path.Site == site));
            _actionModelTreeRoot = new AbstractActionModelTreeRoot(_site);

            _enforceFlatActionModel = flatActionModel;
            if (flatActionModel)
            {
                BuildFlatActionModelTree(_actionModel, _actionModelTreeRoot);
            }
            else
            {
                BuildActionModelTree(_actionModel, _actionModelTreeRoot);
            }

            _actionNodeMapDictionary = new ActionNodeMapDictionary();
            foreach (AbstractActionModelTreeNode node in _actionModelTreeRoot.EnumerateDescendants())
            {
                if (node is AbstractActionModelTreeLeafAction)
                {
                    _actionNodeMapDictionary.AddToMap((AbstractActionModelTreeLeafAction)node);
                }
            }
        }
Esempio n. 35
0
        /// <summary>
        /// Compile the rule.
        /// </summary>
        /// <param name="ruleNode">XML representation of the rule.</param>
        /// <param name="ruleType">The type of the rule.</param>
        /// <param name="specCompiler">An <see cref="XmlSpecificationCompiler"/>.</param>
        /// <param name="actionCompiler">An <see cref="XmlActionCompiler{TActionContext,TTypeEnum}"/>.</param>
        public void Compile(XmlNode ruleNode, TTypeEnum ruleType, XmlSpecificationCompiler specCompiler,
                            XmlActionCompiler <TActionContext, TTypeEnum> actionCompiler)
        {
            var conditionNode =
                CollectionUtils.SelectFirst(ruleNode.ChildNodes,
                                            (XmlNode child) => child.Name.Equals("condition"));

            if (conditionNode != null)
            {
                _conditions = specCompiler.Compile(conditionNode as XmlElement, true);
            }
            else if (!IsDefault)
            {
                throw new ApplicationException("No condition element defined for the rule.");
            }
            else
            {
                _conditions = new AndSpecification();
            }

            var actionNode =
                CollectionUtils.SelectFirst(ruleNode.ChildNodes,
                                            (XmlNode child) => child.Name.Equals("action"));

            if (actionNode != null)
            {
                _actions = actionCompiler.Compile(actionNode as XmlElement, ruleType, true);
            }
            else if (!IsExempt)
            {
                throw new ApplicationException("No action element defined for the rule.");
            }
            else
            {
                _actions = new ActionSet <TActionContext>(new List <IActionItem <TActionContext> >());
            }
        }
        public override void Stop()
        {
            // save columns to settings
            _settings.Columns = _columns.Serialize();

            _actions = null;
            _toolset.Dispose();
            _toolset     = null;
            _toolContext = null;

            _table.Filter();

            base.Stop();

            // dispose any remaining study items now
            if (_masterList.Count > 0)
            {
                foreach (var item in _masterList)
                {
                    item.Dispose();
                }
                _masterList.Clear();
            }
        }
Esempio n. 37
0
		private static IClickAction FindClickAction(KeyboardButtonShortcut shortcut, string @namespace, string site, IActionSet actionSet)
		{
			var actions = ActionModelRoot.CreateModel(@namespace, site, actionSet).GetActionsInOrder();
			foreach (var action in actions)
			{
				var clickAction = action as IClickAction;
				if (clickAction != null && shortcut.Equals(clickAction.KeyStroke))
						return clickAction;
			}

			return null;
		}
Esempio n. 38
0
		/// <summary>
		/// Builds an in-memory abstract action model from the specified XML model and the specified set of known actions.
		/// </summary>
		/// <remarks>
		/// This method functions similarly to <see cref="BuildAndSynchronize"/> except that the resulting action model
		/// consists solely of <see cref="AbstractAction"/>s which are not actually associated with any concrete actions on tools or components.
		/// </remarks>
		/// <param name="namespace">A namespace to qualify the site.</param>
		/// <param name="site">The site.</param>
		/// <param name="actions">The set of actions to include. This set should be prefiltered on <paramref name="site"/>.</param>
		/// <returns>An <see cref="ActionModelNode"/> representing the root of the action model.</returns>
		public ActionModelRoot BuildAbstractActionModel(string @namespace, string site, IActionSet actions)
		{
			// do one time initialization
			if (_actionModelXmlDoc == null)
				Initialize();

			string actionModelId = string.Format("{0}:{1}", @namespace, site);

			IDictionary<string, IAction> actionMap = BuildActionMap(actions);

			XmlElement xmlActionModel = FindXmlActionModel(actionModelId);
			if (xmlActionModel == null)
			{
				xmlActionModel = Synchronize(actionModelId, actionMap);
			}
			else
			{
				// clone the model because we don't want to be modifying the actual action model yet
				xmlActionModel = (XmlElement) xmlActionModel.CloneNode(true);

                //Fix all the group hints.
			    UpdateGroupHints(xmlActionModel, actionMap);

				// if there are new persistent actions that aren't already in the xml, insert them now
				foreach (IAction action in actionMap.Values)
				{
					if (action.Persistent)
					{
						if (AppendActionToXmlModel(_actionModelXmlDoc, xmlActionModel, action))
							Platform.Log(LogLevel.Debug, "Inserted {0}", action.ActionID);
					}
				}

				List<XmlElement> childNodes = GetActionNodeList(xmlActionModel);
				List<IAction> abstractActions = new List<IAction>(childNodes.Count);
				foreach (XmlElement childElement in childNodes)
				{
					if (childElement.Name == "action")
					{
						string actionId = childElement.GetAttribute("id");
						if (string.IsNullOrEmpty(actionId))
						{
							Platform.Log(LogLevel.Debug, "Invalid action model entry with null ID in /action-models/action-model[@id='{0}']", actionModelId);
							continue;
						}

						try
						{
							if (actionMap.ContainsKey(actionId))
							{
								abstractActions.Add(AbstractAction.Create(actionMap[actionId]));
							}
						}
						catch (Exception ex)
						{
							Platform.Log(LogLevel.Debug, ex, "Invalid action model entry at /action-models/action-model[@id='{0}']/action[@id='{1}']", actionModelId, actionId);
						}
					}
				}
				actions = new ActionSet(abstractActions);
				actionMap = BuildActionMap(actions);
			}

			return Build(site, xmlActionModel, actionMap);
		}
Esempio n. 39
0
		/// <summary>
        /// Creates the action model with the specified namespace and site, using the specified
        /// set of actions as input.
        /// </summary>
        /// <remarks>
        /// If an action model specification for the namespace/site
        /// does not exist, it will be created.  If it does exist, it will be used as guidance
        /// in constructing the action model tree.
        /// </remarks>
        /// <param name="namespace">A namespace to qualify the site, typically the class name of the calling class is a good choice.</param>
        /// <param name="site">The site (<see cref="ActionPath.Site"/>).</param>
        /// <param name="actions">The set of actions from which to construct the model.</param>
        /// <returns>An action model tree.</returns>
        public static ActionModelRoot CreateModel(string @namespace, string site, IActionSet actions)
        {
            return ActionModelSettings.DefaultInstance.BuildAndSynchronize(@namespace, site, actions.Select(delegate(IAction action) { return action.Path.Site == site; }));
        }
Esempio n. 40
0
		protected override void OnExternalsChanged(EventArgs e)
		{
			base.OnExternalsChanged(e);
			_actions = null;
		}
Esempio n. 41
0
		/// <summary>
		/// Builds a map of action IDs to actions.
		/// </summary>
		/// <param name="actions">the set of actions from which to build a map</param>
		/// <returns>a map of action IDs to actions</returns>
		private static IDictionary<string, IAction> BuildActionMap(IActionSet actions)
		{
			var actionMap = new Dictionary<string, IAction>();

			foreach (IAction action in actions)
			{
			    actionMap[action.ActionID] = action;

			    foreach (var formerActionId in action.FormerActionIDs)
                    actionMap[formerActionId] = action;
			}

			return actionMap;
		}
Esempio n. 42
0
		/// <summary>
		/// Constructs an instance of a <see cref="ContextMenuControlGraphic"/> with the specified initial context menu actions.
		/// </summary>
		/// <param name="site">The action model site for the context menu (see <see cref="ActionPath.Site"/>).</param>
		/// <param name="actions">The set of actions on the context menu.</param>
		/// <param name="subject">The subject graphic.</param>
		public ContextMenuControlGraphic(string site, IActionSet actions, IGraphic subject)
			: this(string.Empty, site, actions, subject) {}
        /// <summary>
        /// Called by the framework to initialize this tool.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            _actions = CreateActions();
        }
Esempio n. 44
0
		public static ActionPlaceholder GetPlaceholderAction(string site, IActionSet actions, string placeholderActionId)
		{
			string actionId = ":" + placeholderActionId;
			return (ActionPlaceholder) CollectionUtils.SelectFirst(actions, x => x is ActionPlaceholder && x.Path.StartsWith(new Path(site)) && x.ActionID.EndsWith(actionId));
		}