예제 #1
0
파일: odfEditor.cs 프로젝트: kkdevs/sb3u
        public void MergeMaterial(odfMaterial srcMat, odfParser srcParser)
        {
            odfMaterial newMat = srcMat.Clone();

            bool found = false;

            for (int i = 0; i < Parser.MaterialSection.Count; i++)
            {
                odfMaterial oldMat = Parser.MaterialSection[i];
                if (oldMat.Name == newMat.Name)
                {
                    newMat.Id = oldMat.Id;
                    Parser.MaterialSection.RemoveChild(i);
                    Parser.MaterialSection.InsertChild(i, newMat);

                    found = true;
                    break;
                }
            }

            if (!found)
            {
                Parser.MaterialSection.AddChild(newMat);
                if (Parser.IsUsedID(newMat.Id))
                {
                    newMat.Id = Parser.GetNewID(typeof(odfMaterial));
                    Report.ReportLog("Warning! Material " + newMat.Name + " got a new ID : " + newMat.Id);
                }
                else
                {
                    Parser.UsedIDs.Add((int)newMat.Id, typeof(odfMaterial));
                }
            }

            if (Parser.MataSection != null && srcParser.MataSection != null)
            {
                odfMaterialList newMatList = odf.FindMaterialList(newMat.Id, srcParser.MataSection);
                if (newMatList != null)
                {
                    odfMaterialList matList = odf.FindMaterialList(newMat.Id, Parser.MataSection);
                    if (matList != null)
                    {
                        int originalIdx = Parser.MataSection.IndexOf(matList);
                        Parser.MataSection.RemoveChild(originalIdx);
                        Parser.MataSection.InsertChild(originalIdx, newMatList);
                    }
                    else
                    {
                        Parser.MataSection.AddChild(newMatList);
                    }
                }
            }
        }
예제 #2
0
파일: odfEditor.cs 프로젝트: kkdevs/sb3u
        public void CopyMaterial(int idx)
        {
            odfMaterial mat    = Parser.MaterialSection[idx];
            odfMaterial newMat = mat.Clone();

            newMat.Name.Name += "_copy";
            newMat.Id         = Parser.GetNewID(typeof(odfMaterial));
            Parser.MaterialSection.AddChild(newMat);

            if (Parser.MataSection != null)
            {
                for (int i = 0; i < Parser.MataSection.Count; i++)
                {
                    odfMaterialList matList = Parser.MataSection[i];
                    if (matList.MaterialId == mat.Id)
                    {
                        odfMaterialList newMatList = matList.Clone();
                        newMatList.MaterialId = newMat.Id;
                        Parser.MataSection.AddChild(newMatList);
                        break;
                    }
                }
            }
        }