예제 #1
0
        private async Task <AnnotationModel> UpdateAnnotation(AnnotationModel model)
        {
            var entity = await _annotations
                         .Include(a => a.CreatedUser)
                         .Include(a => a.Target)
                         .Include(a => a.Group)
                         .Include(a => a.License)
                         .Include(a => a.AnnotationType)
                         .Include(a => a.Tags).ThenInclude(at => at.Tag)
                         .FirstOrDefaultAsync(a => a.AnnotationId == model.Id);

            if (entity != null)
            {
                entity             = model.ToEntity(entity);
                entity.UpdatedDate = DateTime.UtcNow;
                await _unitOfWork.SaveChangesAsync();

                var updated = entity.ToModel();
                return(updated);
            }
            else
            {
                throw new NotFoundException($"Annotation with id {model.Id} not found.");
            }
        }
예제 #2
0
        public async Task <IViewComponentResult> InvokeAsync(string entityName, string recordId)
        {
            ApplicationUser curUser = await Helpers.Common.GetCurrentUser(_userManager, HttpContext.User);

            curUser = curUser == null ? new ApplicationUser() : curUser;
            var annotations = await _context.Annotation.Select(n => new Annotation
            {
                Annotation_Id = n.Annotation_Id,
                ObjectName    = n.ObjectName,
                ObjectId      = n.ObjectId,
                CreatedBy     = n.CreatedBy,
                CreatedOn     = n.CreatedOn,
                FileName      = n.FileName,
                FileSize      = n.FileSize,
                Id            = n.Id,
                IsDocument    = n.IsDocument,
                IsPrivate     = n.IsPrivate,
                MimeType      = n.MimeType,
                ModifiedBy    = n.ModifiedBy,
                ModifiedOn    = n.ModifiedOn,
                NoteText      = n.NoteText,
                Subject       = n.Subject
            }).Where(n => n.ObjectName == entityName && n.ObjectId == recordId &&
                     (!n.IsPrivate || (n.IsPrivate && n.CreatedBy == curUser.Id))).
                              OrderByDescending(n => n.CreatedOn).ToListAsync();

            List <AnnotationViewModel> notesModel = new List <AnnotationViewModel>();

            foreach (var note in annotations)
            {
                notesModel.Add(new AnnotationViewModel
                {
                    Annotation_Id = note.Annotation_Id,
                    ObjectName    = note.ObjectName,
                    ObjectId      = note.ObjectId,
                    CreatedBy     = Helpers.Common.ResolveUser(_context, note.CreatedBy),
                    CreatedOn     = note.CreatedOn,
                    FileName      = note.FileName,
                    FileSize      = note.FileSize,
                    Id            = note.Id,
                    IsDocument    = note.IsDocument,
                    IsPrivate     = note.IsPrivate,
                    MimeType      = note.MimeType,
                    ModifiedBy    = Helpers.Common.ResolveUser(_context, note.CreatedBy),
                    ModifiedOn    = note.ModifiedOn,
                    NoteText      = note.NoteText,
                    Subject       = note.Subject
                });
            }

            AnnotationModel notes = new AnnotationModel
            {
                EntityName    = entityName,
                RecordId      = recordId,
                CurrentUserId = curUser.Id,
                Notes         = notesModel
            };

            return(View(notes));
        }
예제 #3
0
        private async Task <AnnotationModel> AddAnnotation(AnnotationModel model)
        {
            var target = model.Target?.ToEntity();

            if (target != null && target.AnnotationTargetId < 1)
            {
                await _annotationTargets.AddAsync(target);
            }

            var entity = model.ToEntity();

            entity.AnnotationTargetId = target.AnnotationTargetId;
            entity.CreatedDate        = DateTime.UtcNow;
            entity.CreatedUserId      = model.CreatedUserId;
            entity.GroupId            = model.GroupId;

            await _annotations.AddAsync(entity);

            await _unitOfWork.SaveChangesAsync();

            var added = await _annotations
                        .Include(a => a.CreatedUser)
                        .Include(a => a.Target)
                        .Include(a => a.Group)
                        .Include(a => a.License)
                        .Include(a => a.AnnotationType)
                        .Include(a => a.Tags).ThenInclude(at => at.Tag)
                        .SingleOrDefaultAsync(a => a.AnnotationId == entity.AnnotationId);

            return(added.ToModel());
        }
