Exemplo n.º 1
0
        private void AddToTab(PartDesignBase part)
        {
            var key = new Tuple <PartToolItemBase, PartDesignBase>(part.GetToolItem(), part);

            _tabParts.Add(key);

            if (_tabName == null)
            {
                _tabName = key.Item1.TabName;
            }
            else if (_tabName != key.Item1.TabName)
            {
                throw new ArgumentException(string.Format("parts span tabNames, not sure how to handle that: \"{0}\", \"{1}\"", _tabName, key.Item1.TabName));
            }

            int tabIndex = FindOrCreateTab(key);

            // The standard 2D element is pretty basic, add a tooltip
            FrameworkElement asFramework = key.Item1.Visual2D as FrameworkElement;

            if (asFramework != null && asFramework.ToolTip == null)
            {
                asFramework.ToolTip = new TextBlock()
                {
                    Text = string.Format("volume {0}", Math1D.Avg(part.Scale.X, part.Scale.Y, part.Scale.Z).ToStringSignificantDigits(3)),
                };
            }

            _tabStats[tabIndex].Item2.Children.Add(key.Item1.Visual2D);
        }
Exemplo n.º 2
0
 public override void AddPart(PartToolItemBase part2D, PartDesignBase part3D)
 {
     if (part3D != null)
     {
         AddToTab(part3D);
     }
 }
Exemplo n.º 3
0
        public override void RemovePart(PartToolItemBase part2D, PartDesignBase part3D)
        {
            if (part3D != null)
            {
                RemoveFromTab(part3D);

                this.PreviousRemoved.Add(Tuple.Create(part3D.Token, DateTime.UtcNow));
            }
        }
Exemplo n.º 4
0
        private void RemoveFromTab(PartDesignBase part)
        {
            var previouslyRemoved = this.PreviousRemoved.
                                    Where(o => o.Item1 == part.Token).
                                    OrderByDescending(o => o.Item2).
                                    FirstOrDefault();

            if (previouslyRemoved != null)
            {
                DateTime utcNow       = DateTime.UtcNow;
                TimeSpan gap          = utcNow - previouslyRemoved.Item2;
                double   milliseconds = gap.TotalMilliseconds;
            }



            // Find the part
            int partIndex = FindPart(part);

            if (partIndex < 0)
            {
                // This seems to be a reentry thing
                //throw new ApplicationException("Couldn't find part");
                string trace = Environment.StackTrace;
                return;
            }

            // Find the tab
            int tabIndex = FindTab(_tabParts[partIndex]);

            if (tabIndex < 0)
            {
                throw new ApplicationException("Couldn't find tab");
            }

            // Remove from part
            _tabStats[tabIndex].Item2.Children.Remove(_tabParts[partIndex].Item1.Visual2D);



            if (_tabParts[partIndex].Item2.Token != part.Token)
            {
                throw new ApplicationException("different");
            }

            _tabParts.RemoveAt(partIndex);



            // Maybe remove tab
            if (_tabStats[tabIndex].Item2.Children.Count == 0)
            {
                _tabStats.RemoveAt(tabIndex);
                base.Tabs.RemoveAt(tabIndex);
            }
        }
Exemplo n.º 5
0
        private int FindPart(PartDesignBase part)
        {
            for (int cntr = 0; cntr < _tabParts.Count; cntr++)
            {
                if (_tabParts[cntr].Item2.Token == part.Token)
                {
                    return(cntr);
                }
            }

            return(-1);
        }
Exemplo n.º 6
0
        public Cargo_ShipPart(ShipPartDNA dna, ItemOptions options, EditorOptions editorOptions)
            : base(CargoType.ShipPart)
        {
            PartDesignBase part = BotConstructor.GetPartDesign(dna, editorOptions, true);

            //TODO: This is really ineficient, let design calculate it for real
            //TODO: Volume and Mass should be calculated by the design class (add to PartBase interface)
            var aabb = Math3D.GetAABB(UtilityWPF.GetPointsFromMesh(part.Model));

            this.Volume = (aabb.Item2.X - aabb.Item1.X) * (aabb.Item2.Y - aabb.Item1.Y) * (aabb.Item2.Y - aabb.Item1.Y);

            //TODO: Let the design class return this (expose a property called DryDensity)
            this.Density = Math1D.Avg(options.Thruster_Density, options.Sensor_Density);

            this.PartDNA = dna;
        }
Exemplo n.º 7
0
        private static Tuple <InventoryEntry, PartDesignBase>[] GatherParts_FromPanel(UIElementCollection panel, EditorOptions editorOptions, bool isFinalModel)
        {
            var retVal = new List <Tuple <InventoryEntry, PartDesignBase> >();

            foreach (var item in panel)
            {
                InventoryEntry inventory = item as InventoryEntry;
                if (inventory == null || inventory.Inventory.Part == null)
                {
                    continue;
                }

                PartDesignBase part = BotConstructor.GetPartDesign(inventory.Inventory.Part, editorOptions, isFinalModel);

                retVal.Add(Tuple.Create(inventory, part));
            }

            return(retVal.ToArray());
        }
