public SSBasePairLineConnectorViewModel(SSBasePairViewModel basePair)
        {
            BasePair = basePair;
            double ntAngle = Math.Atan2(BasePair.ThreePrimeNucleotide.CenterY - BasePair.FivePrimeNucleotide.CenterY,
                                        BasePair.ThreePrimeNucleotide.CenterX - BasePair.FivePrimeNucleotide.CenterX) * (180 / Math.PI);
            double ntDistance = Math.Sqrt(Math.Pow((BasePair.FivePrimeNucleotide.CenterX - BasePair.ThreePrimeNucleotide.CenterX), 2) +
                                          Math.Pow((BasePair.FivePrimeNucleotide.CenterY - BasePair.ThreePrimeNucleotide.CenterY), 2));

            double targetConnectorDistance = 0.35 * ntDistance;

            Width  = Math.Cos(ntAngle * (Math.PI / 180)) * targetConnectorDistance;
            Height = Math.Sin(ntAngle * (Math.PI / 180)) * targetConnectorDistance;

            double remainingDistance = ntDistance - targetConnectorDistance;

            X = BasePair.FivePrimeNucleotide.CenterX + (remainingDistance / 2.0) * Math.Cos(ntAngle * (Math.PI / 180));
            Y = BasePair.FivePrimeNucleotide.CenterY + (remainingDistance / 2.0) * Math.Sin(ntAngle * (Math.PI / 180));
        }
示例#2
0
        public override bool Initialize(IBioDataLoader data)
        {
            Dictionary <int, SSBasePairViewModel> basePairVMs = new Dictionary <int, SSBasePairViewModel>();

            var sdloader = data as IBioDataLoader <IStructureModelBioEntity>;

            if (sdloader != null)
            {
                var basePairs = from bp in sdloader.Entities.OfType <XRNABasePair>()
                                select bp;

                foreach (XRNABasePair bp in basePairs)
                {
                    SSBasePairViewModel bpvm = BuildBasePairViewModel(bp);
                    ModelElements.Add(bpvm);
                    ModelElements.Add(bpvm.FivePrimeNucleotide);
                    ModelElements.Add(bpvm.ThreePrimeNucleotide);
                    basePairVMs.Add(bpvm.FivePrimeNucleotide.Index, bpvm);
                }

                var unpairedNt = from nt in sdloader.Entities.OfType <XRNANucleotide>()
                                 select nt;
                foreach (XRNANucleotide nt in unpairedNt)
                {
                    SSSymbolViewModel svm = BuildSymbolViewModel(nt);
                    ModelElements.Add(svm);
                }

                var allEntities = from entity in sdloader.Entities
                                  select entity;

                foreach (IStructureModelBioEntity entity in allEntities)
                {
                    if (entity is XRNABasePairConnector)
                    {
                        XRNABasePairConnector lc = (XRNABasePairConnector)entity;
                        ModelElements.Add(new SSBasePairLineConnectorViewModel(basePairVMs[lc.BasePair.FivePrimeIndex + 1])
                        {
                            Color     = lc.Color,
                            Thickness = lc.Thickness,
                            Visible   = lc.Visible
                        });
                    }
                    else if (entity is XRNABasePairConnectorCircle)
                    {
                        XRNABasePairConnectorCircle cc = (XRNABasePairConnectorCircle)entity;
                        ModelElements.Add(new SSBasePairCircleConnectorViewModel(basePairVMs[cc.BasePair.FivePrimeIndex + 1])
                        {
                            Color     = cc.Color,
                            Radius    = cc.Radius,
                            Filled    = cc.Filled,
                            Thickness = cc.Thickness
                        });
                    }
                    else if (entity is TextLabel)
                    {
                        TextLabel lc = (TextLabel)entity;
                        ModelElements.Add(new SSTextLabelViewModel(lc.Start.X, lc.Start.Y, lc.Text, new FontFamily(lc.FontFace), (FontStyle)_fscvtr.ConvertFrom(lc.FontStyle),
                                                                   (FontWeight)_fwcvtr.ConvertFrom(lc.FontWeight), lc.FontSize, (Brush)_colorCvtr.ConvertFrom(lc.Color)));
                    }
                    else if (entity is LineLabel)
                    {
                        LineLabel ll = (LineLabel)entity;
                        ModelElements.Add(new SSLineLabelViewModel()
                        {
                            X         = ll.Start.X,
                            Y         = ll.Start.Y,
                            X1        = ll.End.X - ll.Start.X,
                            Y1        = ll.End.Y - ll.Start.Y,
                            Color     = (Brush)_colorCvtr.ConvertFrom(ll.Color),
                            Thickness = ll.LineWeight
                        });
                    }
                    else if (entity is ParallelogramLabel)
                    {
                        ParallelogramLabel            lc = (ParallelogramLabel)entity;
                        SSParallelogramLabelViewModel vm = new SSParallelogramLabelViewModel()
                        {
                            CenterX            = lc.Center.X,
                            CenterY            = lc.Center.Y,
                            Side1Length        = lc.Side1Length,
                            RotationAngle      = lc.Side1Angle,
                            Side2Length        = lc.Side2Length,
                            ParallelogramAngle = lc.Side2Angle,
                            Color      = (Brush)_colorCvtr.ConvertFrom(lc.Color),
                            LineWeight = lc.LineWeight
                        };
                        vm.ComputeParallelogram();
                        ModelElements.Add(vm);
                    }
                    else if (entity is ArcLabel)
                    {
                        ArcLabel            ac = (ArcLabel)entity;
                        SSArcLabelViewModel vm = new SSArcLabelViewModel()
                        {
                            CenterX    = ac.Center.X,
                            CenterY    = ac.Center.Y,
                            Color      = (Brush)_colorCvtr.ConvertFrom(ac.Color),
                            LineWeight = ac.LineWeight,
                            Radius     = ac.Radius,
                            Angle1     = ac.Angle1,
                            Angle2     = ac.Angle2,
                        };
                        vm.ComputeArc();
                        ModelElements.Add(vm);
                    }
                    else if (entity is ArrowLabel)
                    {
                        ArrowLabel            al = (ArrowLabel)entity;
                        SSArrowLabelViewModel vm = new SSArrowLabelViewModel()
                        {
                            ArrowTipX     = al.ArrowTip.X,
                            ArrowTipY     = al.ArrowTip.Y,
                            LeftTipX      = al.LeftTip.X,
                            LeftTipY      = al.LeftTip.Y,
                            Color         = (Brush)_colorCvtr.ConvertFrom(al.Color),
                            LineWeight    = al.LineWeight,
                            TailLength    = al.TailLength,
                            RotationAngle = al.Angle
                        };
                        vm.ComputeArrow();
                        ModelElements.Add(vm);
                    }
                }

                MeasureAndArrangeCanvas();

                return(base.Initialize(data));
            }
            return(false);
        }