예제 #4
0
 internal void RecordGroupModelBeforeUngroup(AnnotationModel annotation)
 {
     using (undoRecorder.BeginActionGroup()) // Start a new action group.
     {
         undoRecorder.RecordModificationForUndo(annotation);
     }
 }
예제 #5
0
        public async Task <IActionResult> CreateAnnotation([FromBody] AnnotationModel model)
        {
            var newAnnotation = new Annotation();

            try
            {
                if (!ModelState.IsValid)
                {
                    ValidModel();
                }
                newAnnotation = new Annotation()
                {
                    IsChecked = model.IsChecked,
                    StudentId = model.StudentId,
                    Type      = model.Type,
                    Content   = model.Content
                };
                await _service.AnnotationService.AddAsync(newAnnotation);
            }
            catch (Exception e)
            {
                return(ErrorResult(e.Message));
            }
            return(SuccessResult(newAnnotation, "Created Annotation successfully."));
        }
예제 #6
0
        public static AnnotationModel ToModel(this Annotation entity, bool includeChildren = true)
        {
            AnnotationModel model = null;

            if (entity != null)
            {
                model = new AnnotationModel
                {
                    Id               = entity.AnnotationId,
                    Body             = entity.Body,
                    TargetId         = entity.AnnotationTargetId,
                    Target           = entity.Target?.ToModel(),
                    CreatedDate      = entity.CreatedDate,
                    UpdatedDate      = entity.UpdatedDate,
                    CreatedUser      = entity.CreatedUser?.Email,
                    UpdatedUser      = entity.UpdatedUser?.Email,
                    GroupId          = entity.GroupId,
                    GroupName        = entity.Group?.GroupName,
                    CreatedUserId    = entity.CreatedUserId,
                    UpdatedUserId    = entity.UpdatedUserId,
                    LicenseId        = entity.LicenseId,
                    License          = entity.License?.ToModel(),
                    AnnotationTypeId = entity.AnnotationTypeId,
                    AnnotationType   = entity.AnnotationType?.ToModel(),
                    Annotations      = includeChildren ? entity.Annotations?.ToList().ConvertAll(a => a.ToModel()) : new List <AnnotationModel>(),
                    ParentId         = entity.ParentId,
                    Tags             = entity.Tags?.ToList().ConvertAll(t => t.ToTagModel())
                };
            }

            return(model);
        }
예제 #7
0
        private void AnnotateButtonClick()
        {
            // TODO: check if tracking

            byte[] png;
            if (DebugImage != null)
            {
                png = DebugImage.EncodeToPNG();
            }
            else
            {
                png = ArUtils.GetCameraImage(ARInterface.GetInterface());
                if (png == null)
                {
                    return;
                }
            }

            var imageModel = new ImageModel(png);

            imageModel.Save();
            var annotationModel =
                new AnnotationModel(
                    new Pose(Camera.main.transform.position, Camera.main.transform.rotation),
                    Camera.main.aspect,
                    imageModel);

            annotationModel.Save();
            AddAnnotation(annotationModel);
        }
예제 #8
0
        public IActionResult Annotation([FromBody] AnnotationModel model)
        {
            var annotation = ModelFactory.MapAnnotation(model);

            //return Ok(DataService.AddAnnotation(annotation));
            return(Ok(DataService.AddAnnotation(annotation)));
        }
예제 #9
0
        internal static AnnotationModel LoadAnnotationFromXml(XmlNode annotation, IEnumerable <NodeModel> nodes, IEnumerable <NoteModel> notes)
        {
            var instance = new AnnotationModel(nodes, notes);

            instance.Deserialize(annotation as XmlElement, SaveContext.File);
            return(instance);
        }
예제 #10
0
 public Annotation Parse(AnnotationModel model)
 {
     return new Annotation
     {
         Body = model.Body,
         Date = model.Date
     };
 }
예제 #11
0
 void Awake()
 {
     SocketService.GetInstance().OnCreate["annotation"] = json =>
     {
         var annotationModel = new AnnotationModel(json);
         AddAnnotation(annotationModel);
     };
 }
