public IEnumerable <Annotation> InferAnnotations(NewPrimitive toBeSnapped, SnappedPrimitive toBeAnnotated)
        {
            // we skip coplanarity inference for spheres.
            if (toBeSnapped is NewSphere)
            {
                return(Enumerable.Empty <Annotation>());
            }

            var curvesToSkip = toBeAnnotated.FeatureCurves.Concat(GetSphereFeatureCurves()).ToArray();

            var candidates = from firstCurve in toBeAnnotated.FeatureCurves.OfType <CircleFeatureCurve>()
                             from secondCurve in sessionData.FeatureCurves.Except(curvesToSkip).OfType <CircleFeatureCurve>()
                             where AreGoodCandidates(firstCurve, secondCurve)
                             select Tuple.Create(firstCurve, secondCurve);

            if (candidates.Any())
            {
                var annotations =
                    from candidate in candidates
                    let coplanarity = new Coplanarity {
                    Elements = new FeatureCurve[] { candidate.Item1, candidate.Item2 }
                }
                select coplanarity as Annotation;

                return(annotations);
            }
            else
            {
                return(Enumerable.Empty <Annotation>());
            }
        }
Esempio n. 2
0
        public void ApplyMovement(NewPrimitive source, NewPrimitive target, Vector3D moveVector)
        {
            var concreteSource = (TSource)source;
            var concreteTarget = (TTarget)target;

            ApplyMovementCore(concreteSource, concreteTarget, moveVector);
        }
Esempio n. 3
0
 /// <summary>
 /// Concatinates the results of all inferrers for the given input to a single collection of annotations.
 /// </summary>
 /// <param name="toBeSnapped">The new primitive to be snapped</param>
 /// <param name="toBeAnnotated">The snapped version of <see cref="toBeAnnotated"/></param>
 /// <returns>A list of all the inferred annotations for this new primitive</returns>
 public IEnumerable <Annotation> InferAnnotations(NewPrimitive toBeSnapped, SnappedPrimitive toBeAnnotated)
 {
     return(from entry in inferrers
            where entry.IsEnabledPredicate()
            from annotation in entry.Inferrer.InferAnnotations(toBeSnapped, toBeAnnotated)
            select annotation);
 }
Esempio n. 4
0
        public IEnumerable <Annotation> InferAnnotations(NewPrimitive toBeSnapped, SnappedPrimitive toBeAnnotated)
        {
            // we skip orthogonality inference for spheres
            if (toBeSnapped is NewSphere)
            {
                return(Enumerable.Empty <Annotation>());
            }

            var curvesToSkip = toBeAnnotated.FeatureCurves.Concat(GetSphereFeatureCurves()).ToArray();

            var candidates =
                from firstCurve in toBeAnnotated.FeatureCurves
                from secondCurve in sessionData.FeatureCurves.Except(curvesToSkip)
                where AreGoodCandidates(firstCurve, secondCurve)
                select Tuple.Create(firstCurve, secondCurve);

            if (candidates.Any())
            {
                var bestCandidate        = candidates.Minimizer(pair => DistanceBetweenCurves(pair.Item1, pair.Item2));
                var newFeatureCurve      = bestCandidate.Item1;
                var existingFeatureCurve = bestCandidate.Item2;

                Annotation curveOrthogonality = new OrthogonalAxis
                {
                    Elements = new FeatureCurve[] { newFeatureCurve, existingFeatureCurve }
                };

                return(UtilsEnumerable.ArrayOf(curveOrthogonality));
            }
            else
            {
                return(Enumerable.Empty <Annotation>());
            }
        }
