Esempio n. 1
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            using (var session = LicenseConfig.Create())
            {
                if (session.IsValid == false)
                {
                    LicenseConfig.ShowDialog(session, this);
                    return;
                }

                using (new ProgressHelper(this, @"Generating Diff Model ..."))
                {
                    try
                    {
                        var sw = Stopwatch.StartNew();

                        #region setup materials

                        var matUnmodified = new Material
                        {
                            Color        = Vector3D.FromColor(0xffffff), //Darker: Vector3D.FromColor(0x101010)
                            Transparent  = 0.95,
                            Reflectivity = 0
                        };

                        var matAdd = new Material
                        {
                            Color = Vector3D.FromColor(Color.GreenYellow)
                        };

                        var matDelete = new Material
                        {
                            Color = Vector3D.FromColor(Color.Red)
                        };

                        var matModifiedBefore = new Material
                        {
                            Color       = Vector3D.FromColor(Color.Orange),
                            Transparent = 0.5
                        };

                        var matModifiedAfter = new Material
                        {
                            Color = Vector3D.FromColor(Color.Aqua),
                        };

                        #endregion

                        var baseModelPath = txtBaseModel.Text;
                        var incrModelPath = txtIncrementModel.Text;
                        var diffModelPath = txtDiffModel.Text;

                        var svfbase = baseModelPath.EndsWith(@"zip")
                            ? SvfDocument.LoadFromZipFile(baseModelPath)
                            : SvfDocument.LoadFromSvfFile(baseModelPath);

                        var svfincr = incrModelPath.EndsWith(@"zip")
                            ? SvfDocument.LoadFromZipFile(incrModelPath)
                            : SvfDocument.LoadFromSvfFile(incrModelPath);

                        var compareResult = CompareModel(svfbase, svfincr);

                        var svfdiff = new SvfDocument();
                        svfdiff.Model.Name = @"Diff Model";
                        svfdiff.Metadata   = svfbase.Metadata;

                        var nodeUnmodified = svfdiff.Model.Children.CreateNode();
                        nodeUnmodified.Name = @"Unmodified";

                        var nodeAdded = svfdiff.Model.Children.CreateNode();
                        nodeAdded.Name = @"Added";

                        var nodeDeleted = svfdiff.Model.Children.CreateNode();
                        nodeDeleted.Name = @"Deleted";

                        var nodeModifiedBefore = svfdiff.Model.Children.CreateNode();
                        nodeModifiedBefore.Name = @"Modified Before";

                        var nodeModifiedAfter = svfdiff.Model.Children.CreateNode();
                        nodeModifiedAfter.Name = @"Modified After";

                        foreach (var node in svfbase)
                        {
                            if (node.Children?.Count == 0 &&
                                node.Fragments?.Count > 0 &&
                                string.IsNullOrEmpty(node.ExternalId) == false)
                            {
                                var nodeKey = node.GetKey();
                                if (compareResult.Unmodified.Remove(nodeKey))
                                {
                                    ImportNodeWithPath(nodeUnmodified, node, svfbase.Model, matUnmodified);
                                }
                                else if (compareResult.Deleted.Remove(nodeKey))
                                {
                                    ImportNodeWithPath(nodeDeleted, node, svfbase.Model, matDelete);
                                }
                                else if (compareResult.Modified.Contains(nodeKey))
                                {
                                    var targetNode = ImportNodeWithPath(nodeModifiedBefore, node, svfbase.Model, matModifiedBefore);
                                    targetNode.ExternalId += @"_Before";
                                }
                            }
                        }

                        foreach (var node in svfincr)
                        {
                            if (node.Children?.Count == 0 &&
                                node.Fragments?.Count > 0 &&
                                string.IsNullOrEmpty(node.ExternalId) == false)
                            {
                                var nodeKey = node.GetKey();
                                if (compareResult.Added.Remove(nodeKey))
                                {
                                    ImportNodeWithPath(nodeAdded, node, svfincr.Model, matAdd);
                                }
                                else if (compareResult.Modified.Remove(nodeKey))
                                {
                                    ImportNodeWithPath(nodeModifiedAfter, node, svfincr.Model, matModifiedAfter);
                                }
                            }
                        }

                        svfdiff.SaveToFolder(diffModelPath, true);
                        svfdiff.Dispose();

                        svfbase.Dispose();
                        svfincr.Dispose();

                        ProgressHelper.Close();
                        var message = $@"Generate Diff Model Success! (duration: {sw.Elapsed})";
                        MessageBox.Show(this, message, Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        ProgressHelper.Close();
                        MessageBox.Show(this, ex.ToString(), Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
Esempio n. 2
0
 private void licenseStatusToolStripMenuItem_Click(object sender, EventArgs e)
 {
     LicenseConfig.ShowDialog(this);
 }