예제 #12
0
 public void Update(AnnotationModel _annotation)
 {
     using (ISession session = NHibernateHelper.OpenSession())
         using (ITransaction transaction = session.BeginTransaction())
         {
             session.Update(_annotation);
             transaction.Commit();
         }
 }
예제 #13
0
        public IActionResult AnnotationDummy(AnnotationModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewData["IsError"] = "Fehler verursacht";
            }

            return(View(model));
        }
예제 #14
0
        private void AddAnnotation(AnnotationModel annotationModel)
        {
            var annotationController = Instantiate(AnnotationPrefab);

            annotationController.Setup(annotationModel);
            annotationController.TargetPosition       = AnchorPosition.transform;
            annotationController.OnLeaveInactiveMode += OnAnnotationControllerSelect;
            annotationController.OnInactiveMode      += OnAnnotationControllerDeselect;
            MapCanvasController.AddAnnotation(annotationController);
        }
예제 #15
0
        public AnnotationViewModel(WorkspaceViewModel workspaceViewModel, AnnotationModel model)
        {
            annotationModel         = model;
            this.WorkspaceViewModel = workspaceViewModel;
            model.PropertyChanged  += model_PropertyChanged;
            // Group is created already.So just populate it.
            var selectNothing = new DynamoModel.SelectModelCommand(Guid.Empty, System.Windows.Input.ModifierKeys.None.AsDynamoType());

            WorkspaceViewModel.DynamoViewModel.ExecuteCommand(selectNothing);
        }
예제 #16
0
            public static void AddAnnotation(AnnotationModel a)
            {
                DataVariables._annotationRepo.Add(a);
                DataVariables.Active_Annotation = a;
                DataVariables.Annotations.Add(DataVariables.Active_Annotation);
                DataVariables.Annotations = DataVariables.Annotations.Where(x => x.HideShowRow == false).ToList();//.OrderByDescending(x => x.Date_Time < DateTime.Now).ToList();
                DataVariables.Annotations.Sort((x, y) => x.Date_Time.CompareTo(y.Date_Time));

                DataVariables.Annotations.Reverse();
            }
예제 #17
0
 public void Remove(AnnotationModel _annotation)
 {
     //using (ISession session = NHibernateHelper.OpenSession())
     //using (ITransaction transaction = session.BeginTransaction())
     {
         //session.Delete(_annotation);
         //transaction.Commit();
         Update(_annotation);
     }
 }
예제 #18
0
        public IActionResult Put(int id, [FromBody] AnnotationModel model)
        {
            var annotation = ModelFactory.MapAnnotation(model);

            annotation.AnnotationId = id;
            if (!DataService.UpdateAnnotation(annotation))
            {
                return(NotFound());
            }
            return(Ok());
        }
예제 #19
0
        public IActionResult GetAnnotration(int Pid)
        {
            var annot           = _repository.GetAnnotationById(Pid);
            var annotationModel = new AnnotationModel();

            annotationModel.MarkingLink      = Url.Link(nameof(MarkingController.GetMarking), new { Pid = annot.MarkedPostId });
            annotationModel.AnnotationText   = annot.Annotation;
            annotationModel.EditAnnotation   = Url.Link(nameof(AnnotationController.EditAnnotation), new { AnnotId = annot.Annotationid, text = annot.Annotation });
            annotationModel.RemoveAnnotation = Url.Link(nameof(AnnotationController.RemoveAnnotation), new { AnnotId = annot.Annotationid });
            return(Ok(annotationModel));
        }
예제 #20
0
 public AnnotationModel GetByName(string name)
 {
     using (ISession session = NHibernateHelper.OpenSession())
     {
         AnnotationModel _annotation = session
                                       .CreateCriteria(typeof(AnnotationModel))
                                       .Add(Restrictions.Eq("Name", name))
                                       .UniqueResult <AnnotationModel>();
         return(_annotation);
     }
 }
        public IActionResult EditAnnotation(AnnotationModel model)
        {
            if (ModelState.IsValid)
            {
                _context.Annotations.Update(model);
                _context.SaveChanges();
                return(RedirectToAction("Annotations"));
            }

            return(View(model));
        }
        public IActionResult EditAnnotation(Guid id)
        {
            AnnotationModel ann = _context.Annotations.FirstOrDefault(x => x.ID == id);

            if (ann != null)
            {
                return(View(ann));
            }

            TempData["Error"] = "Nie znaleziono obiektu o podanym ID.";
            return(RedirectToAction("Annotations"));
        }