Esempio n. 5
0
        public IEnumerable <Annotation> InferAnnotations(NewPrimitive toBeSnapped, SnappedPrimitive toBeAnnotated)
        {
            var toBeAnnotatedCurves = toBeAnnotated.FeatureCurves;
            var candidateTriples    =
                from i in Enumerable.Range(0, toBeAnnotatedCurves.Length)
                from j in Enumerable.Range(i + 1, toBeAnnotatedCurves.Length - i - 1)
                // at this point (i, j) are all the possible pairs of curves without repetitions
                let allExistingCurves = sessionData.FeatureCurves.Except(toBeAnnotatedCurves)
                                        from existingCurve in allExistingCurves
                                        where AreGoodCandidates(toBeAnnotatedCurves[i], toBeAnnotatedCurves[j], existingCurve)
                                        select new
            {
                FistNewCurve   = toBeAnnotatedCurves[i],
                SecondNewCurve = toBeAnnotatedCurves[j],
                ExistingCurve  = existingCurve
            };

            if (candidateTriples.Any())
            {
                var bestCandidate = candidateTriples.Minimizer(triple => ProximityMeasure(triple.FistNewCurve, triple.SecondNewCurve, triple.ExistingCurve));
                var annotation    = new ColinearCenters
                {
                    Elements = UtilsEnumerable.ArrayOf(bestCandidate.FistNewCurve, bestCandidate.SecondNewCurve, bestCandidate.ExistingCurve)
                };
                return(UtilsEnumerable.Singleton(annotation));
            }
            else
            {
                return(Enumerable.Empty <Annotation>());
            }
        }
 public Type[] GetTargetTypes(NewPrimitive source)
 {
     Contract.Requires(source != null);
     Contract.Ensures(Contract.Result <Type[]>() != null);
     Contract.Ensures(Contract.ForAll(Contract.Result <Type[]>(), type => type != null));
     Contract.Ensures(Contract.Result <Type[]>().Contains(source.GetType()));
     return(null);
 }
        public void DuplicateSnapped(SnappedPrimitive primitiveData, out NewPrimitive newPrimitive, out NewPrimitive clone)
        {
            newPrimitive = primitivesConverter.SnappedToNew(primitiveData);
            newPrimitive.UpdateCurvesGeometry();

            sessionData.NewPrimitives.Add(newPrimitive);
            clone = primitivesConverter.NewToNew(newPrimitive, newPrimitive.GetType(), new Vector3D(0, 0, 0));
            SelectPrimitive(newPrimitive);
        }
Esempio n. 8
0
        public Type[] GetTargetTypes(NewPrimitive source)
        {
            var query =
                from key in newConvertersRegistry.Keys
                where key.Item1 == source.GetType()
                select key.Item2;

            return(query.ToArray());
        }
 public NewPrimitive NewToNew(NewPrimitive source, Type targetType, Vector3D moveVector)
 {
     Contract.Requires(source != null);
     Contract.Requires(targetType != null);
     Contract.Requires(GetTargetTypes(source).Contains(targetType));
     Contract.Ensures(Contract.Result <NewPrimitive>() != null);
     Contract.Ensures(Contract.Result <NewPrimitive>().GetType() == targetType);
     return(null);
 }
Esempio n. 10
0
        SnappedPrimitive IPrimitiveSnapper.Create(NewPrimitive newPrimitive)
        {
            Contract.Requires(newPrimitive != null);
            Contract.Requires(NewPrimitiveType.IsAssignableFrom(newPrimitive.GetType()));

            Contract.Ensures(Contract.Result <SnappedPrimitive>() != null);
            Contract.Ensures(SnappedPrimitiveType.IsAssignableFrom(Contract.Result <SnappedPrimitive>().GetType()));

            return(null);
        }
Esempio n. 11
0
 public ITemporarySnap TemporarySnap(NewPrimitive newPrimitive)
 {
     if (snapOptions.IsSnapEnabled)
     {
         return(new TemporarySnap(sessionData, snappersManager, primitivesReaderWriterFactory, eventAggregator, newPrimitive, constrainedOptimizer));
     }
     else
     {
         return(new DoNothingTemporarySnap());
     }
 }
            protected override void MouseDownCore(MousePosInfo3D position, dynamic data)
            {
                var draggedPrimitive = data.Item1 as INewPrimitiveView;

                if (draggedPrimitive != null && position.Ray3D != null)
                {
                    draggedPrimitiveData = draggedPrimitive.ViewModel.Model;
                    draggedPrimitive.OnStartEdit(position.Pos2D, position.Ray3D.Value);
                    editor = draggedPrimitive.ViewModel.StartEdit(position.Pos2D, position.Ray3D.Value);
                }
            }
Esempio n. 13
0
        SnappedPrimitive IPrimitiveSnapper.Create(PointsSequence[] selectedCurves, NewPrimitive newPrimitive)
        {
            Contract.Requires(selectedCurves != null);
            Contract.Requires(Contract.ForAll(selectedCurves, c => c != null));
            Contract.Requires(newPrimitive != null);
            Contract.Requires(NewPrimitiveType.IsAssignableFrom(newPrimitive.GetType()));

            Contract.Ensures(Contract.Result <SnappedPrimitive>() != null);
            Contract.Ensures(SnappedPrimitiveType.IsAssignableFrom(Contract.Result <SnappedPrimitive>().GetType()));

            return(null);
        }
Esempio n. 14
0
        public IEnumerable <Annotation> InferAnnotations(NewPrimitive toBeSnapped, SnappedPrimitive toBeAnnotated)
        {
            var toBeAnnotatedSphere = toBeAnnotated as SnappedSphere;

            if (toBeAnnotatedSphere == null)
            {
                return(InferNonSphereAnnotations(toBeAnnotated));
            }
            else
            {
                return(InferSphereAnnotations(toBeAnnotatedSphere));
            }
        }
        public IEnumerable <Annotation> InferAnnotations(NewPrimitive toBeSnapped, SnappedPrimitive toBeAnnotated)
        {
            var otherPrimitives = from primitive in sessionData.SnappedPrimitives
                                  where primitive != toBeAnnotated
                                  select primitive;

            var result =
                from primitive in otherPrimitives
                from annotation in InferCoplanarity(primitive, toBeAnnotated)
                select annotation;

            return(result);
        }
