public void Combine_TreeStringsWithSeparators_ResultSeparated() { var result = ExportUtils.Combine("A/", "B/", "C/"); Assert.AreEqual("A/B/C/", result); }
/// <summary> /// Generate Viewpoint /// </summary> /// <param name="elemCheck"></param> /// <returns></returns> private VisualizationInfo generateViewpoint(int elemCheck) { try { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; VisualizationInfo v = new VisualizationInfo(); XYZ centerIMP = new XYZ(); string type = ""; double zoomValue = 1; if (uidoc.ActiveView.ViewType != ViewType.ThreeD) //is a 2D view { XYZ TL = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0]; XYZ BR = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1]; v.SheetCamera = new SheetCamera(); v.SheetCamera.SheetID = uidoc.ActiveView.Id.IntegerValue; v.SheetCamera.TopLeft = new IssueTracker.Data.Point(TL.X, TL.Y, TL.Z); v.SheetCamera.BottomRight = new IssueTracker.Data.Point(BR.X, BR.Y, BR.Z); } else { View3D view3D = (View3D)uidoc.ActiveView; if (!view3D.IsPerspective) //IS ORTHO { XYZ TL = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0]; XYZ BR = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1]; double xO = (TL.X + BR.X) / 2; double yO = (TL.Y + BR.Y) / 2; double zO = (TL.Z + BR.Z) / 2; //converto to METERS centerIMP = new XYZ(xO, yO, zO); double dist = TL.DistanceTo(BR) / 2; //custom value to get solibri zoom value from Corners of Revit UiView XYZ diagVector = TL.Subtract(BR); double customZoomValue = (ProjectSettings.Get("useDefaultZoom", doc.PathName) == "1") ? 1 : 2.5; zoomValue = UnitUtils.ConvertFromInternalUnits(dist * Math.Sin(diagVector.AngleTo(view3D.RightDirection)), DisplayUnitType.DUT_METERS) * customZoomValue; type = "OrthogonalCamera"; } else // it is a perspective view { centerIMP = uidoc.ActiveView.Origin; type = "PerspectiveCamera"; zoomValue = 45; } ViewOrientation3D t = ConvertBasePoint(centerIMP, uidoc.ActiveView.ViewDirection, uidoc.ActiveView.UpDirection, false); XYZ c = t.EyePosition; XYZ vi = t.ForwardDirection; XYZ up = t.UpDirection; if (type == "OrthogonalCamera") { v.OrthogonalCamera = new OrthogonalCamera(); v.OrthogonalCamera.CameraViewPoint.X = UnitUtils.ConvertFromInternalUnits(c.X, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraViewPoint.Y = UnitUtils.ConvertFromInternalUnits(c.Y, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraViewPoint.Z = UnitUtils.ConvertFromInternalUnits(c.Z, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraUpVector.X = UnitUtils.ConvertFromInternalUnits(up.X, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraUpVector.Y = UnitUtils.ConvertFromInternalUnits(up.Y, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraUpVector.Z = UnitUtils.ConvertFromInternalUnits(up.Z, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraDirection.X = UnitUtils.ConvertFromInternalUnits(vi.X, DisplayUnitType.DUT_METERS) * -1; v.OrthogonalCamera.CameraDirection.Y = UnitUtils.ConvertFromInternalUnits(vi.Y, DisplayUnitType.DUT_METERS) * -1; v.OrthogonalCamera.CameraDirection.Z = UnitUtils.ConvertFromInternalUnits(vi.Z, DisplayUnitType.DUT_METERS) * -1; v.OrthogonalCamera.ViewToWorldScale = zoomValue; } else { v.PerspectiveCamera = new PerspectiveCamera(); v.PerspectiveCamera.CameraViewPoint.X = UnitUtils.ConvertFromInternalUnits(c.X, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraViewPoint.Y = UnitUtils.ConvertFromInternalUnits(c.Y, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraViewPoint.Z = UnitUtils.ConvertFromInternalUnits(c.Z, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraUpVector.X = UnitUtils.ConvertFromInternalUnits(up.X, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraUpVector.Y = UnitUtils.ConvertFromInternalUnits(up.Y, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraUpVector.Z = UnitUtils.ConvertFromInternalUnits(up.Z, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraDirection.X = UnitUtils.ConvertFromInternalUnits(vi.X, DisplayUnitType.DUT_METERS) * -1; v.PerspectiveCamera.CameraDirection.Y = UnitUtils.ConvertFromInternalUnits(vi.Y, DisplayUnitType.DUT_METERS) * -1; v.PerspectiveCamera.CameraDirection.Z = UnitUtils.ConvertFromInternalUnits(vi.Z, DisplayUnitType.DUT_METERS) * -1; v.PerspectiveCamera.FieldOfView = zoomValue; } } //COMPONENTS PART FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType(); System.Collections.Generic.ICollection <ElementId> collection = null; if (elemCheck == 0) { collection = collector.ToElementIds(); } else if (elemCheck == 1) { collection = uidoc.Selection.GetElementIds(); } if (null != collection && collection.Any()) { v.Components = new IssueTracker.Data.Component[collection.Count]; for (var i = 0; i < collection.Count; i++) { Guid guid = ExportUtils.GetExportId(doc, collection.ElementAt(i)); string ifcguid = IfcGuid.ToIfcGuid(guid).ToString(); ; v.Components[i] = new Case.IssueTracker.Data.Component(doc.Application.VersionName, collection.ElementAt(i).ToString(), ifcguid); } } return(v); } catch (System.Exception ex1) { TaskDialog.Show("Error!", "exception: " + ex1); } return(null); }
public override void ExportMaterial(Material material, PrefabContext prefabContext) { var urhoPath = EvaluateMaterialName(material); using (var writer = Engine.TryCreateXml(material.GetKey(), urhoPath, ExportUtils.GetLastWriteTimeUtc(material))) { if (writer == null) { return; } var arguments = CreateShaderArguments(material); SetupFlags(material, arguments); var shader = material.shader; for (var i = 0; i < ShaderUtil.GetPropertyCount(shader); i++) { var propertyName = ShaderUtil.GetPropertyName(shader, i); var propertyType = ShaderUtil.GetPropertyType(shader, i); switch (propertyType) { case ShaderUtil.ShaderPropertyType.Color: { ParseColor(propertyName, material.GetColor(propertyName), arguments); break; } case ShaderUtil.ShaderPropertyType.Float: { ParseFloatOrRange(propertyName, material.GetFloat(propertyName), arguments); break; } case ShaderUtil.ShaderPropertyType.Range: { ParseFloatOrRange(propertyName, material.GetFloat(propertyName), arguments); break; } case ShaderUtil.ShaderPropertyType.TexEnv: { ParseTexture(propertyName, material.GetTexture(propertyName), arguments); break; } } } var urhoMaterial = FromMetallicGlossiness(material, arguments); WriteMaterial(writer, urhoMaterial, prefabContext); Engine.ScheduleTexture(arguments.BaseColor, new TextureReference(TextureSemantic.PBRBaseColor)); //Engine.ScheduleTexture(arguments.Bump, new TextureReference(TextureSemantic.Bump)); Engine.ScheduleTexture(arguments.DetailBaseColor, new TextureReference(TextureSemantic.Detail)); Engine.SchedulePBRTextures(arguments, urhoMaterial); Engine.ScheduleTexture(arguments.Emission, new TextureReference(TextureSemantic.Emission)); //Engine.ScheduleTexture(arguments.Occlusion, new TextureReference(TextureSemantic.Occlusion)); } }
private void PrintButton_Click(object sender, EventArgs e) { ExportUtils.ToPdf(_bill); }
protected override void ExportAssetBlock(string assetPath, Type mainType, Object[] assets, PrefabContext prefabContext) { if (mainType == typeof(GameObject)) { var prefab = AssetDatabase.LoadAssetAtPath <GameObject>(assetPath); _meshExporter.ExportMesh(prefab, prefabContext); _prefabExporter.ExportPrefab(new AssetKey(AssetDatabase.AssetPathToGUID(assetPath), 0), _prefabExporter.EvaluatePrefabName(assetPath), prefab); } else { foreach (var asset in assets) { if (asset is Mesh mesh) { EditorTaskScheduler.Default.ScheduleForegroundTask( () => _meshExporter.ExportMeshModel(new MeshSource(mesh), EvaluateMeshName(mesh, prefabContext), mesh.GetKey(), ExportUtils.GetLastWriteTimeUtc(mesh)), mesh.name + " from " + assetPath); } } } foreach (var asset in assets) { if (asset is Mesh mesh) { //We already processed all meshes. } else if (asset is GameObject gameObject) { //We already processed prefab. } else if (asset is Transform transform) { //Skip } else if (asset is MeshRenderer meshRenderer) { //Skip } else if (asset is MeshFilter meshFilter) { //Skip } else if (asset is MeshCollider meshCollider) { //Skip } else if (asset is ProBuilderMesh proBuilderMesh) { //Skip } else if (asset is LODGroup lodGroup) { //Skip } else if (asset is SkinnedMeshRenderer skinnedMeshRenderer) { //Skip } else if (asset is Animation animation) { //Skip } else if (asset is AudioClip audioClip) { EditorTaskScheduler.Default.ScheduleForegroundTask(() => _audioExporter.ExportClip(audioClip), audioClip.name + " from " + assetPath); } else if (asset is Material material) { EditorTaskScheduler.Default.ScheduleForegroundTask(() => _materialExporter.ExportMaterial(material, prefabContext), material.name + " from " + assetPath); } else if (asset is TerrainData terrainData) { EditorTaskScheduler.Default.ScheduleForegroundTask( () => _terrainExporter.ExportTerrain(terrainData, prefabContext), terrainData.name + " from " + assetPath); } else if (asset is Texture2D texture2d) { EditorTaskScheduler.Default.ScheduleForegroundTask( () => _textureExporter.ExportTexture(texture2d), texture2d.name + " from " + assetPath); } else if (asset is Cubemap cubemap) { EditorTaskScheduler.Default.ScheduleForegroundTask(() => _cubemapExporter.Cubemap(cubemap), cubemap.name + " from " + assetPath); } else if (asset is AnimationClip animationClip) { EditorTaskScheduler.Default.ScheduleForegroundTask( () => _animationExporter.ExportAnimation(animationClip, prefabContext), animationClip.name + " from " + assetPath); } else if (asset is AnimatorController animationController) { EditorTaskScheduler.Default.ScheduleForegroundTask( () => _animationControllerExporter.ExportAnimationController(animationController, prefabContext), animationController.name + " from " + assetPath); } } }
public static string GetIFCGuid(this Autodesk.Revit.DB.Element e) { var guid = ExportUtils.GetExportId(e.Document, e.Id); return(ConvertToIFCGuid(guid)); }
public string EvaluateMaterial(TerrainData terrainData) { return(ExportUtils.ReplaceExtension(ExportUtils.GetRelPathFromAsset(_engine.Options.Subfolder, terrainData), ".Material.xml")); }
public string EvaluatePrefabName(string assetPath) { return(ExportUtils.ReplaceExtension(ExportUtils.GetRelPathFromAssetPath(_engine.Options.Subfolder, assetPath), ".xml")); }
private string GetHref(ReportComponentBase obj) { string href = String.Empty; if (!String.IsNullOrEmpty(obj.Hyperlink.Value)) { string hrefStyle = String.Empty; if (obj is TextObject) { TextObject textObject = obj as TextObject; hrefStyle = String.Format("style=\"color:{0}{1}\"", ExportUtils.HTMLColor(textObject.TextColor), !textObject.Font.Underline ? ";text-decoration:none" : String.Empty ); } string url = EncodeURL(obj.Hyperlink.Value); if (obj.Hyperlink.Kind == HyperlinkKind.URL) { href = String.Format("<a {0} href=\"{1}\"" + (obj.Hyperlink.OpenLinkInNewTab ? "target=\"_blank\"" : "") + ">", hrefStyle, obj.Hyperlink.Value); } else if (obj.Hyperlink.Kind == HyperlinkKind.DetailReport) { url = String.Format("{0},{1},{2}", EncodeURL(obj.Name), // object name for security reasons EncodeURL(obj.Hyperlink.ReportParameter), EncodeURL(obj.Hyperlink.Value)); string onClick = String.Format(OnClickTemplate, ReportID, "detailed_report", url); href = String.Format("<a {0} href=\"#\" onclick=\"{1}\">", hrefStyle, onClick); } else if (obj.Hyperlink.Kind == HyperlinkKind.DetailPage) { url = String.Format("{0},{1},{2}", EncodeURL(obj.Name), EncodeURL(obj.Hyperlink.ReportParameter), EncodeURL(obj.Hyperlink.Value)); string onClick = String.Format(OnClickTemplate, ReportID, "detailed_page", url); href = String.Format("<a {0} href=\"#\" onclick=\"{1}\">", hrefStyle, onClick); } else if (SinglePage) { if (obj.Hyperlink.Kind == HyperlinkKind.Bookmark) { href = String.Format("<a {0} href=\"#{1}\">", hrefStyle, url); } else if (obj.Hyperlink.Kind == HyperlinkKind.PageNumber) { href = String.Format("<a {0} href=\"#PageN{1}\">", hrefStyle, url); } } else { string onClick = String.Empty; if (obj.Hyperlink.Kind == HyperlinkKind.Bookmark) { onClick = String.Format(OnClickTemplate, ReportID, "bookmark", url); } else if (obj.Hyperlink.Kind == HyperlinkKind.PageNumber) { onClick = String.Format(OnClickTemplate, ReportID, "goto", url); } if (onClick != String.Empty) { href = String.Format("<a {0} href=\"#\" onclick=\"{1}\">", hrefStyle, onClick); } } } return(href); }
private void DoPageEnd(Stream stream) { ExportUtils.WriteLn(stream, BODY_END); ExportUtils.Write(stream, templates.PageTemplateFooter); }
/// <inheritdoc/> protected override void Finish() { if (!webMode) { if (navigator) { if (saveStreams) { FinishSaveStreams(); } else { if (singlePage) { //if (saveStreams) // Commented because saveStreams is always false!! //{ // int fileIndex = GeneratedFiles.IndexOf(singlePageFileName); // DoPageEnd(generatedStreams[fileIndex]); //} //else //{ using (Stream pageStream = new FileStream(singlePageFileName, FileMode.Append)) { DoPageEnd(pageStream); } //} // Commented because saveStreams is always false!! } ExportHTMLIndex(Stream); GeneratedFiles.Add(targetIndexPath + navFileName); using (FileStream outStream = new FileStream(targetIndexPath + navFileName, FileMode.Create)) { ExportHTMLNavigator(outStream); } //GeneratedFiles.Add(FTargetIndexPath + FOutlineFileName); //using (FileStream OutStream = new FileStream(FTargetIndexPath + FOutlineFileName, FileMode.Create)) // ExportHTMLOutline(OutStream); } } else if (format == HTMLExportFormat.MessageHTML) { FinishMHT(); } else { if (saveStreams) { if (!String.IsNullOrEmpty(singlePageFileName)) { int fileIndex = GeneratedFiles.IndexOf(singlePageFileName); DoPageEnd(GeneratedStreams[fileIndex]); } } else { if (!singlePage) { DoPageStart(Stream, documentTitle, false); int pageCounter = 0; foreach (string genFile in GeneratedFiles) { string ext = Path.GetExtension(genFile); if (ext == ".html" && genFile != FileName) { string file = Path.GetFileName(genFile); if (subFolder) { file = Path.Combine(subFolderPath, file); } ExportUtils.WriteLn(Stream, String.Format("<a href=\"{0}\">Page {1}</a><br />", file, ++pageCounter)); } } } DoPageEnd(Stream); } } } }
public LayerJson(AnimatorControllerLayer layer, string name, int index, Urho3DEngine engine, PrefabContext prefabContext) { stateMachine = ExportUtils.ReplaceExtension(name, $".SM{index}.json"); }
/// <summary> /// External Event Implementation /// </summary> /// <param name="app"></param> public void Execute(UIApplication app) { try { UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; SelElementSet m_elementsToHide = SelElementSet.Create(); List <ElementId> elementids = new List <ElementId>(); // IS ORTHOGONAL if (v.OrthogonalCamera != null) { if (v.OrthogonalCamera.ViewToWorldScale == null || v.OrthogonalCamera.CameraViewPoint == null || v.OrthogonalCamera.CameraUpVector == null || v.OrthogonalCamera.CameraDirection == null) { return; } //type = "OrthogonalCamera"; var zoom = UnitUtils.ConvertToInternalUnits(v.OrthogonalCamera.ViewToWorldScale, DisplayUnitType.DUT_METERS); var CameraDirection = Utils.GetXYZ(v.OrthogonalCamera.CameraDirection.X, v.OrthogonalCamera.CameraDirection.Y, v.OrthogonalCamera.CameraDirection.Z); var CameraUpVector = Utils.GetXYZ(v.OrthogonalCamera.CameraUpVector.X, v.OrthogonalCamera.CameraUpVector.Y, v.OrthogonalCamera.CameraUpVector.Z); var CameraViewPoint = Utils.GetXYZ(v.OrthogonalCamera.CameraViewPoint.X, v.OrthogonalCamera.CameraViewPoint.Y, v.OrthogonalCamera.CameraViewPoint.Z); var orient3d = Utils.ConvertBasePoint(doc, CameraViewPoint, CameraDirection, CameraUpVector, true); View3D orthoView = null; //if active view is 3d ortho use it if (doc.ActiveView.ViewType == ViewType.ThreeD) { View3D ActiveView3D = doc.ActiveView as View3D; if (!ActiveView3D.IsPerspective) { orthoView = ActiveView3D; } } if (orthoView == null) { IEnumerable <View3D> viewcollector3D = get3DViews(doc); //try to use default 3D view if (viewcollector3D.Any() && viewcollector3D.Where(o => o.Name == "{3D}" || o.Name == "BCFortho").Any()) { orthoView = viewcollector3D.Where(o => o.Name == "{3D}" || o.Name == "BCFortho").First(); } } using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Open orthogonal view") == TransactionStatus.Started) { //create a new 3d ortho view if (orthoView == null) { orthoView = View3D.CreateIsometric(doc, getFamilyViews(doc).First().Id); orthoView.Name = "BCFortho"; } orthoView.SetOrientation(orient3d); trans.Commit(); } } uidoc.ActiveView = orthoView; //adjust view rectangle // **** CUSTOM VALUE FOR TEKLA **** // // double x = touple.Item2 // **** CUSTOM VALUE FOR TEKLA **** // double customZoomValue = (MyProjectSettings.Get("useDefaultZoom", doc.PathName) == "1") ? 1 : 2.5; double x = zoom / customZoomValue; XYZ m_xyzTl = uidoc.ActiveView.Origin.Add(uidoc.ActiveView.UpDirection.Multiply(x)).Subtract(uidoc.ActiveView.RightDirection.Multiply(x)); XYZ m_xyzBr = uidoc.ActiveView.Origin.Subtract(uidoc.ActiveView.UpDirection.Multiply(x)).Add(uidoc.ActiveView.RightDirection.Multiply(x)); uidoc.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr); } else if (v.PerspectiveCamera != null) { if (v.PerspectiveCamera.FieldOfView == null || v.PerspectiveCamera.CameraViewPoint == null || v.PerspectiveCamera.CameraUpVector == null || v.PerspectiveCamera.CameraDirection == null) { return; } var zoom = v.PerspectiveCamera.FieldOfView; double z1 = 18 / Math.Tan(zoom / 2 * Math.PI / 180); //focale 1 double z = 18 / Math.Tan(25 / 2 * Math.PI / 180); //focale, da controllare il 18, vedi PDF double factor = z1 - z; var CameraDirection = Utils.GetXYZ(v.PerspectiveCamera.CameraDirection.X, v.PerspectiveCamera.CameraDirection.Y, v.PerspectiveCamera.CameraDirection.Z); var CameraUpVector = Utils.GetXYZ(v.PerspectiveCamera.CameraUpVector.X, v.PerspectiveCamera.CameraUpVector.Y, v.PerspectiveCamera.CameraUpVector.Z); XYZ oldO = Utils.GetXYZ(v.PerspectiveCamera.CameraViewPoint.X, v.PerspectiveCamera.CameraViewPoint.Y, v.PerspectiveCamera.CameraViewPoint.Z); var CameraViewPoint = (oldO.Subtract(CameraDirection.Divide(factor))); var orient3d = Utils.ConvertBasePoint(doc, CameraViewPoint, CameraDirection, CameraUpVector, true); View3D perspView = null; IEnumerable <View3D> viewcollector3D = get3DViews(doc); if (viewcollector3D.Any() && viewcollector3D.Where(o => o.Name == "BCFpersp").Any()) { perspView = viewcollector3D.Where(o => o.Name == "BCFpersp").First(); } using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Open perspective view") == TransactionStatus.Started) { if (null == perspView) { perspView = View3D.CreatePerspective(doc, getFamilyViews(doc).First().Id); perspView.Name = "BCFpersp"; } perspView.SetOrientation(orient3d); // turn off the far clip plane with standard parameter API if (perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR).HasValue) { Parameter m_farClip = perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR); m_farClip.Set(0); } perspView.CropBoxActive = true; perspView.CropBoxVisible = true; trans.Commit(); } } uidoc.ActiveView = perspView; } else if (v.SheetCamera != null)//sheet { //using (Transaction trans = new Transaction(uidoc.Document)) //{ // if (trans.Start("Open sheet view") == TransactionStatus.Started) // { IEnumerable <View> viewcollectorSheet = getSheets(doc, v.SheetCamera.SheetID); if (!viewcollectorSheet.Any()) { MessageBox.Show("No Sheet with Id=" + v.SheetCamera.SheetID + " found."); return; } uidoc.ActiveView = viewcollectorSheet.First(); uidoc.RefreshActiveView(); // trans.Commit(); // } //} XYZ m_xyzTl = new XYZ(v.SheetCamera.TopLeft.X, v.SheetCamera.TopLeft.Y, v.SheetCamera.TopLeft.Z); XYZ m_xyzBr = new XYZ(v.SheetCamera.BottomRight.X, v.SheetCamera.BottomRight.Y, v.SheetCamera.BottomRight.Z); uidoc.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr); } else { return; } //select/hide elements if (v.Components != null && v.Components.Any()) { FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType(); System.Collections.Generic.ICollection <ElementId> collection = collector.ToElementIds(); foreach (var e in v.Components) { var bcfguid = IfcGuid.FromIfcGUID(e.IfcGuid); var ids = collection.Where(o => bcfguid == ExportUtils.GetExportId(doc, o)); if (ids.Any()) { m_elementsToHide.Add(doc.GetElement(ids.First())); elementids.Add(ids.First()); } } if (null != m_elementsToHide && !m_elementsToHide.IsEmpty) { //do transaction only if there is something to hide/select using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Apply visibility/selection") == TransactionStatus.Started) { if (MySettings.Get("selattachedelems") == "0") { uidoc.ActiveView.IsolateElementsTemporary(elementids); } else { uidoc.Selection.Elements = m_elementsToHide; } } trans.Commit(); } } } uidoc.RefreshActiveView(); } catch (Exception ex) { TaskDialog.Show("Error!", "exception: " + ex); } }
public void Combine_EmptyStrings_ResultEmpty() { var result = ExportUtils.Combine("", "", ""); Assert.AreEqual("", result); }
private void HTMLBorder(FastString BorderDesc, Border border) { if (!layers) { BorderDesc.Append("border-collapse: separate;"); } if (border.Lines > 0) { // bottom if ((border.Lines & BorderLines.Bottom) > 0) { BorderDesc.Append("border-bottom-width:"). Append(HTMLBorderWidthPx(border.BottomLine)). Append("border-bottom-color:"). Append(ExportUtils.HTMLColor(border.BottomLine.Color)).Append(";border-bottom-style:"). Append(HTMLBorderStyle(border.BottomLine)).Append(";"); } else { BorderDesc.Append("border-bottom:none;"); } // top if ((border.Lines & BorderLines.Top) > 0) { BorderDesc.Append("border-top-width:"). Append(HTMLBorderWidthPx(border.TopLine)). Append("border-top-color:"). Append(ExportUtils.HTMLColor(border.TopLine.Color)).Append(";border-top-style:"). Append(HTMLBorderStyle(border.TopLine)).Append(";"); } else { BorderDesc.Append("border-top:none;"); } // left if ((border.Lines & BorderLines.Left) > 0) { BorderDesc.Append("border-left-width:"). Append(HTMLBorderWidthPx(border.LeftLine)). Append("border-left-color:"). Append(ExportUtils.HTMLColor(border.LeftLine.Color)).Append(";border-left-style:"). Append(HTMLBorderStyle(border.LeftLine)).Append(";"); } else { BorderDesc.Append("border-left:none;"); } // right if ((border.Lines & BorderLines.Right) > 0) { BorderDesc.Append("border-right-width:"). Append(HTMLBorderWidthPx(border.RightLine)). Append("border-right-color:"). Append(ExportUtils.HTMLColor(border.RightLine.Color)).Append(";border-right-style:"). Append(HTMLBorderStyle(border.RightLine)).Append(";"); } else { BorderDesc.Append("border-right:none;"); } } else { BorderDesc.Append("border:none;"); } }
static private string CreateSimpleGUID(Element element) { Guid guid = ExportUtils.GetExportId(element.Document, element.Id); return(ConvertToIFCGuid(guid)); }
public void ExportAnimation(AnimationClip clipAnimation, PrefabContext prefabContext) { if (!_engine.Options.ExportAnimations) { return; } var name = GetSafeFileName(_engine.DecorateName(clipAnimation.name)); //_assetCollection.AddAnimationPath(clipAnimation, fileName); var aniFilePath = EvaluateAnimationName(clipAnimation, prefabContext); using (var file = _engine.TryCreate(clipAnimation.GetKey(), aniFilePath, ExportUtils.GetLastWriteTimeUtc(clipAnimation))) { if (file == null) { return; } using (var writer = new BinaryWriter(file)) { writer.Write(new byte[] { 0x55, 0x41, 0x4e, 0x49 }); WriteStringSZ(writer, _engine.DecorateName(clipAnimation.name)); writer.Write(clipAnimation.length); if (clipAnimation.legacy) { WriteTracksAsIs(clipAnimation, writer); } else { var allBindings = AnimationUtility.GetCurveBindings(clipAnimation); var rootBones = new HashSet <string>(allBindings.Select(_ => GetRootBoneName(_)).Where(_ => _ != null)); if (rootBones.Count != 1) { Debug.LogWarning(aniFilePath + ": Multiple root bones found (" + string.Join(", ", rootBones.ToArray()) + "), falling back to curve export"); WriteTracksAsIs(clipAnimation, writer); } else { var rootBoneName = rootBones.First(); var rootGOs = _skeletons .Select(_ => _.name == rootBoneName ? _.transform : _.transform.Find(rootBoneName)) .Where(_ => _ != null).ToList(); if (rootGOs.Count == 1) { WriteSkelAnimation(clipAnimation, rootGOs.First().gameObject, writer); } else { Debug.LogWarning(aniFilePath + ": Multiple game objects found that match root bone name, falling back to curve export"); WriteTracksAsIs(clipAnimation, writer); } } } } } }
static void AddConnection(ExporterIFC exporterIFC, Connector connector, Connector connected, bool isBiDirectional, bool isElectricalDomain) { // Port connection is changed in IFC4 to use IfcRelNests for static connection. IfcRelConnectsPortToElement is used for a dynamic connection and it is restricted to IfcDistributionElement bool isIFC4AndAbove = !ExporterCacheManager.ExportOptionsCache.ExportAsOlderThanIFC4; Element inElement = connector.Owner; Element outElement = connected.Owner; if (isElectricalDomain) { // We may get a connection back to the original element. Ignore it. if (inElement.Id == outElement.Id) { return; } // Check the outElement to see if it is a Wire; if so, get its connections and "skip" the wire. if (outElement is Wire) { if (m_ProcessedWires.Contains(outElement.Id)) { return; } m_ProcessedWires.Add(outElement.Id); ExporterCacheManager.SystemsCache.AddElectricalSystem((outElement as Wire).MEPSystem.Id); try { ConnectorSet wireConnectorSet = MEPCache.GetConnectorsForWire(outElement as Wire); if (wireConnectorSet != null) { foreach (Connector connectedToWire in wireConnectorSet) { ProcessConnections(exporterIFC, connectedToWire, connector); } } } catch { } return; } } // Check if the connection already exist if (ConnectionExists(inElement.Id, outElement.Id)) { return; } if (isBiDirectional) { if (ConnectionExists(outElement.Id, inElement.Id)) { return; } } IFCAnyHandle inElementIFCHandle = ExporterCacheManager.MEPCache.Find(inElement.Id); IFCAnyHandle outElementIFCHandle = ExporterCacheManager.MEPCache.Find(outElement.Id); // Note: In IFC4 the IfcRelConnectsPortToElement should be used for a dynamic connection. The static connection should use IfcRelNests if (ExporterCacheManager.ExportOptionsCache.ExportAs4) { if (inElementIFCHandle == null || outElementIFCHandle == null || !IFCAnyHandleUtil.IsSubTypeOf(inElementIFCHandle, IFCEntityType.IfcObjectDefinition) || !IFCAnyHandleUtil.IsSubTypeOf(outElementIFCHandle, IFCEntityType.IfcObjectDefinition)) { return; } } else { if (inElementIFCHandle == null || outElementIFCHandle == null || !IFCAnyHandleUtil.IsSubTypeOf(inElementIFCHandle, IFCEntityType.IfcElement) || !IFCAnyHandleUtil.IsSubTypeOf(outElementIFCHandle, IFCEntityType.IfcElement)) { return; } } IFCFile ifcFile = exporterIFC.GetFile(); IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle; IFCAnyHandle portOut = null; IFCAnyHandle portIn = null; // Note: the GUIDs below are stable under the assumption that there is only one distribution // port from element A to element B. Also, note that we don't need the "real" GUIDs for these // elements, just stable ones. string inGuid = ExportUtils.GetExportId(inElement.Document, inElement.Id).ToString(); string outGuid = ExportUtils.GetExportId(outElement.Document, outElement.Id).ToString(); string portInGuid = null; string portOutGuid = null; // ----------------------- In Port ---------------------- { portInGuid = GUIDUtil.GenerateIFCGuidFrom("InPort" + connector.Id, inElement, outElement); IFCFlowDirection flowDir = (isBiDirectional) ? IFCFlowDirection.SourceAndSink : IFCFlowDirection.Sink; IFCAnyHandle localPlacement = CreateLocalPlacementForConnector(exporterIFC, connector, inElementIFCHandle, flowDir); portIn = IFCInstanceExporter.CreateDistributionPort(exporterIFC, null, portInGuid, ownerHistory, localPlacement, null, flowDir); string portType = "Flow"; // Assigned as Port.Description ExporterCacheManager.MEPCache.CacheConnectorHandle(connector, portIn); SetDistributionPortAttributes(portIn, connector, portType, inElement.Id, ref flowDir); // Attach the port to the element string guid = GUIDUtil.GenerateIFCGuidFrom("InPortRelConnects" + connector.Id, inElement, outElement); string connectionName = inElement.Id + "|" + guid; // Port connection is changed in IFC4 to use IfcRelNests for static connection. IfcRelConnectsPortToElement is used for a dynamic connection and it is restricted to IfcDistributionElement // The following code collects the ports that are nested to the object to be assigned later if (isIFC4AndAbove) { AddNestedMembership(inElementIFCHandle, portIn); } else { IFCInstanceExporter.CreateRelConnectsPortToElement(ifcFile, guid, ownerHistory, connectionName, portType, portIn, inElementIFCHandle); } } // ----------------------- Out Port---------------------- { portOutGuid = GUIDUtil.GenerateIFCGuidFrom("OutPort" + connector.Id, outElement, inElement); IFCFlowDirection flowDir = (isBiDirectional) ? IFCFlowDirection.SourceAndSink : IFCFlowDirection.Source; IFCAnyHandle localPlacement = CreateLocalPlacementForConnector(exporterIFC, connected, outElementIFCHandle, flowDir); portOut = IFCInstanceExporter.CreateDistributionPort(exporterIFC, null, portOutGuid, ownerHistory, localPlacement, null, flowDir); string portType = "Flow"; // Assigned as Port.Description ExporterCacheManager.MEPCache.CacheConnectorHandle(connected, portOut); SetDistributionPortAttributes(portOut, connected, portType, outElement.Id, ref flowDir); // Attach the port to the element string guid = GUIDUtil.GenerateIFCGuidFrom("OutPortRelConnects" + connector.Id.ToString(), outElement, inElement); string connectionName = outElement.Id + "|" + guid; // Port connection is changed in IFC4 to use IfcRelNests for static connection. IfcRelConnectsPortToElement is used for a dynamic connection and it is restricted to IfcDistributionElement // The following code collects the ports that are nested to the object to be assigned later if (isIFC4AndAbove) { AddNestedMembership(outElementIFCHandle, portOut); } else { IFCInstanceExporter.CreateRelConnectsPortToElement(ifcFile, guid, ownerHistory, connectionName, portType, portOut, outElementIFCHandle); } } // ----------------------- Out Port -> In Port ---------------------- if (portOut != null && portIn != null) { IFCAnyHandle realizingElement = null; string connectionName = portInGuid + "|" + portOutGuid; string connectionType = "Flow"; // Assigned as Description string guid = GUIDUtil.GenerateIFCGuidFrom(IFCEntityType.IfcRelConnectsPorts, portIn, portOut); IFCInstanceExporter.CreateRelConnectsPorts(ifcFile, guid, ownerHistory, connectionName, connectionType, portIn, portOut, realizingElement); AddConnectionInternal(inElement.Id, outElement.Id); } // Add the handles to the connector system. HashSet <MEPSystem> systemList = new HashSet <MEPSystem>(); try { MEPSystem system = connector.MEPSystem; if (system != null) { systemList.Add(system); } } catch { } if (isElectricalDomain) { foreach (MEPSystem system in systemList) { ExporterCacheManager.SystemsCache.AddElectricalSystem(system.Id); ExporterCacheManager.SystemsCache.AddHandleToElectricalSystem(system.Id, inElementIFCHandle); ExporterCacheManager.SystemsCache.AddHandleToElectricalSystem(system.Id, outElementIFCHandle); ExporterCacheManager.SystemsCache.AddHandleToElectricalSystem(system.Id, portIn); ExporterCacheManager.SystemsCache.AddHandleToElectricalSystem(system.Id, portOut); } } else { foreach (MEPSystem system in systemList) { ExporterCacheManager.SystemsCache.AddHandleToBuiltInSystem(system, inElementIFCHandle); ExporterCacheManager.SystemsCache.AddHandleToBuiltInSystem(system, outElementIFCHandle); ExporterCacheManager.SystemsCache.AddHandleToBuiltInSystem(system, portIn); ExporterCacheManager.SystemsCache.AddHandleToBuiltInSystem(system, portOut); } } }
public string EvaluateWeightsMap(TerrainData terrainData) { return(ExportUtils.ReplaceExtension(ExportUtils.GetRelPathFromAsset(_engine.Options.Subfolder, terrainData), ".Weights.tga")); }
private FastString GetSpanText(TextObjectBase obj, FastString text, float top, float width, float ParagraphOffset) { FastString style = new FastString(); style.Append("display:block;border:0;width:").Append(Px(width * Zoom)); if (ParagraphOffset != 0) { style.Append("text-indent:").Append(Px(ParagraphOffset * Zoom)); } if (obj.Padding.Left != 0) { style.Append("padding-left:").Append(Px((obj.Padding.Left) * Zoom)); } if (obj.Padding.Right != 0) { style.Append("padding-right:").Append(Px(obj.Padding.Right * Zoom)); } if (top != 0) { style.Append("margin-top:").Append(Px(top * Zoom)); } // we need to apply border width in order to position our div perfectly float borderLeft = 0; float borderRight = 0; float borderTop = 0; float borderBottom = 0; if (HTMLBorderWidthValues(obj, out borderLeft, out borderTop, out borderRight, out borderBottom)) { style.Append("position:absolute;") .Append("left:").Append(Px(-1 * borderLeft / 2f)) .Append("top:").Append(Px(-1 * borderTop / 2f)); } string href = String.Empty; if (!String.IsNullOrEmpty(obj.Hyperlink.Value)) { string hrefStyle = String.Empty; if (obj is TextObject) { TextObject textObject = obj as TextObject; hrefStyle = String.Format("style=\"color:{0}{1}\"", ExportUtils.HTMLColor(textObject.TextColor), !textObject.Font.Underline ? ";text-decoration:none" : String.Empty ); } string url = EncodeURL(obj.Hyperlink.Value); if (obj.Hyperlink.Kind == HyperlinkKind.URL) { href = String.Format("<a {0} href=\"{1}\"" + (obj.Hyperlink.OpenLinkInNewTab ? "target=\"_blank\"" : "") + ">", hrefStyle, obj.Hyperlink.Value); } else if (obj.Hyperlink.Kind == HyperlinkKind.DetailReport) { url = String.Format("{0},{1},{2}", EncodeURL(obj.Name), // object name for security reasons EncodeURL(obj.Hyperlink.ReportParameter), EncodeURL(obj.Hyperlink.Value)); string onClick = String.Format(OnClickTemplate, ReportID, "detailed_report", url); href = String.Format("<a {0} href=\"#\" onclick=\"{1}\">", hrefStyle, onClick); } else if (obj.Hyperlink.Kind == HyperlinkKind.DetailPage) { url = String.Format("{0},{1},{2}", EncodeURL(obj.Name), EncodeURL(obj.Hyperlink.ReportParameter), EncodeURL(obj.Hyperlink.Value)); string onClick = String.Format(OnClickTemplate, ReportID, "detailed_page", url); href = String.Format("<a {0} href=\"#\" onclick=\"{1}\">", hrefStyle, onClick); } else if (SinglePage) { if (obj.Hyperlink.Kind == HyperlinkKind.Bookmark) { href = String.Format("<a {0} href=\"#{1}\">", hrefStyle, url); } else if (obj.Hyperlink.Kind == HyperlinkKind.PageNumber) { href = String.Format("<a {0} href=\"#PageN{1}\">", hrefStyle, url); } } else { string onClick = String.Empty; if (obj.Hyperlink.Kind == HyperlinkKind.Bookmark) { onClick = String.Format(OnClickTemplate, ReportID, "bookmark", url); } else if (obj.Hyperlink.Kind == HyperlinkKind.PageNumber) { onClick = String.Format(OnClickTemplate, ReportID, "goto", url); } if (onClick != String.Empty) { href = String.Format("<a {0} href=\"#\" onclick=\"{1}\">", hrefStyle, onClick); } } } FastString result = new FastString(128); result.Append("<div "). Append(GetStyleTag(UpdateCSSTable(style.ToString()))).Append(">"). Append(href).Append(text).Append(href != String.Empty ? "</a>" : String.Empty). Append("</div>"); return(result); }
/// <summary> /// External Event Implementation /// </summary> /// <param name="app"></param> public void Execute(UIApplication app) { try { UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; var uniqueView = UserSettings.GetBool("alwaysNewView"); // IS ORTHOGONAL if (v.OrthogonalCamera != null) { if (v.OrthogonalCamera.CameraViewPoint == null || v.OrthogonalCamera.CameraUpVector == null || v.OrthogonalCamera.CameraDirection == null) { return; } //type = "OrthogonalCamera"; var zoom = v.OrthogonalCamera.ViewToWorldScale.ToFeet(); var cameraDirection = RevitUtils.GetRevitXYZ(v.OrthogonalCamera.CameraDirection); var cameraUpVector = RevitUtils.GetRevitXYZ(v.OrthogonalCamera.CameraUpVector); var cameraViewPoint = RevitUtils.GetRevitXYZ(v.OrthogonalCamera.CameraViewPoint); var orient3D = RevitUtils.ConvertBasePoint(doc, cameraViewPoint, cameraDirection, cameraUpVector, true); View3D orthoView = null; //if active view is 3d ortho use it if (doc.ActiveView.ViewType == ViewType.ThreeD) { var activeView3D = doc.ActiveView as View3D; if (!activeView3D.IsPerspective) { orthoView = activeView3D; } } if (orthoView == null) { //try to use an existing 3D view IEnumerable <View3D> viewcollector3D = get3DViews(doc); if (viewcollector3D.Any(o => o.Name == "{3D}" || o.Name == "BCFortho")) { orthoView = viewcollector3D.First(o => o.Name == "{3D}" || o.Name == "BCFortho"); } } using (var trans = new Transaction(uidoc.Document)) { if (trans.Start("Open orthogonal view") == TransactionStatus.Started) { //create a new 3d ortho view if (orthoView == null || uniqueView) { orthoView = View3D.CreateIsometric(doc, getFamilyViews(doc).First().Id); orthoView.Name = (uniqueView) ? "BCFortho" + DateTime.Now.ToString("yyyyMMddTHHmmss") : "BCFortho"; } else { //reusing an existing view, I net to reset the visibility //placed this here because if set afterwards it doesn't work orthoView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate); } orthoView.SetOrientation(orient3D); trans.Commit(); } } uidoc.ActiveView = orthoView; //adjust view rectangle // **** CUSTOM VALUE FOR TEKLA **** // // double x = zoom / 2.5; // **** CUSTOM VALUE FOR TEKLA **** // double x = zoom; //if(MySettings.Get("optTekla")=="1") // x = zoom / 2.5; //set UI view position and zoom XYZ m_xyzTl = uidoc.ActiveView.Origin.Add(uidoc.ActiveView.UpDirection.Multiply(x)).Subtract(uidoc.ActiveView.RightDirection.Multiply(x)); XYZ m_xyzBr = uidoc.ActiveView.Origin.Subtract(uidoc.ActiveView.UpDirection.Multiply(x)).Add(uidoc.ActiveView.RightDirection.Multiply(x)); uidoc.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr); } //perspective else if (v.PerspectiveCamera != null) { if (v.PerspectiveCamera.CameraViewPoint == null || v.PerspectiveCamera.CameraUpVector == null || v.PerspectiveCamera.CameraDirection == null) { return; } //not used since the fov cannot be changed in Revit var zoom = v.PerspectiveCamera.FieldOfView; //FOV - not used //double z1 = 18 / Math.Tan(zoom / 2 * Math.PI / 180); //double z = 18 / Math.Tan(25 / 2 * Math.PI / 180); //double factor = z1 - z; var cameraDirection = RevitUtils.GetRevitXYZ(v.PerspectiveCamera.CameraDirection); var cameraUpVector = RevitUtils.GetRevitXYZ(v.PerspectiveCamera.CameraUpVector); var cameraViewPoint = RevitUtils.GetRevitXYZ(v.PerspectiveCamera.CameraViewPoint); var orient3D = RevitUtils.ConvertBasePoint(doc, cameraViewPoint, cameraDirection, cameraUpVector, true); View3D perspView = null; //try to use an existing 3D view IEnumerable <View3D> viewcollector3D = get3DViews(doc); if (viewcollector3D.Any(o => o.Name == "BCFpersp")) { perspView = viewcollector3D.First(o => o.Name == "BCFpersp"); } using (var trans = new Transaction(uidoc.Document)) { if (trans.Start("Open perspective view") == TransactionStatus.Started) { if (null == perspView || uniqueView) { perspView = View3D.CreatePerspective(doc, getFamilyViews(doc).First().Id); perspView.Name = (uniqueView) ? "BCFpersp" + DateTime.Now.ToString("yyyyMMddTHHmmss") : "BCFpersp"; } else { //reusing an existing view, I net to reset the visibility //placed this here because if set afterwards it doesn't work perspView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate); } perspView.SetOrientation(orient3D); // turn off the far clip plane if (perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR).HasValue) { Parameter m_farClip = perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR); m_farClip.Set(0); } perspView.CropBoxActive = true; perspView.CropBoxVisible = true; trans.Commit(); } } uidoc.ActiveView = perspView; } //sheet else if (v.SheetCamera != null) { IEnumerable <View> viewcollectorSheet = getSheets(doc, v.SheetCamera.SheetID); if (!viewcollectorSheet.Any()) { MessageBox.Show("View " + v.SheetCamera.SheetName + " with Id=" + v.SheetCamera.SheetID + " not found."); return; } uidoc.ActiveView = viewcollectorSheet.First(); uidoc.RefreshActiveView(); XYZ m_xyzTl = new XYZ(v.SheetCamera.TopLeft.X, v.SheetCamera.TopLeft.Y, v.SheetCamera.TopLeft.Z); XYZ m_xyzBr = new XYZ(v.SheetCamera.BottomRight.X, v.SheetCamera.BottomRight.Y, v.SheetCamera.BottomRight.Z); uidoc.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr); } //no view included else { return; } if (v.Components == null) { return; } var elementsToSelect = new List <ElementId>(); var elementsToHide = new List <ElementId>(); var elementsToShow = new List <ElementId>(); var visibleElems = new FilteredElementCollector(doc, doc.ActiveView.Id) .WhereElementIsNotElementType() .WhereElementIsViewIndependent() .ToElementIds() .Where(e => doc.GetElement(e).CanBeHidden(doc.ActiveView)); //might affect performance, but it's necessary bool canSetVisibility = (v.Components.Visibility != null && v.Components.Visibility.DefaultVisibilitySpecified && v.Components.Visibility.Exceptions.Any()) ; bool canSetSelection = (v.Components.Selection != null && v.Components.Selection.Any()); //loop elements foreach (var e in visibleElems) { var guid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, e)); if (canSetVisibility) { if (v.Components.Visibility.DefaultVisibility) { if (v.Components.Visibility.Exceptions.Any(x => x.IfcGuid == guid)) { elementsToHide.Add(e); } } else { if (v.Components.Visibility.Exceptions.Any(x => x.IfcGuid == guid)) { elementsToShow.Add(e); } } } if (canSetSelection) { if (v.Components.Selection.Any(x => x.IfcGuid == guid)) { elementsToSelect.Add(e); } } } using (var trans = new Transaction(uidoc.Document)) { if (trans.Start("Apply BCF visibility and selection") == TransactionStatus.Started) { if (elementsToHide.Any()) { doc.ActiveView.HideElementsTemporary(elementsToHide); } //there are no items to hide, therefore hide everything and just show the visible ones else if (elementsToShow.Any()) { doc.ActiveView.IsolateElementsTemporary(elementsToShow); } if (elementsToSelect.Any()) { uidoc.Selection.SetElementIds(elementsToSelect); } } trans.Commit(); } uidoc.RefreshActiveView(); } catch (Exception ex) { TaskDialog.Show("Error!", "exception: " + ex); } }
private void LayerText(FastString Page, TextObject obj) { float top = 0; switch (obj.TextRenderType) { case TextRenderType.HtmlParagraph: HtmlTextRenderer htmlTextRenderer = obj.GetHtmlTextRenderer(Zoom, Zoom); if (obj.VertAlign == VertAlign.Center) { top = (obj.Height - htmlTextRenderer.CalcHeight()) / 2; } else if (obj.VertAlign == VertAlign.Bottom) { top = obj.Height - htmlTextRenderer.CalcHeight(); } FastString sb = GetHtmlParagraph(htmlTextRenderer); LayerBack(Page, obj, GetSpanText(obj, sb, top + obj.Padding.Top, obj.Width - obj.Padding.Horizontal, obj.ParagraphOffset)); break; default: if (obj.VertAlign != VertAlign.Top) { Graphics g = htmlMeasureGraphics; using (Font f = new Font(obj.Font.Name, obj.Font.Size, obj.Font.Style)) { RectangleF textRect = new RectangleF(obj.AbsLeft, obj.AbsTop, obj.Width, obj.Height); StringFormat format = obj.GetStringFormat(Report.GraphicCache, 0); Brush textBrush = Report.GraphicCache.GetBrush(obj.TextColor); AdvancedTextRenderer renderer = new AdvancedTextRenderer(obj.Text, g, f, textBrush, null, textRect, format, obj.HorzAlign, obj.VertAlign, obj.LineHeight, obj.Angle, obj.FontWidthRatio, obj.ForceJustify, obj.Wysiwyg, obj.HasHtmlTags, false, Zoom, Zoom, obj.InlineImageCache); if (renderer.Paragraphs.Count > 0) { if (renderer.Paragraphs[0].Lines.Count > 0) { float height = renderer.Paragraphs[0].Lines[0].CalcHeight(); if (height > obj.Height) { top = -(height - obj.Height) / 2; } else { top = renderer.Paragraphs[0].Lines[0].Top - obj.AbsTop; } } } } } LayerBack(Page, obj, GetSpanText(obj, ExportUtils.HtmlString(obj.Text, obj.TextRenderType), top + obj.Padding.Top, obj.Width - obj.Padding.Horizontal, obj.ParagraphOffset)); break; } }
public void ExportScene(Scene scene) { var exlusion = new HashSet <Renderer>(); var sceneAssetName = ResolveAssetPath(scene); var prefabContext = new PrefabContext() { TempFolder = ExportUtils.ReplaceExtension(sceneAssetName, "") }; using (var writer = _engine.TryCreateXml(AssetKey.Empty, sceneAssetName, DateTime.MaxValue)) { if (writer == null) { return; } var rootGameObjects = scene.GetRootGameObjects(); if (_engine.Options.ExportSceneAsPrefab) { if (rootGameObjects.Length > 1) { StartNode(writer, ""); foreach (var gameObject in rootGameObjects) { WriteObject(writer, "\t", gameObject, exlusion, true, prefabContext); } writer.WriteEndElement(); writer.WriteWhitespace("\n"); } else { foreach (var gameObject in rootGameObjects) { WriteObject(writer, "", gameObject, exlusion, true, prefabContext); } } } else { using (var sceneElement = Element.Start(writer, "scene")) { WriteAttribute(writer, "\t", "Name", _engine.DecorateName(scene.name)); StartComponent(writer, "\t", "Octree", true); EndElement(writer, "\t"); StartComponent(writer, "\t", "DebugRenderer", true); EndElement(writer, "\t"); var skybox = scene.GetRootGameObjects().Select(_ => _.GetComponentInChildren <Skybox>(true)) .Where(_ => _ != null).FirstOrDefault(); var skyboxMaterial = skybox?.material ?? RenderSettings.skybox; if (skybox == null) { WriteSkyboxComponent(writer, "\t", RenderSettings.skybox, prefabContext, true); } if (skyboxMaterial != null) { var skyboxCubemap = _engine.TryGetSkyboxCubemap(skyboxMaterial); if (!string.IsNullOrWhiteSpace(skyboxCubemap)) { ExportZone(writer, "\t", new Vector3(2000, 2000, 2000), skyboxCubemap, prefabContext, true); } } foreach (var gameObject in rootGameObjects) { WriteObject(writer, "", gameObject, exlusion, true, prefabContext); } } } } _engine.ExportNavMesh(prefabContext); }
private string GetLayerPicture(ReportComponentBase obj, out float Width, out float Height) { string result = String.Empty; Width = 0; Height = 0; if (obj != null) { if (pictures) { MemoryStream PictureStream = new MemoryStream(); System.Drawing.Imaging.ImageFormat FPictureFormat = System.Drawing.Imaging.ImageFormat.Bmp; if (imageFormat == ImageFormat.Png) { FPictureFormat = System.Drawing.Imaging.ImageFormat.Png; } else if (imageFormat == ImageFormat.Jpeg) { FPictureFormat = System.Drawing.Imaging.ImageFormat.Jpeg; } else if (imageFormat == ImageFormat.Gif) { FPictureFormat = System.Drawing.Imaging.ImageFormat.Gif; } Width = obj.Width == 0 ? obj.Border.LeftLine.Width : obj.Width; Height = obj.Height == 0 ? obj.Border.TopLine.Width : obj.Height; if (Math.Abs(Width) * Zoom < 1 && Zoom > 0) { Width = 1 / Zoom; } if (Math.Abs(Height) * Zoom < 1 && Zoom > 0) { Height = 1 / Zoom; } using (System.Drawing.Image image = new Bitmap( (int)(Math.Abs(Math.Round(Width * Zoom))), (int)(Math.Abs(Math.Round(Height * Zoom))) ) ) { using (Graphics g = Graphics.FromImage(image)) { if (obj is TextObjectBase) { g.Clear(Color.White); } float Left = Width > 0 ? obj.AbsLeft : obj.AbsLeft + Width; float Top = Height > 0 ? obj.AbsTop : obj.AbsTop + Height; float dx = 0; float dy = 0; g.TranslateTransform((-Left - dx) * Zoom, (-Top - dy) * Zoom); BorderLines oldLines = obj.Border.Lines; obj.Border.Lines = BorderLines.None; obj.Draw(new FRPaintEventArgs(g, Zoom, Zoom, Report.GraphicCache)); obj.Border.Lines = oldLines; } if (FPictureFormat == System.Drawing.Imaging.ImageFormat.Jpeg) { ExportUtils.SaveJpeg(image, PictureStream, 95); } else { image.Save(PictureStream, FPictureFormat); } } PictureStream.Position = 0; result = HTMLGetImage(0, 0, 0, Crypter.ComputeHash(PictureStream), true, null, PictureStream, false); } } return(result); }
//<summary> //Generate a VisualizationInfo of the current view //</summary> //<returns></returns> public static VisualizationInfo GenerateViewpoint(UIDocument uidoc) { try { var doc = uidoc.Document; var v = new VisualizationInfo(); //Corners of the active UI view var topLeft = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0]; var bottomRight = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1]; //It's a 2D view //not supported by BCF, but I store it under a custom //fields using 2D coordinates and sheet id if (uidoc.ActiveView.ViewType != ViewType.ThreeD) { v.SheetCamera = new SheetCamera { SheetID = uidoc.ActiveView.Id.IntegerValue, TopLeft = new Point { X = topLeft.X, Y = topLeft.Y, Z = topLeft.Z }, BottomRight = new Point { X = bottomRight.X, Y = bottomRight.Y, Z = bottomRight.Z } }; } //It's a 3d view else { var viewCenter = new XYZ(); var view3D = (View3D)uidoc.ActiveView; double zoomValue = 1; // it is a orthogonal view if (!view3D.IsPerspective) { double x = (topLeft.X + bottomRight.X) / 2; double y = (topLeft.Y + bottomRight.Y) / 2; double z = (topLeft.Z + bottomRight.Z) / 2; //center of the UI view viewCenter = new XYZ(x, y, z); //vector going from BR to TL XYZ diagVector = topLeft.Subtract(bottomRight); //length of the vector double dist = topLeft.DistanceTo(bottomRight) / 2; //ViewToWorldScale value zoomValue = dist * Math.Sin(diagVector.AngleTo(view3D.RightDirection)).ToMeters(); // **** CUSTOM VALUE FOR TEKLA **** // // calculated experimentally, not sure why but it works //if (UserSettings.Get("optTekla") == "1") // zoomValue = zoomValue * 2.5; // **** CUSTOM VALUE FOR TEKLA **** // ViewOrientation3D t = RevitUtils.ConvertBasePoint(doc, viewCenter, uidoc.ActiveView.ViewDirection, uidoc.ActiveView.UpDirection, false); XYZ c = t.EyePosition; XYZ vi = t.ForwardDirection; XYZ up = t.UpDirection; v.OrthogonalCamera = new OrthogonalCamera { CameraViewPoint = { X = c.X.ToMeters(), Y = c.Y.ToMeters(), Z = c.Z.ToMeters() }, CameraUpVector = { X = up.X.ToMeters(), Y = up.Y.ToMeters(), Z = up.Z.ToMeters() }, CameraDirection = { X = vi.X.ToMeters() * -1, Y = vi.Y.ToMeters() * -1, Z = vi.Z.ToMeters() * -1 }, ViewToWorldScale = zoomValue }; } // it is a perspective view else { viewCenter = uidoc.ActiveView.Origin; //revit default value zoomValue = 45; ViewOrientation3D t = RevitUtils.ConvertBasePoint(doc, viewCenter, uidoc.ActiveView.ViewDirection, uidoc.ActiveView.UpDirection, false); XYZ c = t.EyePosition; XYZ vi = t.ForwardDirection; XYZ up = t.UpDirection; v.PerspectiveCamera = new PerspectiveCamera { CameraViewPoint = { X = c.X.ToMeters(), Y = c.Y.ToMeters(), Z = c.Z.ToMeters() }, CameraUpVector = { X = up.X.ToMeters(), Y = up.Y.ToMeters(), Z = up.Z.ToMeters() }, CameraDirection = { X = vi.X.ToMeters() * -1, Y = vi.Y.ToMeters() * -1, Z = vi.Z.ToMeters() * -1 }, FieldOfView = zoomValue }; } } //COMPONENTS PART string versionName = doc.Application.VersionName; v.Components = new List <Component>(); var visibleElems = new FilteredElementCollector(doc, doc.ActiveView.Id) .WhereElementIsNotElementType() .WhereElementIsViewIndependent() .ToElementIds(); var hiddenElems = new FilteredElementCollector(doc) .WhereElementIsNotElementType() .WhereElementIsViewIndependent() .Where(x => x.IsHidden(doc.ActiveView) || !doc.ActiveView.IsElementVisibleInTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate, x.Id)).ToList();//would need to check how much this is affecting performance var selectedElems = uidoc.Selection.GetElementIds(); //include only hidden elements and selected in the BCF if (visibleElems.Count() > hiddenElems.Count()) { foreach (var elem in hiddenElems) { v.Components.Add(new Component { OriginatingSystem = versionName, IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem.Id)), Visible = false, Selected = false, AuthoringToolId = elem.Id.IntegerValue.ToString() }); } foreach (var elem in selectedElems) { v.Components.Add(new Component { OriginatingSystem = versionName, IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem)), Visible = true, Selected = true, AuthoringToolId = elem.IntegerValue.ToString() }); } } //include only visible elements //all the others are hidden else { foreach (var elem in visibleElems) { v.Components.Add(new Component { OriginatingSystem = versionName, IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem)), Visible = true, Selected = selectedElems.Contains(elem), AuthoringToolId = elem.IntegerValue.ToString() }); } } return(v); } catch (System.Exception ex1) { TaskDialog.Show("Error generating viewpoint", "exception: " + ex1); } return(null); }
private void ExportHTMLPageLayeredBegin(HTMLData d) { if (!singlePage && !WebMode) { cssStyles.Clear(); } css = new FastString(); htmlPage = new FastString(); ReportPage reportPage = d.page; if (reportPage != null) { maxWidth = ExportUtils.GetPageWidth(reportPage) * Units.Millimeters; maxHeight = ExportUtils.GetPageHeight(reportPage) * Units.Millimeters; if (enableMargins) { leftMargin = reportPage.LeftMargin * Units.Millimeters; topMargin = reportPage.TopMargin * Units.Millimeters; } else { maxWidth -= (reportPage.LeftMargin + reportPage.RightMargin) * Units.Millimeters; maxHeight -= (reportPage.TopMargin + reportPage.BottomMargin) * Units.Millimeters; leftMargin = 0; topMargin = 0; } currentPage = d.PageNumber - 1; ExportHTMLPageStart(htmlPage, d.PageNumber, d.CurrentPage); doPageBreak = (singlePage && pageBreaks); htmlPage.Append(HTMLGetAncor((d.PageNumber).ToString())); htmlPage.Append("<div ").Append(doPageBreak ? "class=\"frpage\"" : String.Empty). Append(" style=\"position:relative;width:").Append(Px(maxWidth * Zoom + 3)). Append("height:").Append(Px(maxHeight * Zoom)); if (reportPage.Fill is SolidFill) { SolidFill fill = reportPage.Fill as SolidFill; htmlPage.Append("; background-color:"). Append(fill.Color.A == 0 ? "transparent" : ExportUtils.HTMLColor(fill.Color)); } htmlPage.Append("\">"); if (!(reportPage.Fill is SolidFill)) { // to-do for picture background } if (reportPage.Watermark.Enabled && !reportPage.Watermark.ShowImageOnTop) { Watermark(htmlPage, reportPage, false); } if (reportPage.Watermark.Enabled && !reportPage.Watermark.ShowTextOnTop) { Watermark(htmlPage, reportPage, true); } } }
private void export_button_Click(object sender, RoutedEventArgs e) { ExportUtils.exportToExcel(production_dg, page_header.Content.ToString().Trim(), "C"); }
private string HTMLGetImage(int PageNumber, int CurrentPage, int ImageNumber, string hash, bool Base, System.Drawing.Image Metafile, MemoryStream PictureStream, bool isSvg) { if (pictures) { System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Bmp; if (imageFormat == ImageFormat.Png) { format = System.Drawing.Imaging.ImageFormat.Png; } else if (imageFormat == ImageFormat.Jpeg) { format = System.Drawing.Imaging.ImageFormat.Jpeg; } else if (imageFormat == ImageFormat.Gif) { format = System.Drawing.Imaging.ImageFormat.Gif; } string formatNm = isSvg ? "svg" : format.ToString().ToLower(); string embedImgType = isSvg ? "svg+xml" : format.ToString(); string embedPreffix = "data:image/" + embedImgType + ";base64,"; FastString ImageFileNameBuilder = new FastString(48); string ImageFileName; if (!saveStreams) { ImageFileNameBuilder.Append(Path.GetFileName(targetFileName)).Append("."); } ImageFileNameBuilder.Append(hash). Append(".").Append(formatNm); ImageFileName = ImageFileNameBuilder.ToString(); if (!webMode && !(preview || print)) { if (Base) { if (Metafile != null && !EmbedPictures) { if (saveStreams) { MemoryStream ImageFileStream = new MemoryStream(); Metafile.Save(ImageFileStream, format); GeneratedUpdate(targetPath + ImageFileName, ImageFileStream); } else { using (FileStream ImageFileStream = new FileStream(targetPath + ImageFileName, FileMode.Create)) Metafile.Save(ImageFileStream, format); } } else if (PictureStream != null && !EmbedPictures) { if (this.format == HTMLExportFormat.HTML) { string fileName = targetPath + ImageFileName; FileInfo info = new FileInfo(fileName); if (!(info.Exists && info.Length == PictureStream.Length)) { if (saveStreams) { GeneratedUpdate(targetPath + ImageFileName, PictureStream); } else { using (FileStream ImageFileStream = new FileStream(fileName, FileMode.Create)) PictureStream.WriteTo(ImageFileStream); } } } else { PicsArchiveItem item; item.FileName = ImageFileName; item.Stream = PictureStream; bool founded = false; for (int i = 0; i < picsArchive.Count; i++) { if (item.FileName == picsArchive[i].FileName) { founded = true; break; } } if (!founded) { picsArchive.Add(item); } } } if (!saveStreams) { GeneratedFiles.Add(targetPath + ImageFileName); } } if (EmbedPictures && PictureStream != null) { return(embedPreffix + GetBase64Image(PictureStream, hash)); } else if (subFolder && singlePage && !navigator) { return(ExportUtils.HtmlURL(subFolderPath + ImageFileName)); } else { return(ExportUtils.HtmlURL(ImageFileName)); } } else { if (EmbedPictures) { return(embedPreffix + GetBase64Image(PictureStream, hash)); } else { if (print || preview) { printPageData.Pictures.Add(PictureStream); printPageData.Guids.Add(hash); } else if (Base) { pages[CurrentPage].Pictures.Add(PictureStream); pages[CurrentPage].Guids.Add(hash); } return(webImagePrefix + "=" + hash + webImageSuffix); } } } else { return(String.Empty); } }
private int GetTable(StringBuilder Page, ExportMatrix FMatrix, int PageNumber, int CurrentPage, int ImagesCount) { for (int y = 0; y < FMatrix.Height - 1; y++) { int drow = (int)Math.Round((FMatrix.YPosById(y + 1) - FMatrix.YPosById(y))); if (drow == 0) { drow = 1; } Page.Append("<tr style=\"height:").Append(SizeValue(drow, FMatrix.MaxHeight, FHeightUnits)).AppendLine("\">"); for (int x = 0; x < FMatrix.Width - 1; x++) { int i = FMatrix.Cell(x, y); if (i != -1) { ExportIEMObject obj = FMatrix.ObjectById(i); if (obj.Counter == 0) { int fx, fy, dx, dy; FMatrix.ObjectPos(i, out fx, out fy, out dx, out dy); obj.Counter = 1; Page.Append("<td"). Append((dx > 1 ? " colspan=\"" + dx.ToString() + "\"" : String.Empty)). Append((dy > 1 ? " rowspan=\"" + dy.ToString() + "\"" : String.Empty)). Append(" class=\"").Append(FStylePrefix).Append("s").Append(obj.StyleIndex.ToString()). Append("\""); StringBuilder style = new StringBuilder(256); if (obj.Text.Length == 0) { style.Append("font-size:1px;"); } if (obj.PictureStream != null && obj.IsText) { style.Append("background-image: url("). Append(HTMLGetImage(PageNumber, CurrentPage, ImagesCount++, obj.Hash, obj.Base, obj.Metafile, obj.PictureStream)). Append(");"); } if (style.Length > 0) { Page.Append(" style=\"").Append(style).Append("\""); } Page.Append(">"); // TEXT if (obj.IsText) { if (obj.Text.Length > 0) { if (!String.IsNullOrEmpty(obj.URL)) { Page.Append("<a href=\"" + obj.URL + "\">"); } Page.Append(ExportUtils.HtmlString(obj.Text, obj.HtmlTags)); if (!String.IsNullOrEmpty(obj.URL)) { Page.Append("</a>"); } } else { Page.Append(NBSP); } } else { Page.Append(HTMLSaveImage(obj, PageNumber, CurrentPage, ImagesCount++)); } Page.AppendLine("</td>"); } } else { Page.AppendLine("</td>"); } } Page.AppendLine("</tr>"); } return(ImagesCount); }
public void Combine_TwoStrings_ResultSeparated() { var result = ExportUtils.Combine("A", "B"); Assert.AreEqual("A/B", result); }