예제 #23
0
        public async Task <IActionResult> UploadAttachment(AnnotationModel newAttachment)
        {
            bool uploaded = await UploadAttachmentDragDrop(newAttachment);

            if (uploaded)
            {
                return(RedirectToAction("Details", "HRCase", new { id = newAttachment.CaseId }, "tabAttachments"));
            }
            else
            {
                return(null);
            }
        }
예제 #24
0
        public IActionResult AddAnnotation(int Pid, [FromBody] AnnotationModel obj)
        {
            var addedAnnotation = _repository.AddAnnotation(Pid, obj.AnnotationText, (int)obj.From, (int)obj.To);
            var annotationModel = new AnnotationModel();

            annotationModel.MarkingLink      = Url.Link(nameof(MarkingController.GetMarking), new { Pid = addedAnnotation.MarkedPostId });
            annotationModel.AnnotationText   = addedAnnotation.Annotation;
            annotationModel.From             = obj.From;
            annotationModel.To               = obj.To;
            annotationModel.EditAnnotation   = Url.Link(nameof(AnnotationController.EditAnnotation), new { AnnotId = addedAnnotation.Annotationid, text = addedAnnotation.Annotation });
            annotationModel.RemoveAnnotation = Url.Link(nameof(AnnotationController.RemoveAnnotation), new { AnnotId = addedAnnotation.Annotationid });
            return(Created($"api/marking/{Pid}/annotation", annotationModel));
        }
        public IActionResult AddAnnotation(AnnotationModel model)
        {
            if (ModelState.IsValid)
            {
                _context.Annotations.Add(model);
                _context.SaveChanges();

                return(RedirectToAction("Annotations"));
            }

            ViewBag.Usr = _usermanager.GetUserId(User);
            return(View(model));
        }
예제 #26
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var workspaceView = (WorkspaceViewModel)value;

            writer.WriteStartObject();

            writer.WritePropertyName("Dynamo");
            serializer.Serialize(writer, workspaceView.DynamoPreferences);

            writer.WritePropertyName("Camera");
            serializer.Serialize(writer, workspaceView.Camera);

            writer.WritePropertyName("NodeViews");
            writer.WriteStartArray();
            foreach (var nodeView in workspaceView.Nodes)
            {
                serializer.Serialize(writer, nodeView);
            }
            writer.WriteEndArray();

            writer.WritePropertyName("Annotations");
            writer.WriteStartArray();
            foreach (var annotation in workspaceView.Annotations)
            {
                serializer.Serialize(writer, annotation);
            }
            foreach (var note in workspaceView.Notes)
            {
                AnnotationModel convertedNote = new AnnotationModel(new NodeModel[0], new NoteModel[0]);
                convertedNote.GUID           = note.Model.GUID;
                convertedNote.X              = note.Left;
                convertedNote.Y              = note.Top;
                convertedNote.AnnotationText = note.Text;

                serializer.Serialize(writer, new AnnotationViewModel(workspaceView, convertedNote));
            }
            writer.WriteEndArray();

            writer.WritePropertyName("X");
            writer.WriteValue(workspaceView.X);

            writer.WritePropertyName("Y");
            writer.WriteValue(workspaceView.Y);

            writer.WritePropertyName("Zoom");
            writer.WriteValue(workspaceView.Zoom);

            writer.WriteEndObject();
        }
예제 #27
0
파일: Program.cs 프로젝트: EricCote/WebApi2
        private static void EdmReadAnnotationDemo()
        {
            Console.WriteLine("EdmReadAnnotationDemo");

            var annotationModel = new AnnotationModel();
            var model           = annotationModel.Model;
            var person          = (IEdmEntityType)model.FindType("TestNS.Person");
            var annotation      = model.FindVocabularyAnnotations <IEdmValueAnnotation>(person, "TestNS.OutColor").First();
            var memberExp       = (IEdmEnumMemberExpression)annotation.Value;

            foreach (var member in memberExp.EnumMembers)
            {
                Console.WriteLine(member.Name);
            }
        }
