private void AddComponentRepresentation(PSMSubordinateComponent component) { IModelElementRepresentant componentRepresentant = null; IConnectable connectedChild = null; PSM_ComponentConnector connector = null; if (component is PSMAssociation) { connectedChild = (IConnectable)((PSMAssociation)component).Child; ComponentConnectorViewHelper viewHelper = ((PSMElementViewHelper)((PSMElementViewBase)connectedChild).ViewHelper).ConnectorViewHelper; connector = new PSM_ComponentConnector(XCaseCanavs, SuperordinateRepresentation, connectedChild, viewHelper); } else { componentRepresentant = XCaseCanavs.ElementRepresentations[component]; connectedChild = (IConnectable)componentRepresentant; ComponentConnectorViewHelper viewHelper = ((PSMElementViewHelper)((PSMElementViewBase)connectedChild).ViewHelper).ConnectorViewHelper; connector = new PSM_ComponentConnector(XCaseCanavs, SuperordinateRepresentation, connectedChild, viewHelper); } ComponentData data = new ComponentData() { ComponentRepresentant = componentRepresentant, ConnectedChild = connectedChild, Connector = connector }; ComponentsData[component] = data; }
public override bool CanExecute(object parameter) { if (ActiveDiagramView.Diagram is PSMDiagram && ActiveDiagramView.SelectedItems.Count() == 1) { IModelElementRepresentant representant = ActiveDiagramView.SelectedItems.First() as IModelElementRepresentant; if (representant != null) { Element element = ActiveDiagramView.ElementRepresentations.GetElementRepresentedBy(representant); if (element != null) { Element relatedElement = GetRelatedElement(element); if (relatedElement != null && ActiveDiagramView.ElementRepresentations.IsElementPresent(relatedElement)) { ISelectable selectable = ActiveDiagramView.ElementRepresentations[relatedElement] as ISelectable; if (selectable != null) { return(true); //ActiveDiagramView.SelectedItems.SetSelection(selectable); } } } } } return(false); }
/// <summary> /// Returns model element that is represented by <paramref name="representant"/> /// </summary> /// <param name="representant">The representant.</param> /// <returns>model element for representant</returns> public Element GetElementRepresentedBy(IModelElementRepresentant representant) { if (representedElements.ContainsValue(representant)) { return(representedElements.Keys.Where(key => representedElements[key] == representant).FirstOrDefault()); } return(null); }
/// <summary> /// Handles the ElementAdded event of the Diagram control. /// Creates representation of the added element. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="XCase.Model.ElementAddedEventArgs"/> instance containing the event data.</param> private void Diagram_ElementAdded(object sender, ElementAddedEventArgs e) { if (ElementRepresentations.CanRepresentElement(e.Element)) { Element modelElement = e.Element; ViewHelper visualization = e.Visualization; ElementController elementController; IModelElementRepresentant representant = ElementRepresentations.CreateRepresentant(this, e.Element, out elementController); representant.InitializeRepresentant(modelElement, visualization, elementController); ElementRepresentations.AddElement(modelElement, representant); InvalidateMeasure(); } }
/// <summary> /// Handles the ElementRemoved event of the Diagram control. /// Removes representation of the removed element /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="XCase.Model.ElementRemovedEventArgs"/> instance containing the event data.</param> private void Diagram_ElementRemoved(object sender, ElementRemovedEventArgs e) { if (ElementRepresentations.CanDeleteElement(e.Element)) { IModelElementRepresentant representant = ElementRepresentations[e.Element]; ISelectable selectable = representant as ISelectable; if (selectable != null) { selectable.IsSelected = false; SelectedItems.Remove(selectable); } ElementRepresentations.RemoveElement(e.Element); representant.DeleteFromCanvas(); InvalidateMeasure(); } }
/// <summary> /// Activates given diagram and selects given element on it (used from Properties window) /// </summary> /// <param name="diagram"></param> /// <param name="selectedElement"></param> public void ActivateDiagramWithElement(Diagram diagram, Element selectedElement) { PanelWindow tab = ActivateDiagram(diagram); tab.xCaseDrawComponent.Canvas.SelectedItems.SetSelection(); if (selectedElement != null) { IModelElementRepresentant r = tab.xCaseDrawComponent.Canvas.ElementRepresentations[selectedElement]; if (r != null && r is ISelectable) { tab.xCaseDrawComponent.Canvas.SelectedItems.SetSelection((ISelectable)r); } } MainWindow.InvokeActiveDiagramChanged(tab); }
private void ShowHideComments(bool show) { foreach (Element element in ElementRepresentations.PresentElements) { IModelElementRepresentant modelElementRepresentant = ElementRepresentations[element]; if (modelElementRepresentant != null && modelElementRepresentant is XCaseComment) { XCaseComment comment = (XCaseComment)modelElementRepresentant; if (show) { comment.Show(); } else { comment.Hide(); } } } }
/// <summary> /// Add record of an <paramref name="element"/> and its <paramref name="representant">registration</paramref> /// </summary> /// <param name="element">model element</param> /// <param name="representant">view representation</param> public void AddElement(Element element, IModelElementRepresentant representant) { representedElements.Add(element, representant); }