public void RenameMolecule(IReactionBuilder reactionBuilder, string oldMoleculeName, string newMoleculeName) { // try to keep same location of renamed molecule var reactionNode = ReactionNodeFor(reactionBuilder); //molecule does not exist with the given name: nothing to rename here (might have been renamed already) var oldMoleculeNode = getMoleculeNode(oldMoleculeName, reactionNode.Location, create: false); if (oldMoleculeNode == null) { return; } var oldLocation = oldMoleculeNode.Location; oldMoleculeNode.Location = oldMoleculeNode.Location.Plus(Assets.Diagram.Reaction.OldMoleculeNodeOffsetInRename); var newMoleculeNode = getMoleculeNode(newMoleculeName, reactionNode.Location); newMoleculeNode.Location = oldLocation; newMoleculeNode.ToFront(); UpdateReactionBuilder(reactionBuilder); if (!oldMoleculeNode.IsConnectedToReactions) { DiagramModel.RemoveNode(oldMoleculeNode.Id); } }
// complement and update ViewModel from PkModel and couple ViewModel and PkModel protected override void UpdateDiagramModel(IMoBiSimulation simulation, IDiagramModel diagramModel, bool coupleAll) { // create neighborhoodsContainerNode, because entities are only added // for available parentContainerNodes IContainerNode neighborhoodsContainerNode = AddAndCoupleNode <IContainer, MultiPortContainerNode>(diagramModel, simulation.Model.Neighborhoods, coupleAll); foreach (var baseNode in neighborhoodsContainerNode.GetAllChildren <IBaseNode>()) { baseNode.IsVisible = false; } neighborhoodsContainerNode.IsVisible = false; foreach (var topContainer in simulation.Model.Root.GetAllContainersAndSelf <IContainer>()) { if (topContainer.ContainerType == ContainerType.Organism || topContainer.ContainerType == ContainerType.Organ || topContainer.ContainerType == ContainerType.Compartment) { AddObjectBase(diagramModel, topContainer, true, coupleAll); } } foreach (var neighborhood in simulation.Model.Neighborhoods.GetAllChildren <INeighborhood>()) { AddNeighborhood(neighborhood); } DiagramModel.ClearUndoStack(); }
protected override void UpdateDiagramModel(T reactionBuildingBlock, IDiagramModel diagramModel, bool coupleAll) { var unusedReactionIds = new HashSet <string>(); foreach (var reactionNode in diagramModel.GetAllChildren <ReactionNode>()) { unusedReactionIds.Add(reactionNode.Id); } if (reactionBuildingBlock != null) { foreach (var reactionBuilder in reactionBuildingBlock) { AddObjectBase(diagramModel, reactionBuilder, recursive: true, coupleAll: coupleAll); unusedReactionIds.Remove(reactionBuilder.Id); } } // remove all unused reactionNodes foreach (var reactionBuilderId in unusedReactionIds) { diagramModel.RemoveNode(reactionBuilderId); } DiagramModel.ClearUndoStack(); }
public void AddObjectBase(IObjectBase objectBase) { if (!MustHandleNew(objectBase)) { return; } // Determine parentContainerBase = containerNode of ParentContainer or DiagramModel IContainerBase parentContainerBase = DiagramModel; // if AddedObject is an entity take its parentContainer to find a parentContainerNode var entity = objectBase as IEntity; if (entity?.ParentContainer != null) { parentContainerBase = (IContainerBase)DiagramModel.GetNode(entity.ParentContainer.Id); if (parentContainerBase == null) { return; //do not add container or parameter in containers not shown, e.g. in globalmoleculedependentproperties } // therefore the node for neighborhoodsContainer has to be created (see InitializeWith) } var node = AddObjectBase(parentContainerBase, objectBase, true, true); //because cannot undo this action, reset undo stack if (node != null) { DiagramModel.ClearUndoStack(); } }
private void fixTopContainerNodeLocation(string topContainerId) { var node = DiagramModel.GetNode(topContainerId); node.Location = new PointF(20, 20); node.LocationFixed = true; }
private void addJournalItem(JournalPage page) { var journalPageNode = DiagramModel.GetNode <JournalPageNode>(page.Id) ?? addNewPageNodeFor(page); journalPageNode.ToolTipText = _toolTipCreator.GetToolTipFor(page); journalPageNode.UpdateAttributesFrom(page); }
/// <summary> /// Open saved diagram /// </summary> /// <param name="sender"></param> /// <param name="diagramModel">Diagram for opening</param> private async void DatabaseConnectionSidebarOnAddDiagram(object sender, DiagramModel diagramModel) { Mouse.OverrideCursor = Cursors.Wait; DiagramFacade.CreateNewDiagram(this, diagramModel.Name); LayoutAnchorable panel; if (TryGetSelectedPanel(out panel)) { DatabaseModelDesigner designer; if (TryGetSelectedDesigner(out designer)) { panel.IsActiveChanged -= AnchorableDesignerActiveChangedHandler; var facade = new DiagramFacade(designer.ViewModel); try { await facade.LoadDiagram(designer.ModelDesignerCanvas, XDocument.Parse(diagramModel.Xml)); } catch (Exception exception) when(exception is SqlException || exception is OracleException) { Output.WriteLine(OutputPanelListener.PrepareException(exception.Message)); } panel.IsActiveChanged += AnchorableDesignerActiveChangedHandler; } } await DatabaseConnectionSidebar.RefreshTreeData(); Mouse.OverrideCursor = null; }
public IDiagramModel XmlDocumentToDiagramModel(XmlDocument xmlDoc) { var diagramModel = new DiagramModel(); Deserialize(diagramModel, xmlDoc); return(diagramModel); }
protected virtual INeighborhoodNode AddNeighborhood(INeighborhoodBase neighborhood) { if (neighborhood == null) { return(null); } var firstNeighborContainerNode = NodeFor <IContainerNode>(neighborhood.FirstNeighbor); var secondNeighborContainerNode = NodeFor <IContainerNode>(neighborhood.SecondNeighbor); if (firstNeighborContainerNode == null || secondNeighborContainerNode == null) { return(null); } var neighborhoodNode = NodeFor <TNeighborhoodNode>(neighborhood); if (neighborhoodNode == null) { neighborhoodNode = DiagramModel.CreateNode <TNeighborhoodNode>(neighborhood.Id, CurrentInsertLocation, DiagramModel); neighborhoodNode.Initialize(firstNeighborContainerNode, secondNeighborContainerNode); neighborhoodNode.AdjustPosition(); Update <INeighborhoodBase, TNeighborhoodNode>(neighborhood); Couple(neighborhood, neighborhoodNode); } else { neighborhoodNode.Initialize(firstNeighborContainerNode, secondNeighborContainerNode); neighborhoodNode.AdjustPosition(); Update <INeighborhoodBase, TNeighborhoodNode>(neighborhood); } return(neighborhoodNode); }
protected TNode AddAndCoupleNode <TObject, TNode>(IContainerBase parentContainerBase, TObject objectBase, bool coupleAll) where TObject : class, IObjectBase where TNode : class, IBaseNode, new() { if (objectBase == null) { return(null); } var node = NodeFor <TNode>(objectBase); if (node == null) { node = DiagramModel.CreateNode <TNode>(objectBase.Id, CurrentInsertLocation, parentContainerBase); Update <TObject, TNode>(objectBase); // couple only once at creation Couple(objectBase, node); } else { Update <TObject, TNode>(objectBase); if (coupleAll) { Couple(objectBase, node); // if called by InitializeWith } } return(node); }
public void SaveDiagram(string filename) { DiagramModel diagramModel = new DiagramModel(); Dictionary <NodeBaseViewModel, DiagramNodeBase> nodeDictionary = new Dictionary <NodeBaseViewModel, DiagramNodeBase>(); foreach (var node in diagramViewModel.Nodes) { DiagramNodeBase diagramNode = diagramViewModel.Definition.ViewModelToModel(node); if (diagramNode == null) { continue; } diagramModel.Nodes.Add(diagramNode); nodeDictionary.Add(node, diagramNode); } foreach (var edge in diagramViewModel.Edges) { diagramModel.Edges.Add(new DiagramConnection() { From = nodeDictionary[edge.From], To = nodeDictionary[edge.To] }); } xmlSettings.SaveModel(diagramModel, filename); }
public void RemoveMoleculeNode(IMoleculeNode moleculeNode) { DiagramModel.RemoveNode(moleculeNode.Id); foreach (var reactionNode in moleculeNode.GetLinkedNodes <ReactionNode>()) { UpdateReactionBuilder(PkModel.First(node => node.Id == reactionNode.Id), reactionNode); } }
private IMoleculeNode createMoleculeNode(string name) { var moleculeNode = DiagramModel.CreateNode <MoleculeNode>(Guid.NewGuid().ToString(), GetNextInsertLocation(), DiagramModel); moleculeNode.Name = name; moleculeNode.Description = name; moleculeNode.SetColorFrom(DiagramOptions.DiagramColors); return(moleculeNode); }
public bool MustHandleExisting(string id) { if (string.IsNullOrEmpty(id) || PkModel == null) { return(false); } return(DiagramModel.GetNode(id) != null); }
public void RestoreChronologicalOrder() { if (_journalDiagram == null || !confirmRestoreDiagramLayout()) { return; } DiagramModel.Clear(); refreshAndSave(); }
private JournalPageNode addNewPageNodeFor(JournalPage page) { var lastNode = getLastJournalNode(); var insertLocation = lastNode != null?NextInsertLocationRelativeTo(lastNode) : GetNextInsertLocation(); var journalPageNode = DiagramModel.CreateNode <JournalPageNode>(page.Id, insertLocation, DiagramModel); return(journalPageNode); }
protected void FixLocationFirstVisibleTopContainer() { var topContainers = DiagramModel.GetDirectChildren <IContainerNode>().Where(x => x.Visible).ToList(); if (topContainers.Any()) { topContainers.First().LocationFixed = true; } }
public static DiagramCallNode CreateDiagramCallNode(DiagramModel diagram, IProvideNodes nodeProvider) { var diagramNode = new DiagramCallNode(nodeProvider); var nodeModel = new NodeModel(typeof(DiagramCallNode).FullName); diagramNode.InitializeWithNode(nodeModel); diagramNode.SetReferencingDiagramModelIfNotBroken(diagram); return(diagramNode); }
private void CloseDiagram(DiagramModel diagram) { var diagramViewModel = Items.FirstOrDefault(viewModel => viewModel.Model == diagram); if (diagramViewModel != null) { CloseItem(diagramViewModel); } }
public IHttpActionResult GetTableReport(int id) { try { var context = Repository.HomeContext(); var answerRepository = new Repository <Answer>(context); var allAnswers = new List <Answer>(); var report = new TableReportModel() { TableItems = new List <TableDiagramItem>() }; var allQA = Repository.Get().Where(x => x.Version.Id == id).Select(y => y.QuestionsAndAnswers).ToList(); var allHeuristics = new Repository <Heuristic>(context).Get().ToList(); var listOfQuestionAnswerIds = new List <int>(); foreach (var item in allQA) { foreach (var answeredQuestion in item) { listOfQuestionAnswerIds.Add(answeredQuestion.Id); } } allAnswers.AddRange(answerRepository.Get().Where(x => listOfQuestionAnswerIds.Contains(x.QuestionAnswerId) && x.Level != 0)); var grouped = allAnswers.GroupBy(x => x.HeuristicId).ToList(); var diagramModel = new DiagramModel() { NumberOfAnswers = allAnswers.Count(x => x.Level != 0), HighLevel = allAnswers.Count(x => x.Level == 3), MediumLevel = allAnswers.Count(x => x.Level == 2), LowLevel = allAnswers.Count(x => x.Level == 1), NoLevel = allAnswers.Count(x => x.Level == 0), }; foreach (var group in grouped) { var heuristicId = group.Select(y => y.HeuristicId).FirstOrDefault(); var total = group.Count(x => x.Level != 0); var tableDiagramItemModel = new TableDiagramItem() { Total = total, HighLevel = group.Count(x => x.Level == 3), MediumLevel = group.Count(x => x.Level == 2), LowLevel = group.Count(x => x.Level == 1), Percentage = Math.Round(((double)total / (double)diagramModel.NumberOfAnswers) * 100, 2), DatabaseHeuristicTitle = allHeuristics.FirstOrDefault(x => x.Id == heuristicId).HeuristicTitle }; report.TableItems.Add(tableDiagramItemModel); } report.DiagramModel = diagramModel; return(Ok(report)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void DeleteDiagram(DiagramModel diagram) { CurrentProject.RemoveDiagram(diagram); var diagramViewModel = Diagrams.FirstOrDefault(m => m.Model == diagram); if (diagramViewModel != null) { Diagrams.Remove(diagramViewModel); } }
private void LoadOriginalGraph() { if (!string.IsNullOrEmpty(this.WfInfo.GraphDescription)) { DiagramModel.Load <ActivityNode, ActivityLink>( XElement.Parse(this.WfInfo.GraphDescription), WorkflowUtils.DIAGRAM_XELEMENT_NODENAME, WorkflowUtils.DIAGRAM_XELEMENT_LINKNAME); } }
private void addRelatedItems(JournalPage page) { var journalPageNode = DiagramModel.GetNode <JournalPageNode>(page.Id); page.RelatedItems.Each(relatedItem => addRelatedItem(journalPageNode, relatedItem, findLowestRelatedItem(page))); if (!journalPageNode.IsExpanded) { journalPageNode.Collapse(); } }
public void TestAddNode_NewNode_AddsNodeToNodes() { var dia = new DiagramModel(); Assert.IsTrue(dia.Nodes.IsNullOrEmpty()); dia.AddNode(_nodeMoq.Object); Assert.AreEqual(_nodeMoq.Object, dia.Nodes.First()); }
public void ModelSelect(string id) { if (_view.IsMoleculeNode(DiagramModel.GetNode(id))) { return; } var objectBase = _context.Get <IObjectBase>(id); _context.PublishEvent(new EntitySelectedEvent(objectBase, this)); }
public void TestDeleteDiagram_CallsDeleteDiagramWithSelectedDiagram() { var diagram = new DiagramModel(); _projectManagerMoq.SetupGet(m => m.CurrentDiagrams).Returns(new BindableCollection <DiagramModel> { diagram }); _projectExplorerViewModel.SelectedDiagram = diagram; _projectExplorerViewModel.DeleteDiagram(); _projectManagerMoq.Verify(m => m.DeleteDiagram(It.Is <DiagramModel>(d => d == diagram)), Times.Once); }
public void SetReferencingDiagramModelIfNotBroken(DiagramModel referencingDiagramModel) { if (BrokenDueToRecursion) { return; } ReferencingDiagramModel = referencingDiagramModel; referencingDiagramModel.PropertyChanged += ReferencingDiagramModelPropertyChanged; DiagramName = ReferencingDiagramModel.Name; }
public bool RemoveAndDecoupleNode <TObject, TNode>(TObject objectBase) where TObject : class, IObjectBase where TNode : class, IBaseNode { if (objectBase == null) { return(false); } Decouple <TObject, TNode>(objectBase); DiagramModel.RemoveNode(objectBase.Id); return(true); }
public void TestCopy_CopyEmptyDiagram_NameContainsCopiedName() { var projectManagerMoq = new Mock <IProjectManager>(); var copier = new DiagramCopier(projectManagerMoq.Object); var diagram = new DiagramModel { Name = "d" }; var copiedDiagram = copier.Copy(diagram); Assert.IsTrue(copiedDiagram.Name.Contains(diagram.Name)); }
public void TestCopy_CopyEmptyDiagram_CopiedDiagramIsDifferent() { var projectManagerMoq = new Mock <IProjectManager>(); var copier = new DiagramCopier(projectManagerMoq.Object); var diagram = new DiagramModel { Name = "d" }; var copiedDiagram = copier.Copy(diagram); Assert.AreNotEqual(diagram, copiedDiagram); }
public string GetDataDiagram() { List<DateTime> createdTasks = data.GetTaskCrearedDates(WebSecurity.GetUserId(User.Identity.Name)); DiagramModel diagram = new DiagramModel { name = "Users task activity", data = new List<List<object>>() }; int coordinateX = 0; foreach (var createdTask in createdTasks) { List<object> temp = new List<object>(); temp.Add(new TimeSpan(createdTask.ToLocalTime().ToUniversalTime().Ticks).TotalMilliseconds); temp.Add(coordinateX++); diagram.data.Add(temp); } return JsonConvert.SerializeObject(new List<object> { diagram }); }