예제 #28
0
 public AnnotationViewModel(WorkspaceViewModel workspaceViewModel, AnnotationModel model)
 {
     annotationModel         = model;
     this.WorkspaceViewModel = workspaceViewModel;
     model.PropertyChanged  += model_PropertyChanged;
     //https://jira.autodesk.com/browse/QNTM-3770
     //Notes and Groups are serialized as annotations. Do not unselect the node selection during
     //Notes serialization
     if (model.Nodes.Count() > 0)
     {
         // Group is created already.So just populate it.
         var selectNothing = new DynamoModel.SelectModelCommand(Guid.Empty, System.Windows.Input.ModifierKeys.None.AsDynamoType());
         WorkspaceViewModel.DynamoViewModel.ExecuteCommand(selectNothing);
     }
 }
예제 #29
0
 public void Add(AnnotationModel _annotation)
 {
     using (ISession session = NHibernateHelper.OpenSession())
         using (ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 session.Save(_annotation);
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex);
             }
         }
 }
        public IHttpActionResult Put(int id, AnnotationModel annotationModel)
        {
            var annotation = new Annotation
            {
                Body         = annotationModel.Body,
                MarkingStart = annotationModel.MarkingStart,
                MarkingEnd   = annotationModel.MarkingEnd,
                PostId       = annotationModel.PostId,
                CommentId    = annotationModel.CommentId,
                SearchUserId = annotationModel.SearchUserId
            };

            if (!_repository.Update(id, annotation))
            {
                return(NotFound());
            }
            return(Ok());
        }
예제 #31
0
        private static Annotation PopulateEntity(AnnotationModel model, Annotation entity)
        {
            entity.Body = model.Body;
            entity.AnnotationTargetId = model.TargetId > 0 ? model.TargetId : model.Target.Id;
            entity.CreatedDate        = model.CreatedDate;
            entity.CreatedUserId      = model.CreatedUserId;
            entity.UpdatedDate        = model.UpdatedDate;
            entity.UpdatedUserId      = model.UpdatedUserId;
            entity.GroupId            = model.GroupId;
            entity.LicenseId          = model.LicenseId;
            entity.AnnotationTypeId   = model.AnnotationTypeId;
            entity.ParentId           = model.ParentId;


            var modelTags = model.Tags?.ToList();

            if (modelTags == null)
            {
                if (entity.Tags.Count > 1)
                {
                    entity.Tags.ToList().RemoveRange(0, entity.Tags.Count);
                }
            }
            else
            {
                // delete first all that have been removed
                entity.Tags.ToList().ForEach(t => {
                    if (modelTags.FindIndex(mt => mt.id == t.TagId) < 0)
                    {
                        entity.Tags.Remove(t);
                    }
                });
                modelTags.ForEach(t =>
                {
                    if (!entity.Tags.Any(e => e.TagId == t.id))
                    {
                        entity.Tags.Add(t.ToAnnotationTagEntity());
                    }
                });
            }


            return(entity);
        }
