public static SceneBuildSettings ByParameters(string transformationStrategy,
                                                      string positioningStrategy,
                                                      CRSTransform crs,
                                                      UnitScale unitScale,
                                                      string[] sceneContexts,
                                                      string identificationStrategy)
        {
            if (string.IsNullOrEmpty(transformationStrategy) || string.IsNullOrEmpty(positioningStrategy) || string.IsNullOrEmpty(identificationStrategy))
            {
                throw new ArgumentNullException("transformationStrategy | positioningStrategy | identificationStrategy");
            }

            var settings = new SceneBuildSettings(new ExportPreferences
            {
                Transforming    = DynamicArgumentDelegation.TryCastEnumOrDefault <SceneTransformationStrategy>(transformationStrategy),
                Positioning     = DynamicArgumentDelegation.TryCastEnumOrDefault <ScenePositioningStrategy>(positioningStrategy),
                UserModelCenter = crs.Transform.T,
                CRS             = crs.Transform.R * (unitScale?.UnitsPerMeter ?? 1),
                SelectedContext = sceneContexts?.Select(c => new SceneContext {
                    Name = c.ToQualifier()
                }).ToArray() ?? new SceneContext[] { },
                ComponentIdentificationStrategy = DynamicArgumentDelegation.TryCastEnumOrDefault <SceneComponentIdentificationStrategy>(identificationStrategy)
            });

            return(settings);
        }
        /// <summary>
        /// Exports the current component scene to the given format indicated by the extension.
        /// </summary>
        /// <param name="scene">The scene</param>
        /// <param name="unitScale">The scale</param>
        /// <param name="transform">The axes transform</param>
        /// <param name="formatID">The format ID (one of <see cref="exportAsFormats"/>)</param>
        /// <param name="canonicalSeparator">The canonical fragment separator</param>
        /// <returns>The exported scene</returns>
        public static ComponentScene Export(ComponentScene scene, UnitScale unitScale, CRSTransform transform, string formatID, string canonicalSeparator)
        {
            if (null == scene)
            {
                throw new ArgumentNullException(nameof(scene));
            }

            var format = exportAsFormats.FirstOrDefault(f => f.ID == formatID);

            if (null == format)
            {
                throw new ArgumentException($"Unknown format ID {formatID}.");
            }

            var qualifier = BuildQualifierByExtension(scene.Qualifier, format.Extension);
            var fileName  = GetFilePathName(qualifier, canonicalSeparator, true);

            using (var monitor = scene.CreateProgressMonitor(LogReason.Saved))
            {
                try
                {
                    var exp = new TRexAssimp.TRexAssimpExport(new TRexAssimp.TRexAssimpPreferences(transform, unitScale));
                    monitor.NotifyProgressEstimateUpdate(1);
                    monitor.NotifyOnProgressChange(0, "Start exporting");

                    if (!exp.ExportTo(scene.SceneModel, fileName, format))
                    {
                        monitor.State.MarkBroken();
                        scene.OnActionLogged(
                            LogMessage.ByErrorMessage(scene.Name, LogReason.Saved, "An error occured while exporting to '{0}'. {1}", fileName, exp.StatusMessage));
                    }
                    else
                    {
                        monitor.NotifyOnProgressChange(1, "Exported");
                        scene.OnActionLogged(
                            LogMessage.BySeverityAndMessage(scene.Name, LogSeverity.Info, LogReason.Saved, "Scene exported to '{0}'.", fileName));
                    }
                }
                catch (Exception e)
                {
                    monitor.State.MarkBroken();

                    scene.Logger?.LogError(e, "An exception has been caught: {0}", e.Message);
                    scene.OnActionLogged(
                        LogMessage.ByErrorMessage(scene.Name, LogReason.Saved, "Exception '{0}' thrown while exporting to '{1}'.", e.Message, fileName));
                }

                monitor.State.MarkTerminated();
                monitor.NotifyOnProgressEnd();
            }

            return(scene);
        }
Example #3
0
 /// <summary>
 /// Combines two scales, and inherited model scale and a new nested scale of units per meter.
 /// </summary>
 /// <param name="modelScale">The given model scale</param>
 /// <param name="nestedScale">The intrinsic nested model scale</param>
 /// <returns>A combined unit scale, if nested scale is non-null otherwise the model scale</returns>
 public static UnitScale ByModelUnitScale(UnitScale nestedScale, UnitScale modelScale)
 {
     if (null != nestedScale)
     {
         return(new UnitScale
         {
             Reference = $"{nestedScale.Reference} => {modelScale.Reference}",
             Name = $"{modelScale.Name} ({nestedScale.Name})",
             UnitsPerMeter = modelScale.UnitsPerMeter / nestedScale.UnitsPerMeter
         });
     }
     else
     {
         return(modelScale);
     }
 }
 internal static AssociativeNode BuildUnitScaleNode(UnitScale us)
 {
     if (null != us)
     {
         return(AstFactory.BuildFunctionCall(
                    new Func <string, string, float, UnitScale>(UnitScale.ByData),
                    new List <AssociativeNode>()
         {
             AstFactory.BuildStringNode(us.Reference),
             AstFactory.BuildStringNode(us.Name),
             AstFactory.BuildDoubleNode(us.UnitsPerMeter)
         }));
     }
     else
     {
         return(AstFactory.BuildNullNode());
     }
 }
        public SceneBuildSettingsNodeModel()
        {
            InPorts.Add(new PortModel(PortType.Input, this,
                                      new PortData("crs", "Model CRS")));
            InPorts.Add(new PortModel(PortType.Input, this,
                                      new PortData("unitScale", "Scaling units per Meter", UnitScaleNodeModel.BuildUnitScaleNode(UnitScale.ByUnitsPerMeter(1.0f)))));
            InPorts.Add(new PortModel(PortType.Input, this,
                                      new PortData("context", "Provided representation model contexts")));

            OutPorts.Add(new PortModel(PortType.Output, this,
                                       new PortData("settings", "Scene build settings")));

            RegisterAllPorts();
        }