Ejemplo n.º 1
0
        private void btnMerge_Click(object sender, EventArgs e)
        {
            var models = new List <SvfModel>();

            foreach (SvfModel item in svfModelBindingSource)
            {
                if (item == null)
                {
                    continue;
                }
                models.Add(item);
            }
            if (models.Count < 1)
            {
                MessageBox.Show(this, @"The source model list is empty!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (string.IsNullOrEmpty(txtOutput.Text))
            {
                MessageBox.Show(this, @"Please Select Output Path!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            using (var session = LicenseConfig.Create())
            {
                if (session.IsValid == false)
                {
                    LicenseConfig.ShowDialog(session, this);
                    return;
                }

                using (new ProgressHelper(this, @"Merging ..."))
                {
                    try
                    {
                        var sw        = Stopwatch.StartNew();
                        var targetDoc = new SvfDocument();
                        var docs      = new List <SvfDocument>();
                        var init      = false;
                        foreach (var model in models)
                        {
                            var doc = model.ModelPath.EndsWith(@"zip")
                                ? SvfDocument.LoadFromZipFile(model.ModelPath)
                                : SvfDocument.LoadFromSvfFile(model.ModelPath);
                            doc.Model.Name = model.ModelTitle;

                            if (!init)
                            {
                                targetDoc.Metadata = doc.Metadata.Clone();
                                init = true;
                            }

                            if (targetDoc.Metadata.DefaultCamera == null && doc.Metadata.DefaultCamera != null)
                            {
                                targetDoc.Metadata.DefaultCamera = doc.Metadata.DefaultCamera.Clone();
                            }

                            var transform = Metadata
                                            .GetUnitScaleTransform(doc.Metadata.Units, targetDoc.Metadata.Units)
                                            .Multiply(doc.Metadata.RefPointTransform);

                            targetDoc.Model.Children.ImportNode(doc.Model, transform);

                            doc.Reset();
                            docs.Add(doc);
                        }

                        if (targetDoc.Metadata.DefaultCamera != null)
                        {
                            targetDoc.Metadata.DefaultCamera.AutoFit = true;
                        }

                        targetDoc.SaveToFolder(txtOutput.Text, true);
                        targetDoc.Dispose();

                        foreach (var doc in docs)
                        {
                            doc.Dispose();
                        }
                        docs.Clear();

                        ProgressHelper.Close();
                        var message = $@"Merge 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);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            using (var session = App.CreateSession())
            {
                if (session.IsValid == false)
                {
                    LicenseSession.ShowLicenseDialog(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";

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

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

                        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);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void btnMerge_Click(object sender, EventArgs e)
        {
            var models = new List <SvfModel>();

            foreach (SvfModel item in svfModelBindingSource)
            {
                if (item == null)
                {
                    continue;
                }
                models.Add(item);
            }
            if (models.Count < 1)
            {
                MessageBox.Show(this, @"The source model list is empty!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (string.IsNullOrEmpty(txtOutput.Text))
            {
                MessageBox.Show(this, @"Please Select Output Path!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            var mode = (int)((cbPositioningMode.SelectedItem as ItemValue <PositioningMode>)?.Value ?? PositioningMode.BySharedCoordinates);

            using (var session = LicenseConfig.Create())
            {
                if (session.IsValid == false)
                {
                    LicenseConfig.ShowDialog(session, this);
                    return;
                }

                using (new ProgressHelper(this, @"Merging ..."))
                {
                    try
                    {
                        var sw        = Stopwatch.StartNew();
                        var targetDoc = new SvfDocument();
                        var docs      = new List <SvfDocument>();
                        var init      = false;
                        foreach (var model in models)
                        {
                            var doc = model.ModelPath.EndsWith(@"zip")
                                ? SvfDocument.LoadFromZipFile(model.ModelPath)
                                : SvfDocument.LoadFromSvfFile(model.ModelPath);
                            doc.Model.Name = model.ModelTitle;

                            if (!init)
                            {
                                targetDoc.Metadata = doc.Metadata.Clone();
                                init = true;
                            }

                            if (targetDoc.Metadata.DefaultCamera == null && doc.Metadata.DefaultCamera != null)
                            {
                                targetDoc.Metadata.DefaultCamera = doc.Metadata.DefaultCamera.Clone();
                            }

                            Transform transform;
                            switch (mode)
                            {
                            case 1:     //原点对原点
                            {
                                transform = Metadata
                                            .GetUnitScaleTransform(doc.Metadata.Units, targetDoc.Metadata.Units);
                                break;
                            }

                            case 2:     //项目基点对项目基点
                            {
                                transform = Metadata
                                            .GetUnitScaleTransform(doc.Metadata.Units, targetDoc.Metadata.Units)
                                            .Multiply(doc.Metadata.PrjPointTransform);
                                break;
                            }

                            case 3:     //中心对中心
                            {
                                var box = doc.Metadata.WorldBoundingBox;
                                if (box == null || box.Empty())
                                {
                                    transform = Metadata
                                                .GetUnitScaleTransform(doc.Metadata.Units, targetDoc.Metadata.Units);
                                }
                                else
                                {
                                    var offset = new Vector3D();
                                    offset.X  = -(box.Max.X + box.Min.X) / 2;
                                    offset.Y  = -(box.Max.Y + box.Min.Y) / 2;
                                    offset.Z  = -(box.Max.Z + box.Min.Z) / 2;
                                    transform = Metadata
                                                .GetUnitScaleTransform(doc.Metadata.Units, targetDoc.Metadata.Units)
                                                .Multiply(Transform.GetTranslation(offset));
                                }
                                break;
                            }

                            case 0:     //通过共享坐标
                            default:
                            {
                                transform = Metadata
                                            .GetUnitScaleTransform(doc.Metadata.Units, targetDoc.Metadata.Units)
                                            .Multiply(doc.Metadata.RefPointTransform);
                                break;
                            }
                            }

                            targetDoc.Model.Children.ImportNode(doc.Model, transform);

                            doc.Reset();
                            docs.Add(doc);
                        }

                        if (targetDoc.Metadata.DefaultCamera != null)
                        {
                            targetDoc.Metadata.DefaultCamera.AutoFit = true;
                        }

                        targetDoc.SaveToFolder(txtOutput.Text, true);
                        targetDoc.Dispose();

                        foreach (var doc in docs)
                        {
                            doc.Dispose();
                        }
                        docs.Clear();

                        ProgressHelper.Close();
                        var message = $@"Merge 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);
                    }
                }
            }
        }