Exemplo n.º 8
0
        public Icon3D(ShipPartDNA dna, EditorOptions options)
        {
            InitializeComponent();

            // Need to set position to zero, or the image won't be centered (part's model considers position/orientation)
            dna             = UtilityCore.Clone(dna);
            dna.Position    = new Point3D();
            dna.Orientation = Quaternion.Identity;

            PartDesignBase part = BotConstructor.GetPartDesign(dna, options, false);

            this.ItemName = part.PartType;
            this.Part     = part;

            lblName.Text = this.ItemName;

            lblName.Visibility = _showName ? Visibility.Visible : Visibility.Collapsed;

            InitializeTrackball();

            RenderPart();
            InitializeLight();
        }
Exemplo n.º 9
0
 /// <summary>
 /// This would get called if the user deleted a part, then later hit undo.  That part needs to be removed from the tab control again
 /// </summary>
 public virtual void RemovePart(PartToolItemBase part2D, PartDesignBase part3D)
 {
 }
Exemplo n.º 10
0
 public TabControlParts_DragItem(PartDesignBase part3D, PartToolItemBase part2D = null, Action <TabControlParts_DragItem> dropped = null)
 {
     this.Part2D = part2D;
     this.Part3D = part3D;
     _dropped    = dropped;
 }
Exemplo n.º 11
0
        public override void RemovePart(PartToolItemBase part2D, PartDesignBase part3D)
        {
            if (part3D != null)
            {
                RemoveFromTab(part3D);

                this.PreviousRemoved.Add(Tuple.Create(part3D.Token, DateTime.UtcNow));
            }
        }
Exemplo n.º 12
0
        private void AddToTab(PartDesignBase part)
        {
            var key = new Tuple<PartToolItemBase, PartDesignBase>(part.GetToolItem(), part);

            _tabParts.Add(key);

            if (_tabName == null)
            {
                _tabName = key.Item1.TabName;
            }
            else if (_tabName != key.Item1.TabName)
            {
                throw new ArgumentException(string.Format("parts span tabNames, not sure how to handle that: \"{0}\", \"{1}\"", _tabName, key.Item1.TabName));
            }

            int tabIndex = FindOrCreateTab(key);

            // The standard 2D element is pretty basic, add a tooltip
            FrameworkElement asFramework = key.Item1.Visual2D as FrameworkElement;
            if (asFramework != null && asFramework.ToolTip == null)
            {
                asFramework.ToolTip = new TextBlock()
                {
                    Text = string.Format("volume {0}", Math1D.Avg(part.Scale.X, part.Scale.Y, part.Scale.Z).ToStringSignificantDigits(3)),
                };
            }

            _tabStats[tabIndex].Item2.Children.Add(key.Item1.Visual2D);
        }
Exemplo n.º 13
0
        private void RemoveFromTab(PartDesignBase part)
        {
            var previouslyRemoved = this.PreviousRemoved.
                Where(o => o.Item1 == part.Token).
                OrderByDescending(o => o.Item2).
                FirstOrDefault();

            if(previouslyRemoved != null)
            {
                DateTime utcNow = DateTime.UtcNow;
                TimeSpan gap = utcNow - previouslyRemoved.Item2;
                double milliseconds = gap.TotalMilliseconds;
            }





            // Find the part
            int partIndex = FindPart(part);
            if (partIndex < 0)
            {
                // This seems to be a reentry thing
                //throw new ApplicationException("Couldn't find part");
                string trace = Environment.StackTrace;
                return;
            }

            // Find the tab
            int tabIndex = FindTab(_tabParts[partIndex]);
            if (tabIndex < 0)
            {
                throw new ApplicationException("Couldn't find tab");
            }

            // Remove from part
            _tabStats[tabIndex].Item2.Children.Remove(_tabParts[partIndex].Item1.Visual2D);





            if (_tabParts[partIndex].Item2.Token != part.Token)
            {
                throw new ApplicationException("different");
            }

            _tabParts.RemoveAt(partIndex);





            // Maybe remove tab
            if (_tabStats[tabIndex].Item2.Children.Count == 0)
            {
                _tabStats.RemoveAt(tabIndex);
                base.Tabs.RemoveAt(tabIndex);
            }
        }
Exemplo n.º 14
0
        private int FindPart(PartDesignBase part)
        {
            for (int cntr = 0; cntr < _tabParts.Count; cntr++)
            {
                if (_tabParts[cntr].Item2.Token == part.Token)
                {
                    return cntr;
                }
            }

            return -1;
        }
Exemplo n.º 15
0
 public TabControlParts_DragItem(PartDesignBase part3D, PartToolItemBase part2D = null, Action<TabControlParts_DragItem> dropped = null)
 {
     this.Part2D = part2D;
     this.Part3D = part3D;
     _dropped = dropped;
 }
Exemplo n.º 16
0
 /// <summary>
 /// This would get called if the user deleted a part, then later hit undo.  That part needs to be removed from the tab control again
 /// </summary>
 public virtual void RemovePart(PartToolItemBase part2D, PartDesignBase part3D)
 {
 }
Exemplo n.º 17
0
 public override void AddPart(PartToolItemBase part2D, PartDesignBase part3D)
 {
     if (part3D != null)
     {
         AddToTab(part3D);
     }
 }