Esempio n. 16
0
 public void ComputeAssignments(NewPrimitive primitive, bool refresh)
 {
     ComputeAssignments(primitive.FeatureCurves, CurveCategories.Feature);
     //if (!onlyFeatures)
     ComputeAssignments(primitive.SilhouetteCurves, CurveCategories.Silhouette);
     //from idx in Enumerable.Range(0, sessionData.SketchObjects.Length)
     if (refresh)
     {
         for (int idx = 0; idx < sessionData.SketchObjects.Length; idx++)
         {
             sessionData.SketchObjects[idx].isdeselected = false;
         }
     }
 }
        private void SelectPrimitive(NewPrimitive primitive)
        {
            var toUnSelect = sessionData.SelectedNewPrimitives.ToArray();

            foreach (var item in toUnSelect)
            {
                if (item != primitive)
                {
                    item.IsSelected = false;
                }
            }

            primitive.IsSelected = true;
        }
        public void CycleDuplicates(NewPrimitive originalDuplicate, ref NewPrimitive currentDuplicate, Vector3D currentDragVector)
        {
            var targetTypes = primitivesConverter.GetTargetTypes(originalDuplicate);
            var currIndex   = Array.IndexOf(targetTypes, currentDuplicate.GetType());
            var nextIndex   = (currIndex + 1) % targetTypes.Length;

            sessionData.NewPrimitives.Remove(currentDuplicate);
            currentDuplicate = primitivesConverter.NewToNew(originalDuplicate, targetTypes[nextIndex], currentDragVector);

            currentDuplicate.UpdateCurvesGeometry();
            sessionData.NewPrimitives.Add(currentDuplicate);

            SelectPrimitive(currentDuplicate);
        }
        private void OnPrimitiveDragged(NewPrimitive primitive)
        {
            var query =
                from vm in NewPrimitiveViewModels
                where vm.Model == primitive
                select vm;
            var viewModel = query.FirstOrDefault();

            if (viewModel != null)
            {
                viewModel.UpdateFromModel();
                viewModel.NotifyDragged();
            }
        }
Esempio n. 20
0
        private void OnPrimitiveCurvesChanged(NewPrimitive primitive)
        {
            var container = primitiveCurvesRoot.ItemContainerGenerator.ContainerFromItem(primitive);

            if (container != null)
            {
                var primitiveView =
                    container.VisualTree().OfType <NewPrimitiveCurvesControl>().FirstOrDefault();
                if (primitiveView != null)
                {
                    primitiveView.Update();
                }
            }
        }
Esempio n. 21
0
 public TemporarySnap(SessionData sessionData,
                      SnappersManager snappersManager,
                      PrimitivesReaderWriterFactory primitivesReaderWriterFactory,
                      IEventAggregator eventAggregator,
                      NewPrimitive newPrimitive,
                      IConstrainedOptimizer optimizer)
 {
     this.sessionData     = sessionData;
     this.snappersManager = snappersManager;
     this.primitivesReaderWriterFactory = primitivesReaderWriterFactory;
     this.eventAggregator = eventAggregator;
     this.newPrimitive    = newPrimitive;
     this.optimizer       = optimizer;
 }
        public IEnumerable <Annotation> InferAnnotations(NewPrimitive toBeSnapped, SnappedPrimitive toBeAnnotated)
        {
            var thisCircles = toBeAnnotated.FeatureCurves.OfType <CircleFeatureCurve>();
            var allCircles  = sessionData.FeatureCurves.OfType <CircleFeatureCurve>();

            var annotations =
                from curve1 in thisCircles
                from curve2 in allCircles.Except(thisCircles)
                where curve1.SnappedTo != null && curve2.SnappedTo != null && curve1.SnappedTo == curve2.SnappedTo
                select new SameRadius {
                Elements = new FeatureCurve[] { curve1, curve2 }
            };

            return(annotations.ToArray());
        }