예제 #32
0
        /// <summary>
        ///     Paste ISelectable objects from the clipboard to the workspace at specified point.
        /// </summary>
        /// <param name="targetPoint">Location where data will be pasted</param>
        /// <param name="useOffset">Indicates whether we will use current workspace offset or paste nodes
        /// directly in this point. </param>
        public void Paste(Point2D targetPoint, bool useOffset = true)
        {
            if (useOffset)
            {
                // Provide a small offset when pasting so duplicate pastes aren't directly on top of each other
                CurrentWorkspace.IncrementPasteOffset();
            }

            //clear the selection so we can put the
            //paste contents in
            DynamoSelection.Instance.ClearSelection();

            //make a lookup table to store the guids of the
            //old models and the guids of their pasted versions
            var modelLookup = new Dictionary<Guid, ModelBase>();

            //make a list of all newly created models so that their
            //creations can be recorded in the undo recorder.
            var createdModels = new List<ModelBase>();

            var nodes = ClipBoard.OfType<NodeModel>();
            var connectors = ClipBoard.OfType<ConnectorModel>();
            var notes = ClipBoard.OfType<NoteModel>();
            var annotations = ClipBoard.OfType<AnnotationModel>();

            // Create the new NoteModel's
            var newNoteModels = new List<NoteModel>();
            foreach (var note in notes)
            {
                var noteModel = new NoteModel(note.X, note.Y, note.Text, Guid.NewGuid());
                //Store the old note as Key and newnote as value.
                modelLookup.Add(note.GUID,noteModel);
                newNoteModels.Add(noteModel);
            }

            var xmlDoc = new XmlDocument();

            // Create the new NodeModel's
            var newNodeModels = new List<NodeModel>();
            foreach (var node in nodes)
            {
                NodeModel newNode;

                if (CurrentWorkspace is HomeWorkspaceModel && (node is Symbol || node is Output))
                {
                    var symbol = (node is Symbol
                        ? (node as Symbol).InputSymbol
                        : (node as Output).Symbol);
                    var code = (string.IsNullOrEmpty(symbol) ? "x" : symbol) + ";";
                    newNode = new CodeBlockNodeModel(code, node.X, node.Y, LibraryServices, CurrentWorkspace.ElementResolver);
                }
                else
                {
                    var dynEl = node.Serialize(xmlDoc, SaveContext.Copy);
                    newNode = NodeFactory.CreateNodeFromXml(dynEl, SaveContext.Copy, CurrentWorkspace.ElementResolver);
                }

                var lacing = node.ArgumentLacing.ToString();
                newNode.UpdateValue(new UpdateValueParams("ArgumentLacing", lacing));
                if (!string.IsNullOrEmpty(node.NickName) && !(node is Symbol) && !(node is Output))
                    newNode.NickName = node.NickName;

                newNode.Width = node.Width;
                newNode.Height = node.Height;

                modelLookup.Add(node.GUID, newNode);

                newNodeModels.Add(newNode);
            }

            var newItems = newNodeModels.Concat<ModelBase>(newNoteModels);

            var shiftX = targetPoint.X - newItems.Min(item => item.X);
            var shiftY = targetPoint.Y - newItems.Min(item => item.Y);
            var offset = useOffset ? CurrentWorkspace.CurrentPasteOffset : 0;

            foreach (var model in newItems)
            {
                model.X = model.X + shiftX + offset;
                model.Y = model.Y + shiftY + offset;
            }

            // Add the new NodeModel's to the Workspace
            foreach (var newNode in newNodeModels)
            {
                CurrentWorkspace.AddAndRegisterNode(newNode, false);
                createdModels.Add(newNode);
            }

            // TODO: is this required?
            OnRequestLayoutUpdate(this, EventArgs.Empty);

            // Add the new NoteModel's to the Workspace
            foreach (var newNote in newNoteModels)
            {
                CurrentWorkspace.AddNote(newNote, false);
                createdModels.Add(newNote);
            }

            ModelBase start;
            ModelBase end;
            var newConnectors =
                from c in connectors

                // If the guid is in nodeLookup, then we connect to the new pasted node. Otherwise we
                // re-connect to the original.
                let startNode =
                    modelLookup.TryGetValue(c.Start.Owner.GUID, out start)
                        ? start as NodeModel
                        : CurrentWorkspace.Nodes.FirstOrDefault(x => x.GUID == c.Start.Owner.GUID)
                let endNode =
                    modelLookup.TryGetValue(c.End.Owner.GUID, out end)
                        ? end as NodeModel
                        : CurrentWorkspace.Nodes.FirstOrDefault(x => x.GUID == c.End.Owner.GUID)

                // Don't make a connector if either end is null.
                where startNode != null && endNode != null
                select
                    ConnectorModel.Make(startNode, endNode, c.Start.Index, c.End.Index);

            createdModels.AddRange(newConnectors);

            //Grouping depends on the selected node models.
            //so adding the group after nodes / notes are added to workspace.
            //select only those nodes that are part of a group.
            var newAnnotations = new List<AnnotationModel>();
            foreach (var annotation in annotations)
            {
                var annotationNodeModel = new List<NodeModel>();
                var annotationNoteModel = new List<NoteModel>();
                // some models can be deleted after copying them,
                // so they need to be in pasted annotation as well
                var modelsToRestore = annotation.DeletedModelBases.Intersect(ClipBoard);
                var modelsToAdd = annotation.SelectedModels.Concat(modelsToRestore);
                // checked condition here that supports pasting of multiple groups
                foreach (var models in modelsToAdd)
                {
                    ModelBase mbase;
                    modelLookup.TryGetValue(models.GUID, out mbase);
                    if (mbase is NodeModel)
                    {
                        annotationNodeModel.Add(mbase as NodeModel);
                    }
                    if (mbase is NoteModel)
                    {
                        annotationNoteModel.Add(mbase as NoteModel);
                    }
                }

                var annotationModel = new AnnotationModel(annotationNodeModel, annotationNoteModel)
                {
                    GUID = Guid.NewGuid(),
                    AnnotationText = annotation.AnnotationText,
                    Background = annotation.Background,
                    FontSize = annotation.FontSize
                };

                newAnnotations.Add(annotationModel);
            }

            // Add the new Annotation's to the Workspace
            foreach (var newAnnotation in newAnnotations)
            {
                CurrentWorkspace.AddAnnotation(newAnnotation);
                createdModels.Add(newAnnotation);
                AddToSelection(newAnnotation);
            }

            // adding an annotation overrides selection, so add nodes and notes after
            foreach (var item in newItems)
            {
                AddToSelection(item);
            }

            // Record models that are created as part of the command.
            CurrentWorkspace.RecordCreatedModels(createdModels);
        }
