Esempio n. 1
0
        public void RemoveItem(ItemBase item)
        {
            // sanity check
            if (null == item)
            {
                Debug.Assert(false);
                return;
            }
            // dispose item first as it may remove dependancies itself
            _log.Debug(string.Format("Disposing {0}...", item.Name));
            item.Dispose();

            // notify listeners / remove
            if (item.GetType() == typeof(BoxProperties)
                || item.GetType() == typeof(BundleProperties)
                || item.GetType() == typeof(CaseOfBoxesProperties)
                || item.GetType() == typeof(PackProperties)
                || item.GetType() == typeof(PalletProperties)
                || item.GetType() == typeof(InterlayerProperties)
                || item.GetType() == typeof(PalletCornerProperties)
                || item.GetType() == typeof(PalletCapProperties)
                || item.GetType() == typeof(PalletFilmProperties)
                || item.GetType() == typeof(TruckProperties)
                || item.GetType() == typeof(CylinderProperties))
            {
                NotifyOnTypeRemoved(item);
                if (!_typeList.Remove(item))
                    _log.Warn(string.Format("Failed to properly remove item {0}", item.Name));
            }
            else if (item.GetType() == typeof(CasePalletAnalysis))
            {
                NotifyOnAnalysisRemoved(item as CasePalletAnalysis);
                if (!_casePalletAnalyses.Remove(item as CasePalletAnalysis))
                    _log.Warn(string.Format("Failed to properly remove analysis {0}", item.Name));
            }
            else if (item.GetType() == typeof(PackPalletAnalysis))
            {
                NotifyOnAnalysisRemoved(item as PackPalletAnalysis);
                if (!_packPalletAnalyses.Remove(item as PackPalletAnalysis))
                    _log.Warn(string.Format("Failed to properly remove analysis {0}", item.Name));
            }
            else if (item.GetType() == typeof(BoxCaseAnalysis))
            {
                NotifyOnAnalysisRemoved(item as BoxCaseAnalysis);
                if (!_boxCaseAnalyses.Remove(item as BoxCaseAnalysis))
                    _log.Warn(string.Format("Failed to properly remove analysis {0}", item.Name));
            }
            else if (item.GetType() == typeof(CylinderPalletAnalysis))
            {
                NotifyOnAnalysisRemoved(item as CylinderPalletAnalysis);
                if (!_cylinderPalletAnalyses.Remove(item as CylinderPalletAnalysis))
                    _log.Warn(string.Format("Failed to properly remove analysis {0}", item.Name));
            }
            else if (item.GetType() == typeof(HCylinderPalletAnalysis))
            {
                NotifyOnAnalysisRemoved(item as HCylinderPalletAnalysis);
                if (!_hCylinderPalletAnalyses.Remove(item as HCylinderPalletAnalysis))
                    _log.Warn(string.Format("Failed to properly remove analysis {0}", item.Name));
            }
            else if (item.GetType() == typeof(TruckAnalysis))
            {
                TruckAnalysis truckAnalysis = item as TruckAnalysis;
                NotifyOnTruckAnalysisRemoved(truckAnalysis.ParentSelSolution, truckAnalysis);
            }
            else if (item.GetType() == typeof(BoxCasePalletAnalysis))
            {
                BoxCasePalletAnalysis caseAnalysis = item as BoxCasePalletAnalysis;
                NotifyOnAnalysisRemoved(caseAnalysis);
                if (!_boxCasePalletOptimizations.Remove(caseAnalysis))
                    _log.Warn(string.Format("Failed to properly remove analysis {0}", item.Name));
            }
            else if (item.GetType() == typeof(ECTAnalysis))
            {
                ECTAnalysis ectAnalysis = item as ECTAnalysis;
                NotifyOnECTAnalysisRemoved(ectAnalysis.ParentSelSolution, ectAnalysis);
            }
            else if (item.GetType() == typeof(SelCasePalletSolution)) { }
            else if (item.GetType() == typeof(SelBoxCasePalletSolution)) { }
            else if (item.GetType() == typeof(SelBoxCaseSolution)) { }
            else if (item.GetType() == typeof(SelCylinderPalletSolution)) { }
            else if (item.GetType() == typeof(SelHCylinderPalletSolution)) { }
            else if (item.GetType() == typeof(SelPackPalletSolution)) { }
            else
                Debug.Assert(false);
            Modify();
        }
 /// <summary>
 /// handles new type creation
 /// </summary>
 /// <param name="doc"></param>
 /// <param name="itemProperties"></param>
 public void OnNewTypeCreated(Document doc, ItemBase itemProperties)
 {
     int iconIndex = 0;
     NodeTag.NodeType nodeType = NodeTag.NodeType.NT_BOX;
     NodeTag.NodeType parentNodeType = NodeTag.NodeType.NT_LISTBOX;
     if (itemProperties.GetType() == typeof(CaseOfBoxesProperties))
     {
         iconIndex = 17;
         nodeType = NodeTag.NodeType.NT_CASEOFBOXES;
         parentNodeType = NodeTag.NodeType.NT_LISTCASE;
     }
     else if (itemProperties.GetType() == typeof(BoxProperties))
     {
         BoxProperties boxProperties = itemProperties as BoxProperties;
         if (boxProperties.HasInsideDimensions)
         {
             iconIndex = 4;
             nodeType = NodeTag.NodeType.NT_CASE;
             parentNodeType = NodeTag.NodeType.NT_LISTCASE;
         }
         else
         {
             iconIndex = 3;
             nodeType = NodeTag.NodeType.NT_BOX;
             parentNodeType = NodeTag.NodeType.NT_LISTBOX;
         }
     }
     else if (itemProperties.GetType() == typeof(BundleProperties))
     {
         iconIndex = 5;
         nodeType = NodeTag.NodeType.NT_BUNDLE;
         parentNodeType = NodeTag.NodeType.NT_LISTBUNDLE;
     }
     else if (itemProperties.GetType() == typeof(CylinderProperties))
     {
         iconIndex = 6;
         nodeType = NodeTag.NodeType.NT_CYLINDER;
         parentNodeType = NodeTag.NodeType.NT_LISTCYLINDER;
     }
     else if (itemProperties.GetType() == typeof(PalletProperties))
     {
         iconIndex = 7;
         nodeType = NodeTag.NodeType.NT_PALLET;
         parentNodeType = NodeTag.NodeType.NT_LISTPALLET;
     }
     else if (itemProperties.GetType() == typeof(InterlayerProperties))
     {
         iconIndex = 8;
         nodeType = NodeTag.NodeType.NT_INTERLAYER;
         parentNodeType = NodeTag.NodeType.NT_LISTINTERLAYER;
     }
     else if (itemProperties.GetType() == typeof(TruckProperties))
     {
         iconIndex = 9;
         nodeType = NodeTag.NodeType.NT_TRUCK;
         parentNodeType = NodeTag.NodeType.NT_LISTTRUCK;
     }
     else if (itemProperties.GetType() == typeof(PalletCornerProperties))
     {
         iconIndex = 10;
         nodeType = NodeTag.NodeType.NT_PALLETCORNERS;
         parentNodeType = NodeTag.NodeType.NT_LISTPALLETCORNERS;
     }
     else if (itemProperties.GetType() == typeof(PalletCapProperties))
     {
         iconIndex = 11;
         nodeType = NodeTag.NodeType.NT_PALLETCAP;
         parentNodeType = NodeTag.NodeType.NT_LISTPALLETCAP;
     }
     else if (itemProperties.GetType() == typeof(PalletFilmProperties))
     {
         iconIndex = 12;
         nodeType = NodeTag.NodeType.NT_PALLETFILM;
         parentNodeType = NodeTag.NodeType.NT_LISTPALLETFILM;
     }
     else if (itemProperties.GetType() == typeof(PackProperties))
     {
         iconIndex = 22;
         nodeType = NodeTag.NodeType.NT_PACK;
         parentNodeType = NodeTag.NodeType.NT_LISTPACK;
     }
     else
     {
         Debug.Assert(false);
         _log.Error("AnalysisTreeView.OnNewTypeCreated() -> unknown type!");
         return;
     }
     // get parent node
     TreeNode parentNode = FindNode(null, new NodeTag(parentNodeType, doc));
     if (null == parentNode)
     {
         _log.Error(string.Format("Failed to load parentNode for {0}", itemProperties.Name));
         return;
     }
     // instantiate node
     TreeNode nodeItem = new TreeNode(itemProperties.Name, iconIndex, iconIndex);
     // set node tag
     nodeItem.Tag = new NodeTag(nodeType, doc, itemProperties);
     // insert
     parentNode.Nodes.Add(nodeItem);
     parentNode.Expand();
     // if item is CaseOfBoxesProperties
     if (itemProperties is CaseOfBoxesProperties)
     {
         // insert sub node
         CaseOfBoxesProperties caseOfBoxesProperties = itemProperties as CaseOfBoxesProperties;
         TreeNode subNode = new TreeNode(caseOfBoxesProperties.InsideBoxProperties.Name, 3, 3);
         subNode.Tag = new NodeTag(NodeTag.NodeType.NT_BOX, doc, caseOfBoxesProperties.InsideBoxProperties);
         nodeItem.Nodes.Add(subNode);
     }
 }
 /// <summary>
 /// handles new type removed
 /// </summary>
 /// <param name="doc"></param>
 /// <param name="itemBase"></param>
 public void OnTypeRemoved(Document doc, ItemBase itemBase)
 {
     NodeTag.NodeType nodeType = NodeTag.NodeType.NT_UNKNOWN;
     if (itemBase.GetType() == typeof(BoxProperties))
     {
         BoxProperties box = itemBase as BoxProperties;
         if (box.HasInsideDimensions)
             nodeType = NodeTag.NodeType.NT_CASE;
         else
             nodeType = NodeTag.NodeType.NT_BOX;
     }
     else if (itemBase.GetType() == typeof(BundleProperties))
         nodeType = NodeTag.NodeType.NT_BUNDLE;
     else if (itemBase.GetType() == typeof(PackProperties))
         nodeType = NodeTag.NodeType.NT_PACK;
     else if (itemBase.GetType() == typeof(CaseOfBoxesProperties))
         nodeType = NodeTag.NodeType.NT_CASEOFBOXES;
     else if (itemBase.GetType() == typeof(InterlayerProperties))
         nodeType = NodeTag.NodeType.NT_INTERLAYER;
     else if (itemBase.GetType() == typeof(PalletCornerProperties))
         nodeType = NodeTag.NodeType.NT_PALLETCORNERS;
     else if (itemBase.GetType() == typeof(PalletCapProperties))
         nodeType = NodeTag.NodeType.NT_PALLETCAP;
     else if (itemBase.GetType() == typeof(PalletFilmProperties))
         nodeType = NodeTag.NodeType.NT_PALLETFILM;
     else if (itemBase.GetType() == typeof(PalletProperties))
         nodeType = NodeTag.NodeType.NT_PALLET;
     else if (itemBase.GetType() == typeof(TruckProperties))
         nodeType = NodeTag.NodeType.NT_TRUCK;
     else if (itemBase.GetType() == typeof(CylinderProperties))
         nodeType = NodeTag.NodeType.NT_CYLINDER;
     Debug.Assert(nodeType != NodeTag.NodeType.NT_UNKNOWN);
     if (nodeType == NodeTag.NodeType.NT_UNKNOWN)
         return; // ->not found exit
     // get node
     TreeNode typeNode = FindNode(null, new NodeTag(nodeType, doc, itemBase));
     // remove node
     if (null != typeNode)
         Nodes.Remove(typeNode);
 }
        public void OnAnalysisRemoved(Document doc, ItemBase analysis)
        {
            NodeTag.NodeType nodeType = NodeTag.NodeType.NT_UNKNOWN;
            if (analysis.GetType() == typeof(CasePalletAnalysis)) nodeType = NodeTag.NodeType.NT_CASEPALLETANALYSIS;
            else if (analysis.GetType() == typeof(PackPalletAnalysis)) nodeType = NodeTag.NodeType.NT_PACKPALLETANALYSIS;
            else if (analysis.GetType() == typeof(CylinderPalletAnalysis)) nodeType = NodeTag.NodeType.NT_CYLINDERPALLETANALYSIS;
            else if (analysis.GetType() == typeof(HCylinderPalletAnalysis)) nodeType = NodeTag.NodeType.NT_HCYLINDERPALLETANALYSIS;
            else if (analysis.GetType() == typeof(BoxCaseAnalysis)) nodeType = NodeTag.NodeType.NT_BOXCASEANALYSIS;
            else if (analysis.GetType() == typeof(BoxCasePalletAnalysis)) nodeType = NodeTag.NodeType.NT_BOXCASEPALLETANALYSIS;

            // get node
            TreeNode analysisNode = FindNode(null, new NodeTag(nodeType, doc, analysis));
            // test
            if (null == analysisNode)
            {
                _log.Warn(string.Format("Failed to find a valid tree node for analysis {0}", analysis.Name));
                return;
            }
            // remove node
            Nodes.Remove(analysisNode);
        }