Esempio n. 23
0
 public void Refresh(NewPrimitive primitive)
 {
     for (int idx = 0; idx < sessionData.SketchObjects.Length; idx++)
     {
         sessionData.SketchObjects[idx].isdeselected = false;
     }
     for (int idx = 0; idx < primitive.AllCurves.Length; idx++)
     {
         primitive.AllCurves[idx].isDeselected = false;
         if (primitive.AllCurves[idx].AssignedTo != null)
         {
             primitive.AllCurves[idx].AssignedTo.isdeselected = false;
         }
     }
 }
        private NewPrimitiveViewModel NewPrimitiveDataToNewPrimitiveViewModel(NewPrimitive data)
        {
            NewPrimitiveViewModel result = null;

            data.MatchClass <NewCylinder>(cylinder =>
            {
                var viewModel = container.Resolve <NewCylinderViewModel>();
                viewModel.Init(cylinder);
                result = viewModel;
            });
            data.MatchClass <NewCone>(newCone =>
            {
                var viewModel = container.Resolve <NewConeViewModel>();
                viewModel.Init(newCone);
                result = viewModel;
            });
            data.MatchClass <NewSphere>(newSphere =>
            {
                var viewModel = container.Resolve <NewSphereViewModel>();
                viewModel.Init(newSphere);
                result = viewModel;
            });
            data.MatchClass <NewStraightGenCylinder>(newSgc =>
            {
                var viewModel = container.Resolve <NewSGCViewModel>();
                viewModel.Init(newSgc);
                result = viewModel;
            });
            data.MatchClass <NewBendedGenCylinder>(newBgc =>
            {
                var viewModel = container.Resolve <NewBGCViewModel>();
                viewModel.Init(newBgc);
                result = viewModel;
            });
            data.MatchClass <NewCuboid>(newCuboid =>
            {
                var viewModel = container.Resolve <NewCuboidViewModel>();
                viewModel.Init(newCuboid);
                result = viewModel;
            });
            Contract.Assume(result != null);

            result.Model = data;
            return(result);
        }
Esempio n. 25
0
        public SnappedPrimitive Create(NewPrimitive newPrimitive)
        {
            Contract.Requires(newPrimitive != null);
            Contract.Ensures(Contract.Result <SnappedPrimitive>() != null);

            // find appropriate type snapper
            var newPrimitiveType = newPrimitive.GetType();
            var snapper          =
                snappers
                .Where(s => s.NewPrimitiveType.IsAssignableFrom(newPrimitiveType))
                .FirstOrDefault();

            if (snapper == null)
            {
                throw new InvalidOperationException("Cannot find snapper that can snap new primitives of type " + newPrimitiveType);
            }

            // return the snapper's result
            return(snapper.Create(newPrimitive));
        }
        public IEnumerable <Annotation> InferAnnotations(NewPrimitive toBeSnapped, SnappedPrimitive toBeAnnotated)
        {
            // we skip orthogonality inference for spheres
            if (toBeSnapped is NewSphere)
            {
                return(Enumerable.Empty <Annotation>());
            }

            var curvesToSkip = toBeAnnotated.FeatureCurves.Concat(GetSphereFeatureCurves()).ToArray();
            var candidates   =
                from firstCurve in toBeAnnotated.FeatureCurves
                from secondCurve in sessionData.FeatureCurves.Except(curvesToSkip)
                where AreGoodCandidates(firstCurve, secondCurve)
                group Tuple.Create(firstCurve, secondCurve) by firstCurve;

            return(from candidatesGroup in candidates
                   let bestCandidate = candidatesGroup.Minimizer(pair => CurveDistance(pair.Item1, pair.Item2))
                                       select new Cocentrality
            {
                Elements = new FeatureCurve[] { bestCandidate.Item1, bestCandidate.Item2 }
            });
        }
Esempio n. 27
0
        public bool ComputeFeatureAssignments(NewPrimitive primitive)
        {
            ComputeAssignments(primitive.FeatureCurves, CurveCategories.Feature);
            int toDoFeatureCurves = primitive.FeatureCurves.Where(curve => !curve.isDeselected).ToArray().Length;

            if (toDoFeatureCurves == 0)
            {
                return(false);
            }
            int toDoFeaturesOnSketch =
                (from idx in Enumerable.Range(0, sessionData.SketchObjects.Length)
                 where sessionData.SketchObjects[idx].CurveCategory == CurveCategories.Feature
                 where sessionData.SketchObjects[idx].isdeselected == false
                 select idx).ToArray().Length;

            if (toDoFeaturesOnSketch == 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Esempio n. 28
0
 public void ApplyMovement(NewPrimitive source, NewPrimitive target, Vector3D moveVector)
 {
     Contract.Requires(source != null && source.GetType() == SourceType);
     Contract.Requires(target != null && target.GetType() == TargetType);
 }
Esempio n. 29
0
 public NewPrimitive Convert(NewPrimitive source, Vector3D moveVector)
 {
     Contract.Requires(source != null && source.GetType() == SourceType);
     Contract.Ensures(Contract.Result <NewPrimitive>() != null && Contract.Result <NewPrimitive>().GetType() == TargetType);
     return(null);
 }
        public SnappedPrimitive Create(NewPrimitive newPrimitive)
        {
            TNew concrete = (TNew)newPrimitive;

            return(Create(concrete));
        }