예제 #33
0
 public AnnotationModel AddAnnotation(string text, Guid id)
 {
     var selectedNodes = this.Nodes == null ? null:this.Nodes.Where(s => s.IsSelected);
     var selectedNotes = this.Notes == null ? null: this.Notes.Where(s => s.IsSelected);
    
     if (!CheckIfModelExistsInSameGroup(selectedNodes, selectedNotes))
     {
         var annotationModel = new AnnotationModel(selectedNodes, selectedNotes)
         {
             GUID = id,
             AnnotationText = text                   
         };
         annotationModel.ModelBaseRequested += annotationModel_GetModelBase;
         annotationModel.Disposed += (_) => annotationModel.ModelBaseRequested -= annotationModel_GetModelBase;
         AddNewAnnotation(annotationModel);
         HasUnsavedChanges = true;
         return annotationModel;
     }
     return null;
 }
예제 #34
0
 public void AddAnnotation(AnnotationModel annotationModel)
 {
     annotationModel.ModelBaseRequested += annotationModel_GetModelBase;
     annotationModel.Disposed += (_) => annotationModel.ModelBaseRequested -= annotationModel_GetModelBase;
     AddNewAnnotation(annotationModel);
 }
예제 #35
0
 private void RemoveAnnotation(AnnotationModel annotation)
 {
     lock (annotations)
     {
         if (!annotations.Remove(annotation)) return;
     }
     OnAnnotationRemoved(annotation);
 }
예제 #36
0
        private void AddNewAnnotation(AnnotationModel annotation)
        {
            lock (annotations)
            {
                annotations.Add(annotation);
            }

            OnAnnotationAdded(annotation);
        }
예제 #37
0
 protected virtual void OnAnnotationRemoved(AnnotationModel annotation)
 {
     var handler = AnnotationRemoved;
     if (handler != null) handler(annotation);
 }
