Example #1
0
        public static IEnumerable <Entity> AllSolidsFromCurrentDrawing()
        {
            var promtResut = new DefaultFactory().CreateDocumentManager().MdiActiveDocument.Editor.SelectAll();

            if (promtResut.Status == PromptStatus.Error || promtResut.Value == null)
            {
                yield break;
            }

            var objectIds   = promtResut.Value.GetObjectIds();
            var transaction = new DefaultFactory().CreateDocumentManager().MdiActiveDocument.Database.TransactionManager.StartTransaction();

            foreach (var objectId in objectIds)
            {
                var dbObject = transaction.GetObject(objectId, OpenMode.ForRead);

                if (dbObject.GetType() == typeof(Solid3d))
                {
                    yield return((Entity)dbObject);
                }
            }
        }
Example #2
0
        public static List <Entity> AskUserToSelectSolids()
        {
            var document         = new DefaultFactory().CreateDocumentManager().MdiActiveDocument;
            var database         = document.Database;
            var editor           = document.Editor;
            var transaction      = database.TransactionManager.StartTransaction();
            var selectionOptions = new PromptSelectionOptions {
                MessageForAdding = "Select solids to analyze: "
            };
            var promptSelectionResult = editor.GetSelection(selectionOptions);

            if (promptSelectionResult.Status != PromptStatus.OK)
            {
                transaction.Commit();
                transaction.Dispose();
                return(new List <Entity>());
            }

            var solids    = new List <Entity>();
            var objectIds = promptSelectionResult.Value.GetObjectIds();

            foreach (var objectId in objectIds)
            {
                var dbObject = transaction.GetObject(objectId, OpenMode.ForRead);

                if (dbObject.GetType() == typeof(Solid3d))
                {
                    solids.Add((Entity)dbObject);
                }
            }

            transaction.Commit();
            transaction.Dispose();

            return(solids);
        }
Example #3
0
        public static string GetDocumentName()
        {
            var pathToOpenDocument = new DefaultFactory().CreateDocumentManager().MdiActiveDocument.Name;

            return(Path.GetFileNameWithoutExtension(pathToOpenDocument));
        }
Example #4
0
        private void CalculationThread()
        {
            WaitEvent.WaitOne(); // Waiting for GUI thread.

            #region Input validation

            if (fdsStartInfo == null)
            {
                log.LogInfo("Calculation was not started because no start info was provided.");
                return;
            }

            var selectedSolids = fdsStartInfo.SelectedSolids;

            if (selectedSolids == null || selectedSolids.Count < 1)
            {
                log.LogInfo("No solids to convert were provided.");
                return;
            }

            var pluginConfig = new DefaultFactory(log).CreateFdsConfig();

            if (pluginConfig == null)
            {
                log.LogInfo("No config was provided.");
                return;
            }

            #endregion

            #region Convert geometry

            var allOptimizedElements = new List <Element>();
            var minMaxPoint          = SolidToElementConverter.GetMaxMinPoint(selectedSolids);
            var progress             = 0;

            foreach (var solid in selectedSolids)
            {
                // LEVEL OPTIMIZER TEST

                SolidToElementConverter converter = pluginConfig.UseCustomElementSize
                                                  ? new SolidToElementConverter(solid, pluginConfig.ElementSize)
                                                  : new SolidToElementConverter(solid);

                var valuableElements = converter.ValueableElements;

                #region Handle out of memory exception

                if (!converter.IsSuccessfullConversion)
                {
                    var result = UserNotifier.ShowWarningWithConfirmation(Constants.OutOfMemoruMessage);

                    if (result == DialogResult.Cancel)
                    {
                        if (progressWindow != null)
                        {
                            progressWindow.ForceClose = true;
                            Action action = progressWindow.Close;
                            progressWindow.Invoke(action);
                        }

                        return;
                    }

                    break;
                }

                #endregion

                var optimizer = new LevelOptimizer(valuableElements);

                allOptimizedElements.AddRange(optimizer.Optimize());

                // GET ALL VALUABLE ELEMENTS TEST
                // allOptimizedElements.AddRange(new SolidToElementConverter(solid).ValueableElements);

                if (progressWindow != null)
                {
                    progressWindow.Update(progress, string.Format(Constants.ConvertedSolidsInfoPattern, progress, selectedSolids.Count));
                }

                progress++;
            }

            selectedSolids.Clear();
            selectedSolids = null;

            #endregion

            #region Handle negative offset

            var minPoint = minMaxPoint[0];

            var vector = ElementHelper.InitNegativeOffsetVector(minPoint);

            if (vector != null)
            {
                foreach (var element in allOptimizedElements)
                {
                    element.Center.MoveUsingNegativeOffsetVector(vector);
                }

                minMaxPoint[0].MoveUsingNegativeOffsetVector(vector);
                minMaxPoint[1].MoveUsingNegativeOffsetVector(vector);
            }

            #endregion

            #region Generating output

            var usedSurfaces      = fdsStartInfo.UsedSurfaces;
            var requiredMaterials = usedSurfaces.GetNecessaryMaterialsFromSurfaces(log);
            var mappings          = XmlSerializer <List <MaterialAndSurface> > .Deserialize(PluginInfoProvider.PathToMappingsMaterials, log);

            var materialsToSurfaces = mappings.GetDictionary();

            var maxPoint = minMaxPoint[1];

            var documentName = fdsStartInfo.DocumentName;

            var pathToFile = Path.Combine(fdsStartInfo.WorkingDirectory, string.Concat(documentName, Constants.FdsFileExtension));

            var templateManager = new TemplateManager(Info.PluginDirectory, Constants.FdsTemplateName);

            var parameters = new Dictionary <string, object>
            {
                { "elements", allOptimizedElements },
                { "usedSurfaces", usedSurfaces },
                { "usedMaterials", requiredMaterials },
                { "materialsToSurfaces", materialsToSurfaces },
                { "calculationTime", fdsStartInfo.CalculationTime },
                { "name", documentName },
                { "maxPoint", maxPoint }
            };

            templateManager.MergeTemplateWithObjects(parameters, pathToFile);

            #endregion

            #region Start FDS

            var startInfo = new ProcessStartInfo
            {
                Arguments        = string.Concat("\"", pathToFile, "\""),         //fdsStartInfo.Arguments,
                FileName         = fdsStartInfo.PathToFds,
                WorkingDirectory = fdsStartInfo.WorkingDirectory
            };

            Process.Start(startInfo);

            #endregion

            if (progressWindow != null)
            {
                progressWindow.ForceClose = true;
                progressWindow.Close();
            }
        }