예제 #38
0
        public void CreateModel(XmlElement modelData)
        {
            var helper = new XmlElementHelper(modelData);
            string typeName = helper.ReadString("type", String.Empty);
            if (string.IsNullOrEmpty(typeName))
            {
                // If there wasn't a "type" attribute, then we fall-back onto 
                // the name of the XmlElement itself, which is usually the type 
                // name.
                typeName = modelData.Name;
                if (string.IsNullOrEmpty(typeName))
                {
                    string guid = helper.ReadString("guid");
                    throw new InvalidOperationException(
                        string.Format("No type information: {0}", guid));
                }
            }

            /*
            if (typeName.Equals("Dynamo.Graph.Nodes.ZeroTouch.DSFunction") ||
                typeName.Equals("Dynamo.Graph.Nodes.ZeroTouch.DSVarArgFunction"))
            {
                // For DSFunction and DSVarArgFunction node types, the type name
                // is actually embedded within "name" attribute (for an example,
                // "UV.ByCoordinates@double,double").
                // 
                typeName = modelData.Attributes["name"].Value;
            }
            */

            if (typeName.Contains("ConnectorModel"))
            {
                var connector = NodeGraph.LoadConnectorFromXml(modelData,
                    Nodes.ToDictionary(node => node.GUID));

                // It is possible that in some cases connector can't be created,
                // for example, connector connects to a custom node instance
                // whose input ports have been changed, so connector can't find
                // its end port owner.
                if (connector == null)
                {
                    var guidAttribute = modelData.Attributes["guid"];
                    if (guidAttribute == null)
                    {
                        throw new InvalidOperationException("'guid' field missing from recorded model");
                    }
                    undoRecorder.RecordModelAsOffTrack(Guid.Parse(guidAttribute.Value)); 
                }
                else 
                {
                    OnConnectorAdded(connector); // Update view-model and view.
                }
            }
            else if (typeName.Contains("NoteModel"))
            {
                var noteModel = NodeGraph.LoadNoteFromXml(modelData);
                AddNote(noteModel);

                //check whether this note belongs to a group
                foreach (var annotation in Annotations)
                {
                    //this note "was" in a group
                    if (annotation.DeletedModelBases.Any(m => m.GUID == noteModel.GUID))
                    {
                        annotation.AddToSelectedModels(noteModel);
                    }
                }
            }
            else if (typeName.Contains("AnnotationModel"))
            {
                var selectedNodes = this.Nodes == null ? null : this.Nodes.Where(s => s.IsSelected);
                var selectedNotes = this.Notes == null ? null : this.Notes.Where(s => s.IsSelected);

                var annotationModel = new AnnotationModel(selectedNodes, selectedNotes);
                annotationModel.ModelBaseRequested += annotationModel_GetModelBase;
                annotationModel.Disposed += (_) => annotationModel.ModelBaseRequested -= annotationModel_GetModelBase;
                annotationModel.Deserialize(modelData, SaveContext.Undo);
                AddNewAnnotation(annotationModel);
            }

            else if (typeName.Contains("PresetModel"))
            {
                var preset = new PresetModel(this.Nodes);
                preset.Deserialize(modelData, SaveContext.Undo);
                presets.Add(preset);
                //we raise this property change here so that this event bubbles up through
                //the model and to the DynamoViewModel so that presets show in the UI menu if our undo/redo
                //created the first preset
                RaisePropertyChanged("EnablePresetOptions");
               
            }
            else // Other node types.
            {
                NodeModel nodeModel = NodeFactory.CreateNodeFromXml(modelData, SaveContext.Undo, ElementResolver);
                
                AddAndRegisterNode(nodeModel);
                
                //check whether this node belongs to a group
                foreach (var annotation in Annotations)
                {
                    //this node "was" in a group
                    if (annotation.DeletedModelBases.Any(m=>m.GUID == nodeModel.GUID))
                    {
                        annotation.AddToSelectedModels(nodeModel);
                    }
                }
            }
        }
예제 #39
0
 internal void RecordGroupModelBeforeUngroup(AnnotationModel annotation)
 {
     using (undoRecorder.BeginActionGroup()) // Start a new action group.
     {
         undoRecorder.RecordModificationForUndo(annotation);
     }
 }
예제 #40
0
 public AnnotationViewModel(WorkspaceViewModel workspaceViewModel, AnnotationModel model)
 {             
     annotationModel = model;           
     this.WorkspaceViewModel = workspaceViewModel;                                     
     model.PropertyChanged += model_PropertyChanged;
     // Group is created already.So just populate it.
     var selectNothing = new DynamoModel.SelectModelCommand(Guid.Empty, System.Windows.Input.ModifierKeys.None.AsDynamoType());
     WorkspaceViewModel.DynamoViewModel.ExecuteCommand(selectNothing);
 }
예제 #41
0
 private void Model_AnnotationAdded(AnnotationModel annotation)
 {
     var viewModel = new AnnotationViewModel(this, annotation);
     _annotations.Add(viewModel);
 }
예제 #42
0
 private void Model_AnnotationRemoved(AnnotationModel annotation)
 {
     _annotations.Remove(_annotations.First(x => x.AnnotationModel == annotation));
 }