commit 2b56cf87a863f9317ca8a3522aeb57ad15fa6741 Author: ninja <914440382@qq.com> Date: Mon Dec 15 22:06:49 2025 +0800 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..853fb39 --- /dev/null +++ b/.gitignore @@ -0,0 +1,451 @@ +# ---> VisualStudio +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +# but not Directory.Build.rsp, as it configures directory-level build defaults +!Directory.Build.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + +# ---> VisualStudioCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +# ---> C++ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +data/ diff --git a/HOOPSExchangePublishSample.props b/HOOPSExchangePublishSample.props new file mode 100644 index 0000000..9fc9f8d --- /dev/null +++ b/HOOPSExchangePublishSample.props @@ -0,0 +1,42 @@ + + + + + $(ProjectDir)\$(Platform)\$(Configuration)\ + $(ProjectDir)\$(Platform)\$(Configuration)\ + + + + $(SolutionDir)..\include;%(AdditionalIncludeDirectories) + UNICODE;_UNICODE;%(PreprocessorDefinitions) + + + SAMPLES_DATA_DIRECTORY=R"(..\..\..\..\..\data)";%(PreprocessorDefinitions) + SAMPLES_DEFAULT_OUTPUT_PATH=R"(.\)";%(PreprocessorDefinitions) + SAMPLES_PUBLISH_GALLERY_DIRECTORY=R"(..\..\..\..\..\publish\publishgallery)";%(PreprocessorDefinitions) + SAMPLES_PUBLISH_QUICKSTARTS_DIRECTORY=R"(..\..\..\..\..\publish\publishquickstarts)";%(PreprocessorDefinitions) + SAMPLES_PUBLISH_HTML_DIRECTORY=R"(..\..\..\..\..\publish\publishhtml)";%(PreprocessorDefinitions) + SAMPLES_ADOBE_RESOURCE_DIRECTORY=R"(..\resource)";%(PreprocessorDefinitions) + + + + + HOOPS_BINARY_DIRECTORY=R"(..\..\..\..\..\..\bin\win32_v142)";%(PreprocessorDefinitions) + + + + + HOOPS_BINARY_DIRECTORY=R"(..\..\..\..\..\..\bin\win64_v142)";%(PreprocessorDefinitions) + + + + + HOOPS_BINARY_DIRECTORY=R"(..\..\..\..\..\..\bin\win32_v142)";%(PreprocessorDefinitions) + + + + + HOOPS_BINARY_DIRECTORY=R"(..\..\..\..\..\..\bin\win64_v142)";%(PreprocessorDefinitions) + + + \ No newline at end of file diff --git a/exchange.sln b/exchange.sln new file mode 100644 index 0000000..606f25f --- /dev/null +++ b/exchange.sln @@ -0,0 +1,303 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32901.82 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".Net Wrapper", ".Net Wrapper", "{3EDA093F-F647-4857-BDBD-0E2DEF0E9A5D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BrepAdaptor", "exchange\exchangesource\BrepAdaptor\BrepAdaptor.vcxproj", "{7CD4F74A-2286-4744-BF8C-C8B55E76730B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CascadedAttributes", "exchange\exchangesource\CascadedAttributes\CascadedAttributes.vcxproj", "{C7C85E0A-87B5-4E20-9F62-7C16802ABA00}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CreatePRCBrepWithGeometry", "exchange\exchangesource\CreatePRCBrepWithGeometry\CreatePRCBrepWithGeometry.vcxproj", "{B0AA5CD9-263E-45CE-AE76-C53AA7307249}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CreatePRCCubes", "exchange\exchangesource\CreatePRCCubes\CreatePRCCubes.vcxproj", "{BC7D4477-04C9-426D-93A1-3401DFD12A0F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IncrementalLoad", "exchange\exchangesource\IncrementalLoad\IncrementalLoad.vcxproj", "{6A9058C6-06BD-4213-8F50-BC7DF8305EC0}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LoadMultiConfigCADFile", "exchange\exchangesource\LoadMultiConfigCADFile\LoadMultiConfigCADFile.vcxproj", "{88467A66-9EF5-43F4-AD35-DB2C530E2374}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MultiplePRCFiles", "exchange\exchangesource\MultiplePRCFiles\MultiplePRCFiles.vcxproj", "{8B90DC19-E9AC-4D8C-A8E5-5190A986F9A0}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PRC2XML", "exchange\exchangesource\PRC2XML\PRC2XML.vcxproj", "{C3C57200-3B1F-465F-8631-E948A935D645}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Viewer", "exchange\exchangesource\Viewer\Viewer.vcxproj", "{D8B6598C-913F-4507-AE93-518F7C76EBDA}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TechSoft3D.Exchange.NetWrapper", "exchange\exchangesource\NetWrapper\TechSoft3D.Exchange.NetWrapper.vcxproj", "{2E7E13B4-0AC4-480F-901F-024CF1938308}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApplication", "exchange\exchangesource\NetWrapper\ConsoleApplication.csproj", "{765D5D20-2470-4597-93CD-25A7E118814D}" + ProjectSection(ProjectDependencies) = postProject + {2E7E13B4-0AC4-480F-901F-024CF1938308} = {2E7E13B4-0AC4-480F-901F-024CF1938308} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DrawingViewer", "exchange\exchangesource\DrawingViewer\DrawingViewer.vcxproj", "{0C9C33A6-D497-45A8-A74D-95E794C3AF78}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImportExport", "exchange\exchangesource\ImportExport\ImportExport.vcxproj", "{58B52422-7322-40C5-BFF7-8E575B7AB63C}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SewBrep", "exchange\exchangesource\SewBrep\SewBrep.vcxproj", "{8BCFAE5D-00F9-41A6-9A15-A1A5AE1EFAEA}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TranslateToPkParts", "exchange\exchangesource\TranslateToPkParts\TranslateToPkParts.vcxproj", "{D77B7B37-01D4-463A-B24F-4EDF3D5B979B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Shattered", "exchange\exchangesource\Shattered\Shattered.vcxproj", "{ACEC4E45-AA20-4C1F-94FB-034459E3ABC7}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2FD95A9C-266F-4920-BAE3-19165785561D}" + ProjectSection(SolutionItems) = preProject + exchange\exchangesource\common.hpp = exchange\exchangesource\common.hpp + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DumpFeatureTree", "exchange\exchangesource\DumpFeatureTree\DumpFeatureTree.vcxproj", "{693094D2-1470-4AB4-977E-8D82E5985618}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Collision", "exchange\exchangesource\Collision\Collision.vcxproj", "{EC2593D7-2AB1-4EFC-B412-9C5A70939DF9}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PRC2IFCXML", "exchange\exchangesource\PRC2IFCXML\PRC2IFCXML.vcxproj", "{236BB296-3A6D-4CBF-B8C2-4370790211F0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Mixed Platforms = Release|Mixed Platforms + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7CD4F74A-2286-4744-BF8C-C8B55E76730B}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {7CD4F74A-2286-4744-BF8C-C8B55E76730B}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {7CD4F74A-2286-4744-BF8C-C8B55E76730B}.Debug|Win32.ActiveCfg = Debug|Win32 + {7CD4F74A-2286-4744-BF8C-C8B55E76730B}.Debug|Win32.Build.0 = Debug|Win32 + {7CD4F74A-2286-4744-BF8C-C8B55E76730B}.Debug|x64.ActiveCfg = Debug|x64 + {7CD4F74A-2286-4744-BF8C-C8B55E76730B}.Debug|x64.Build.0 = Debug|x64 + {7CD4F74A-2286-4744-BF8C-C8B55E76730B}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {7CD4F74A-2286-4744-BF8C-C8B55E76730B}.Release|Mixed Platforms.Build.0 = Release|Win32 + {7CD4F74A-2286-4744-BF8C-C8B55E76730B}.Release|Win32.ActiveCfg = Release|Win32 + {7CD4F74A-2286-4744-BF8C-C8B55E76730B}.Release|Win32.Build.0 = Release|Win32 + {7CD4F74A-2286-4744-BF8C-C8B55E76730B}.Release|x64.ActiveCfg = Release|x64 + {7CD4F74A-2286-4744-BF8C-C8B55E76730B}.Release|x64.Build.0 = Release|x64 + {C7C85E0A-87B5-4E20-9F62-7C16802ABA00}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {C7C85E0A-87B5-4E20-9F62-7C16802ABA00}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {C7C85E0A-87B5-4E20-9F62-7C16802ABA00}.Debug|Win32.ActiveCfg = Debug|Win32 + {C7C85E0A-87B5-4E20-9F62-7C16802ABA00}.Debug|Win32.Build.0 = Debug|Win32 + {C7C85E0A-87B5-4E20-9F62-7C16802ABA00}.Debug|x64.ActiveCfg = Debug|x64 + {C7C85E0A-87B5-4E20-9F62-7C16802ABA00}.Debug|x64.Build.0 = Debug|x64 + {C7C85E0A-87B5-4E20-9F62-7C16802ABA00}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {C7C85E0A-87B5-4E20-9F62-7C16802ABA00}.Release|Mixed Platforms.Build.0 = Release|Win32 + {C7C85E0A-87B5-4E20-9F62-7C16802ABA00}.Release|Win32.ActiveCfg = Release|Win32 + {C7C85E0A-87B5-4E20-9F62-7C16802ABA00}.Release|Win32.Build.0 = Release|Win32 + {C7C85E0A-87B5-4E20-9F62-7C16802ABA00}.Release|x64.ActiveCfg = Release|x64 + {C7C85E0A-87B5-4E20-9F62-7C16802ABA00}.Release|x64.Build.0 = Release|x64 + {B0AA5CD9-263E-45CE-AE76-C53AA7307249}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {B0AA5CD9-263E-45CE-AE76-C53AA7307249}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {B0AA5CD9-263E-45CE-AE76-C53AA7307249}.Debug|Win32.ActiveCfg = Debug|Win32 + {B0AA5CD9-263E-45CE-AE76-C53AA7307249}.Debug|Win32.Build.0 = Debug|Win32 + {B0AA5CD9-263E-45CE-AE76-C53AA7307249}.Debug|x64.ActiveCfg = Debug|x64 + {B0AA5CD9-263E-45CE-AE76-C53AA7307249}.Debug|x64.Build.0 = Debug|x64 + {B0AA5CD9-263E-45CE-AE76-C53AA7307249}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {B0AA5CD9-263E-45CE-AE76-C53AA7307249}.Release|Mixed Platforms.Build.0 = Release|Win32 + {B0AA5CD9-263E-45CE-AE76-C53AA7307249}.Release|Win32.ActiveCfg = Release|Win32 + {B0AA5CD9-263E-45CE-AE76-C53AA7307249}.Release|Win32.Build.0 = Release|Win32 + {B0AA5CD9-263E-45CE-AE76-C53AA7307249}.Release|x64.ActiveCfg = Release|x64 + {B0AA5CD9-263E-45CE-AE76-C53AA7307249}.Release|x64.Build.0 = Release|x64 + {BC7D4477-04C9-426D-93A1-3401DFD12A0F}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {BC7D4477-04C9-426D-93A1-3401DFD12A0F}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {BC7D4477-04C9-426D-93A1-3401DFD12A0F}.Debug|Win32.ActiveCfg = Debug|Win32 + {BC7D4477-04C9-426D-93A1-3401DFD12A0F}.Debug|Win32.Build.0 = Debug|Win32 + {BC7D4477-04C9-426D-93A1-3401DFD12A0F}.Debug|x64.ActiveCfg = Debug|x64 + {BC7D4477-04C9-426D-93A1-3401DFD12A0F}.Debug|x64.Build.0 = Debug|x64 + {BC7D4477-04C9-426D-93A1-3401DFD12A0F}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {BC7D4477-04C9-426D-93A1-3401DFD12A0F}.Release|Mixed Platforms.Build.0 = Release|Win32 + {BC7D4477-04C9-426D-93A1-3401DFD12A0F}.Release|Win32.ActiveCfg = Release|Win32 + {BC7D4477-04C9-426D-93A1-3401DFD12A0F}.Release|Win32.Build.0 = Release|Win32 + {BC7D4477-04C9-426D-93A1-3401DFD12A0F}.Release|x64.ActiveCfg = Release|x64 + {BC7D4477-04C9-426D-93A1-3401DFD12A0F}.Release|x64.Build.0 = Release|x64 + {6A9058C6-06BD-4213-8F50-BC7DF8305EC0}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {6A9058C6-06BD-4213-8F50-BC7DF8305EC0}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {6A9058C6-06BD-4213-8F50-BC7DF8305EC0}.Debug|Win32.ActiveCfg = Debug|Win32 + {6A9058C6-06BD-4213-8F50-BC7DF8305EC0}.Debug|Win32.Build.0 = Debug|Win32 + {6A9058C6-06BD-4213-8F50-BC7DF8305EC0}.Debug|x64.ActiveCfg = Debug|x64 + {6A9058C6-06BD-4213-8F50-BC7DF8305EC0}.Debug|x64.Build.0 = Debug|x64 + {6A9058C6-06BD-4213-8F50-BC7DF8305EC0}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {6A9058C6-06BD-4213-8F50-BC7DF8305EC0}.Release|Mixed Platforms.Build.0 = Release|Win32 + {6A9058C6-06BD-4213-8F50-BC7DF8305EC0}.Release|Win32.ActiveCfg = Release|Win32 + {6A9058C6-06BD-4213-8F50-BC7DF8305EC0}.Release|Win32.Build.0 = Release|Win32 + {6A9058C6-06BD-4213-8F50-BC7DF8305EC0}.Release|x64.ActiveCfg = Release|x64 + {6A9058C6-06BD-4213-8F50-BC7DF8305EC0}.Release|x64.Build.0 = Release|x64 + {88467A66-9EF5-43F4-AD35-DB2C530E2374}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {88467A66-9EF5-43F4-AD35-DB2C530E2374}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {88467A66-9EF5-43F4-AD35-DB2C530E2374}.Debug|Win32.ActiveCfg = Debug|Win32 + {88467A66-9EF5-43F4-AD35-DB2C530E2374}.Debug|Win32.Build.0 = Debug|Win32 + {88467A66-9EF5-43F4-AD35-DB2C530E2374}.Debug|x64.ActiveCfg = Debug|x64 + {88467A66-9EF5-43F4-AD35-DB2C530E2374}.Debug|x64.Build.0 = Debug|x64 + {88467A66-9EF5-43F4-AD35-DB2C530E2374}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {88467A66-9EF5-43F4-AD35-DB2C530E2374}.Release|Mixed Platforms.Build.0 = Release|Win32 + {88467A66-9EF5-43F4-AD35-DB2C530E2374}.Release|Win32.ActiveCfg = Release|Win32 + {88467A66-9EF5-43F4-AD35-DB2C530E2374}.Release|Win32.Build.0 = Release|Win32 + {88467A66-9EF5-43F4-AD35-DB2C530E2374}.Release|x64.ActiveCfg = Release|x64 + {88467A66-9EF5-43F4-AD35-DB2C530E2374}.Release|x64.Build.0 = Release|x64 + {8B90DC19-E9AC-4D8C-A8E5-5190A986F9A0}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {8B90DC19-E9AC-4D8C-A8E5-5190A986F9A0}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {8B90DC19-E9AC-4D8C-A8E5-5190A986F9A0}.Debug|Win32.ActiveCfg = Debug|Win32 + {8B90DC19-E9AC-4D8C-A8E5-5190A986F9A0}.Debug|Win32.Build.0 = Debug|Win32 + {8B90DC19-E9AC-4D8C-A8E5-5190A986F9A0}.Debug|x64.ActiveCfg = Debug|x64 + {8B90DC19-E9AC-4D8C-A8E5-5190A986F9A0}.Debug|x64.Build.0 = Debug|x64 + {8B90DC19-E9AC-4D8C-A8E5-5190A986F9A0}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {8B90DC19-E9AC-4D8C-A8E5-5190A986F9A0}.Release|Mixed Platforms.Build.0 = Release|Win32 + {8B90DC19-E9AC-4D8C-A8E5-5190A986F9A0}.Release|Win32.ActiveCfg = Release|Win32 + {8B90DC19-E9AC-4D8C-A8E5-5190A986F9A0}.Release|Win32.Build.0 = Release|Win32 + {8B90DC19-E9AC-4D8C-A8E5-5190A986F9A0}.Release|x64.ActiveCfg = Release|x64 + {8B90DC19-E9AC-4D8C-A8E5-5190A986F9A0}.Release|x64.Build.0 = Release|x64 + {C3C57200-3B1F-465F-8631-E948A935D645}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {C3C57200-3B1F-465F-8631-E948A935D645}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {C3C57200-3B1F-465F-8631-E948A935D645}.Debug|Win32.ActiveCfg = Debug|Win32 + {C3C57200-3B1F-465F-8631-E948A935D645}.Debug|Win32.Build.0 = Debug|Win32 + {C3C57200-3B1F-465F-8631-E948A935D645}.Debug|x64.ActiveCfg = Debug|x64 + {C3C57200-3B1F-465F-8631-E948A935D645}.Debug|x64.Build.0 = Debug|x64 + {C3C57200-3B1F-465F-8631-E948A935D645}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {C3C57200-3B1F-465F-8631-E948A935D645}.Release|Mixed Platforms.Build.0 = Release|Win32 + {C3C57200-3B1F-465F-8631-E948A935D645}.Release|Win32.ActiveCfg = Release|Win32 + {C3C57200-3B1F-465F-8631-E948A935D645}.Release|Win32.Build.0 = Release|Win32 + {C3C57200-3B1F-465F-8631-E948A935D645}.Release|x64.ActiveCfg = Release|x64 + {C3C57200-3B1F-465F-8631-E948A935D645}.Release|x64.Build.0 = Release|x64 + {D8B6598C-913F-4507-AE93-518F7C76EBDA}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {D8B6598C-913F-4507-AE93-518F7C76EBDA}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {D8B6598C-913F-4507-AE93-518F7C76EBDA}.Debug|Win32.ActiveCfg = Debug|Win32 + {D8B6598C-913F-4507-AE93-518F7C76EBDA}.Debug|Win32.Build.0 = Debug|Win32 + {D8B6598C-913F-4507-AE93-518F7C76EBDA}.Debug|x64.ActiveCfg = Debug|x64 + {D8B6598C-913F-4507-AE93-518F7C76EBDA}.Debug|x64.Build.0 = Debug|x64 + {D8B6598C-913F-4507-AE93-518F7C76EBDA}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {D8B6598C-913F-4507-AE93-518F7C76EBDA}.Release|Mixed Platforms.Build.0 = Release|Win32 + {D8B6598C-913F-4507-AE93-518F7C76EBDA}.Release|Win32.ActiveCfg = Release|Win32 + {D8B6598C-913F-4507-AE93-518F7C76EBDA}.Release|Win32.Build.0 = Release|Win32 + {D8B6598C-913F-4507-AE93-518F7C76EBDA}.Release|x64.ActiveCfg = Release|x64 + {D8B6598C-913F-4507-AE93-518F7C76EBDA}.Release|x64.Build.0 = Release|x64 + {2E7E13B4-0AC4-480F-901F-024CF1938308}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {2E7E13B4-0AC4-480F-901F-024CF1938308}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {2E7E13B4-0AC4-480F-901F-024CF1938308}.Debug|Win32.ActiveCfg = Debug|Win32 + {2E7E13B4-0AC4-480F-901F-024CF1938308}.Debug|Win32.Build.0 = Debug|Win32 + {2E7E13B4-0AC4-480F-901F-024CF1938308}.Debug|x64.ActiveCfg = Debug|x64 + {2E7E13B4-0AC4-480F-901F-024CF1938308}.Debug|x64.Build.0 = Debug|x64 + {2E7E13B4-0AC4-480F-901F-024CF1938308}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {2E7E13B4-0AC4-480F-901F-024CF1938308}.Release|Mixed Platforms.Build.0 = Release|Win32 + {2E7E13B4-0AC4-480F-901F-024CF1938308}.Release|Win32.ActiveCfg = Release|Win32 + {2E7E13B4-0AC4-480F-901F-024CF1938308}.Release|Win32.Build.0 = Release|Win32 + {2E7E13B4-0AC4-480F-901F-024CF1938308}.Release|x64.ActiveCfg = Release|x64 + {2E7E13B4-0AC4-480F-901F-024CF1938308}.Release|x64.Build.0 = Release|x64 + {765D5D20-2470-4597-93CD-25A7E118814D}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {765D5D20-2470-4597-93CD-25A7E118814D}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {765D5D20-2470-4597-93CD-25A7E118814D}.Debug|Win32.ActiveCfg = Debug|x86 + {765D5D20-2470-4597-93CD-25A7E118814D}.Debug|Win32.Build.0 = Debug|x86 + {765D5D20-2470-4597-93CD-25A7E118814D}.Debug|x64.ActiveCfg = Debug|x64 + {765D5D20-2470-4597-93CD-25A7E118814D}.Debug|x64.Build.0 = Debug|x64 + {765D5D20-2470-4597-93CD-25A7E118814D}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {765D5D20-2470-4597-93CD-25A7E118814D}.Release|Mixed Platforms.Build.0 = Release|x86 + {765D5D20-2470-4597-93CD-25A7E118814D}.Release|Win32.ActiveCfg = Release|x86 + {765D5D20-2470-4597-93CD-25A7E118814D}.Release|Win32.Build.0 = Release|x86 + {765D5D20-2470-4597-93CD-25A7E118814D}.Release|x64.ActiveCfg = Release|x64 + {765D5D20-2470-4597-93CD-25A7E118814D}.Release|x64.Build.0 = Release|x64 + {0C9C33A6-D497-45A8-A74D-95E794C3AF78}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {0C9C33A6-D497-45A8-A74D-95E794C3AF78}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {0C9C33A6-D497-45A8-A74D-95E794C3AF78}.Debug|Win32.ActiveCfg = Debug|Win32 + {0C9C33A6-D497-45A8-A74D-95E794C3AF78}.Debug|Win32.Build.0 = Debug|Win32 + {0C9C33A6-D497-45A8-A74D-95E794C3AF78}.Debug|x64.ActiveCfg = Debug|x64 + {0C9C33A6-D497-45A8-A74D-95E794C3AF78}.Debug|x64.Build.0 = Debug|x64 + {0C9C33A6-D497-45A8-A74D-95E794C3AF78}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {0C9C33A6-D497-45A8-A74D-95E794C3AF78}.Release|Mixed Platforms.Build.0 = Release|Win32 + {0C9C33A6-D497-45A8-A74D-95E794C3AF78}.Release|Win32.ActiveCfg = Release|Win32 + {0C9C33A6-D497-45A8-A74D-95E794C3AF78}.Release|Win32.Build.0 = Release|Win32 + {0C9C33A6-D497-45A8-A74D-95E794C3AF78}.Release|x64.ActiveCfg = Release|x64 + {0C9C33A6-D497-45A8-A74D-95E794C3AF78}.Release|x64.Build.0 = Release|x64 + {58B52422-7322-40C5-BFF7-8E575B7AB63C}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {58B52422-7322-40C5-BFF7-8E575B7AB63C}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {58B52422-7322-40C5-BFF7-8E575B7AB63C}.Debug|Win32.ActiveCfg = Debug|Win32 + {58B52422-7322-40C5-BFF7-8E575B7AB63C}.Debug|Win32.Build.0 = Debug|Win32 + {58B52422-7322-40C5-BFF7-8E575B7AB63C}.Debug|x64.ActiveCfg = Debug|x64 + {58B52422-7322-40C5-BFF7-8E575B7AB63C}.Debug|x64.Build.0 = Debug|x64 + {58B52422-7322-40C5-BFF7-8E575B7AB63C}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {58B52422-7322-40C5-BFF7-8E575B7AB63C}.Release|Mixed Platforms.Build.0 = Release|Win32 + {58B52422-7322-40C5-BFF7-8E575B7AB63C}.Release|Win32.ActiveCfg = Release|Win32 + {58B52422-7322-40C5-BFF7-8E575B7AB63C}.Release|Win32.Build.0 = Release|Win32 + {58B52422-7322-40C5-BFF7-8E575B7AB63C}.Release|x64.ActiveCfg = Release|x64 + {58B52422-7322-40C5-BFF7-8E575B7AB63C}.Release|x64.Build.0 = Release|x64 + {8BCFAE5D-00F9-41A6-9A15-A1A5AE1EFAEA}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {8BCFAE5D-00F9-41A6-9A15-A1A5AE1EFAEA}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {8BCFAE5D-00F9-41A6-9A15-A1A5AE1EFAEA}.Debug|Win32.ActiveCfg = Debug|Win32 + {8BCFAE5D-00F9-41A6-9A15-A1A5AE1EFAEA}.Debug|Win32.Build.0 = Debug|Win32 + {8BCFAE5D-00F9-41A6-9A15-A1A5AE1EFAEA}.Debug|x64.ActiveCfg = Debug|x64 + {8BCFAE5D-00F9-41A6-9A15-A1A5AE1EFAEA}.Debug|x64.Build.0 = Debug|x64 + {8BCFAE5D-00F9-41A6-9A15-A1A5AE1EFAEA}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {8BCFAE5D-00F9-41A6-9A15-A1A5AE1EFAEA}.Release|Mixed Platforms.Build.0 = Release|Win32 + {8BCFAE5D-00F9-41A6-9A15-A1A5AE1EFAEA}.Release|Win32.ActiveCfg = Release|Win32 + {8BCFAE5D-00F9-41A6-9A15-A1A5AE1EFAEA}.Release|Win32.Build.0 = Release|Win32 + {8BCFAE5D-00F9-41A6-9A15-A1A5AE1EFAEA}.Release|x64.ActiveCfg = Release|x64 + {8BCFAE5D-00F9-41A6-9A15-A1A5AE1EFAEA}.Release|x64.Build.0 = Release|x64 + {D77B7B37-01D4-463A-B24F-4EDF3D5B979B}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {D77B7B37-01D4-463A-B24F-4EDF3D5B979B}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {D77B7B37-01D4-463A-B24F-4EDF3D5B979B}.Debug|Win32.ActiveCfg = Debug|Win32 + {D77B7B37-01D4-463A-B24F-4EDF3D5B979B}.Debug|Win32.Build.0 = Debug|Win32 + {D77B7B37-01D4-463A-B24F-4EDF3D5B979B}.Debug|x64.ActiveCfg = Debug|x64 + {D77B7B37-01D4-463A-B24F-4EDF3D5B979B}.Debug|x64.Build.0 = Debug|x64 + {D77B7B37-01D4-463A-B24F-4EDF3D5B979B}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {D77B7B37-01D4-463A-B24F-4EDF3D5B979B}.Release|Mixed Platforms.Build.0 = Release|Win32 + {D77B7B37-01D4-463A-B24F-4EDF3D5B979B}.Release|Win32.ActiveCfg = Release|Win32 + {D77B7B37-01D4-463A-B24F-4EDF3D5B979B}.Release|Win32.Build.0 = Release|Win32 + {D77B7B37-01D4-463A-B24F-4EDF3D5B979B}.Release|x64.ActiveCfg = Release|x64 + {D77B7B37-01D4-463A-B24F-4EDF3D5B979B}.Release|x64.Build.0 = Release|x64 + {ACEC4E45-AA20-4C1F-94FB-034459E3ABC7}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {ACEC4E45-AA20-4C1F-94FB-034459E3ABC7}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {ACEC4E45-AA20-4C1F-94FB-034459E3ABC7}.Debug|Win32.ActiveCfg = Debug|Win32 + {ACEC4E45-AA20-4C1F-94FB-034459E3ABC7}.Debug|Win32.Build.0 = Debug|Win32 + {ACEC4E45-AA20-4C1F-94FB-034459E3ABC7}.Debug|x64.ActiveCfg = Debug|x64 + {ACEC4E45-AA20-4C1F-94FB-034459E3ABC7}.Debug|x64.Build.0 = Debug|x64 + {ACEC4E45-AA20-4C1F-94FB-034459E3ABC7}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {ACEC4E45-AA20-4C1F-94FB-034459E3ABC7}.Release|Mixed Platforms.Build.0 = Release|Win32 + {ACEC4E45-AA20-4C1F-94FB-034459E3ABC7}.Release|Win32.ActiveCfg = Release|Win32 + {ACEC4E45-AA20-4C1F-94FB-034459E3ABC7}.Release|Win32.Build.0 = Release|Win32 + {ACEC4E45-AA20-4C1F-94FB-034459E3ABC7}.Release|x64.ActiveCfg = Release|x64 + {ACEC4E45-AA20-4C1F-94FB-034459E3ABC7}.Release|x64.Build.0 = Release|x64 + {693094D2-1470-4AB4-977E-8D82E5985618}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {693094D2-1470-4AB4-977E-8D82E5985618}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {693094D2-1470-4AB4-977E-8D82E5985618}.Debug|Win32.ActiveCfg = Debug|Win32 + {693094D2-1470-4AB4-977E-8D82E5985618}.Debug|Win32.Build.0 = Debug|Win32 + {693094D2-1470-4AB4-977E-8D82E5985618}.Debug|x64.ActiveCfg = Debug|x64 + {693094D2-1470-4AB4-977E-8D82E5985618}.Debug|x64.Build.0 = Debug|x64 + {693094D2-1470-4AB4-977E-8D82E5985618}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {693094D2-1470-4AB4-977E-8D82E5985618}.Release|Mixed Platforms.Build.0 = Release|Win32 + {693094D2-1470-4AB4-977E-8D82E5985618}.Release|Win32.ActiveCfg = Release|Win32 + {693094D2-1470-4AB4-977E-8D82E5985618}.Release|Win32.Build.0 = Release|Win32 + {693094D2-1470-4AB4-977E-8D82E5985618}.Release|x64.ActiveCfg = Release|x64 + {693094D2-1470-4AB4-977E-8D82E5985618}.Release|x64.Build.0 = Release|x64 + {EC2593D7-2AB1-4EFC-B412-9C5A70939DF9}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {EC2593D7-2AB1-4EFC-B412-9C5A70939DF9}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {EC2593D7-2AB1-4EFC-B412-9C5A70939DF9}.Debug|Win32.ActiveCfg = Debug|Win32 + {EC2593D7-2AB1-4EFC-B412-9C5A70939DF9}.Debug|Win32.Build.0 = Debug|Win32 + {EC2593D7-2AB1-4EFC-B412-9C5A70939DF9}.Debug|x64.ActiveCfg = Debug|x64 + {EC2593D7-2AB1-4EFC-B412-9C5A70939DF9}.Debug|x64.Build.0 = Debug|x64 + {EC2593D7-2AB1-4EFC-B412-9C5A70939DF9}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {EC2593D7-2AB1-4EFC-B412-9C5A70939DF9}.Release|Mixed Platforms.Build.0 = Release|Win32 + {EC2593D7-2AB1-4EFC-B412-9C5A70939DF9}.Release|Win32.ActiveCfg = Release|Win32 + {EC2593D7-2AB1-4EFC-B412-9C5A70939DF9}.Release|Win32.Build.0 = Release|Win32 + {EC2593D7-2AB1-4EFC-B412-9C5A70939DF9}.Release|x64.ActiveCfg = Release|x64 + {EC2593D7-2AB1-4EFC-B412-9C5A70939DF9}.Release|x64.Build.0 = Release|x64 + {236BB296-3A6D-4CBF-B8C2-4370790211F0}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {236BB296-3A6D-4CBF-B8C2-4370790211F0}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {236BB296-3A6D-4CBF-B8C2-4370790211F0}.Debug|Win32.ActiveCfg = Debug|Win32 + {236BB296-3A6D-4CBF-B8C2-4370790211F0}.Debug|Win32.Build.0 = Debug|Win32 + {236BB296-3A6D-4CBF-B8C2-4370790211F0}.Debug|x64.ActiveCfg = Debug|x64 + {236BB296-3A6D-4CBF-B8C2-4370790211F0}.Debug|x64.Build.0 = Debug|x64 + {236BB296-3A6D-4CBF-B8C2-4370790211F0}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {236BB296-3A6D-4CBF-B8C2-4370790211F0}.Release|Mixed Platforms.Build.0 = Release|Win32 + {236BB296-3A6D-4CBF-B8C2-4370790211F0}.Release|Win32.ActiveCfg = Release|Win32 + {236BB296-3A6D-4CBF-B8C2-4370790211F0}.Release|Win32.Build.0 = Release|Win32 + {236BB296-3A6D-4CBF-B8C2-4370790211F0}.Release|x64.ActiveCfg = Release|x64 + {236BB296-3A6D-4CBF-B8C2-4370790211F0}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {2E7E13B4-0AC4-480F-901F-024CF1938308} = {3EDA093F-F647-4857-BDBD-0E2DEF0E9A5D} + {765D5D20-2470-4597-93CD-25A7E118814D} = {3EDA093F-F647-4857-BDBD-0E2DEF0E9A5D} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {75852D3C-614B-4B3A-B2E5-36CF6671243E} + EndGlobalSection +EndGlobal diff --git a/exchange/exchangesource/BrepAdaptor/BrepAdaptor.cpp b/exchange/exchangesource/BrepAdaptor/BrepAdaptor.cpp new file mode 100644 index 0000000..60c6f6a --- /dev/null +++ b/exchange/exchangesource/BrepAdaptor/BrepAdaptor.cpp @@ -0,0 +1,194 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file BrepAdaptor.cpp + +The B-rep used by HOOPS Exchange may not be completely compatible with modeling systems that do not support the full range of B-rep as employed by PRC. A3DCopyAndAdaptBrepModel attempts to convert PRC B-rep into a format that is compatible with your system. + +This program demonstrates how to programmatically adapt B-rep models to your particular needs using HOOPS Exchange. B-rep +is always found in this hierarchy: + +Model file > Product occurrence > Part definition > B-rep + +The functions below attempt to find the B-rep entities by traversing the model tree. + +This program reads a model file and outputs a PRC file. Specify these files on the command line (see 'Usage'). + +- Load a CAD file +- Traverse the entire data structure +- Call A3DCopyAndAdaptBrepModel for each BrepModels. +- Copy inputs BrepModels. +- Selected Geometricals surfaces are converted to nurbs. +- Faces are split. +- UV Curves are computed. +- New modified data are populated +- PRC is exported from the modified data + +***********************************************************************************************************************/ + +#define INITIALIZE_A3D_API +#include + +#include "../common.hpp" + +static MY_CHAR acSrcFileName[_MAX_PATH * 2]; +static MY_CHAR acDstFileName[_MAX_PATH * 2]; +static MY_CHAR acLogFileName[_MAX_PATH * 2]; + +//###################################################################################################################### +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + // + // ### COMMAND LINE ARGUMENTS + // + + if (iArgc > 4) + { + MY_PRINTF2("Usage:\n %s [input CAD file] [output CAD file] [output LOG file]\n", ppcArgv[0]); + MY_PRINTF(" Default output CAD file is [input CAD file].prc\n"); + MY_PRINTF(" Default output LOG file is [output CAD file]_Log.txt\n\n"); + return A3D_ERROR; + } + + if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]); + else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD); + if (iArgc > 2) MY_STRCPY(acDstFileName, ppcArgv[2]); + else MY_SPRINTF(acDstFileName, "%s.prc", acSrcFileName); + if (iArgc > 3) MY_STRCPY(acLogFileName, ppcArgv[3]); + else MY_SPRINTF(acLogFileName, "%s_Log.txt", acDstFileName); + GetLogFile(acLogFileName); // Initialize log file + + // + // ### INITIALIZE HOOPS EXCHANGE + // + + A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); + CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus); + + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + // + // ### PROCESS SAMPLE CODE + // + + // specify input file + A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + + A3DStatus iRet = sHoopsExchangeLoader.Import(sImport); + if (iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS) + CHECK_RET(iRet); + + const A3DUns32 NUM_VALID_SURFACES = 11; + A3DUns32 ACCEPTED_SURFACES[NUM_VALID_SURFACES] = { + kA3DTypeSurfBlend01, + //kA3DTypeSurfBlend02, + //kA3DTypeSurfBlend03, + kA3DTypeSurfNurbs, + kA3DTypeSurfCone, + kA3DTypeSurfCylinder, + kA3DTypeSurfCylindrical, + //kA3DTypeSurfOffset, + //kA3DTypeSurfPipe, + kA3DTypeSurfPlane, + kA3DTypeSurfRuled, + kA3DTypeSurfSphere, + //kA3DTypeSurfRevolution, + kA3DTypeSurfExtrusion, + //kA3DTypeSurfFromCurves, + kA3DTypeSurfTorus, + kA3DTypeSurfTransform, + //kA3DTypeSurfBlend04, + }; + + const A3DUns32 NUM_VALID_CURVES = 13; + A3DUns32 ACCEPTED_CURVES[NUM_VALID_CURVES] = { + //kA3DTypeCrvBase, + //kA3DTypeCrvBlend02Boundary, + kA3DTypeCrvNurbs, + kA3DTypeCrvCircle, + kA3DTypeCrvComposite, + kA3DTypeCrvOnSurf, + kA3DTypeCrvEllipse, + kA3DTypeCrvEquation, + kA3DTypeCrvHelix, + kA3DTypeCrvHyperbola, + //kA3DTypeCrvIntersection, + kA3DTypeCrvLine, + kA3DTypeCrvOffset, + kA3DTypeCrvParabola, + kA3DTypeCrvPolyLine, + kA3DTypeCrvTransform, + }; + + A3DCopyAndAdaptBrepModelData sCopyAndAdaptBrepModelData; + A3D_INITIALIZE_DATA(A3DCopyAndAdaptBrepModelData, sCopyAndAdaptBrepModelData); + + sCopyAndAdaptBrepModelData.m_bUseSameParam = false; + sCopyAndAdaptBrepModelData.m_dTol = 1e-3; + sCopyAndAdaptBrepModelData.m_bDeleteCrossingUV = false; + sCopyAndAdaptBrepModelData.m_bAllowUVCrossingSeams = false; + sCopyAndAdaptBrepModelData.m_bSplitFaces = false; + sCopyAndAdaptBrepModelData.m_bSplitClosedFaces = false; + sCopyAndAdaptBrepModelData.m_bForceComputeUV = true; + sCopyAndAdaptBrepModelData.m_bForceCompute3D = false; + sCopyAndAdaptBrepModelData.m_uiAcceptableSurfacesSize = NUM_VALID_SURFACES; + sCopyAndAdaptBrepModelData.m_puiAcceptableSurfaces = &ACCEPTED_SURFACES[0]; + sCopyAndAdaptBrepModelData.m_uiAcceptableCurvesSize = NUM_VALID_CURVES; + sCopyAndAdaptBrepModelData.m_puiAcceptableCurves = &ACCEPTED_CURVES[0]; + sCopyAndAdaptBrepModelData.m_bContinueOnError = true; + + A3DUns32 uiNbErrors = 0; + A3DCopyAndAdaptBrepModelErrorData *pErrors; + iRet = A3DAdaptAndReplaceAllBrepInModelFileAdvanced(sHoopsExchangeLoader.m_psModelFile, &sCopyAndAdaptBrepModelData, &uiNbErrors, &pErrors); + if ((iRet == A3D_SUCCESS || iRet == A3D_TOOLS_CONTINUE_ON_ERROR) && uiNbErrors > 0) + { + for (A3DUns32 i = 0; i < uiNbErrors; i++) + { + A3DCopyAndAdaptBrepModelErrorData* pCurrentError = &pErrors[i]; + + fprintf(GetLogFile(), "----------\n"); + + //see A3DSDKTypes.h for entity type + A3DEEntityType entityType; + CHECK_RET(A3DEntityGetType(pCurrentError->m_pEntity, &entityType)); + fprintf(GetLogFile(), "Error on entity type........: %s(%d)\n", A3DMiscGetEntityTypeMsg(entityType), entityType); + fprintf(GetLogFile(), "Error on topological type...: %s(%d)\n", A3DMiscGetEntityTypeMsg((A3DEEntityType)pCurrentError->m_paiErrors[0]), pCurrentError->m_paiErrors[0]); + fprintf(GetLogFile(), "Status......................: %s(%d)\n", A3DMiscGetErrorMsg((A3DStatus)pCurrentError->m_paiErrors[1]), pCurrentError->m_paiErrors[1]); + + fprintf(GetLogFile(), "The error is on the "); + A3DUns32 numIndex = pCurrentError->m_paiErrors[2]; + if (numIndex == 0) fprintf(GetLogFile(), "BREP"); + if (numIndex >= 1) fprintf(GetLogFile(), "Connex: %d", pCurrentError->m_paiErrors[3]); + if (numIndex >= 2) fprintf(GetLogFile(), ", Shell: %d", pCurrentError->m_paiErrors[4]); + if (numIndex >= 3) fprintf(GetLogFile(), ", Face: %d", pCurrentError->m_paiErrors[5]); + if (numIndex >= 4) fprintf(GetLogFile(), ", Loop: %d", pCurrentError->m_paiErrors[6]); + if (numIndex >= 5) fprintf(GetLogFile(), ", CoEdge/Edge: %d", pCurrentError->m_paiErrors[7]); + fprintf(GetLogFile(), ".\n\n"); + } + } + + // specify output file + A3DExport sExport(acDstFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + iRet = sHoopsExchangeLoader.Export(sExport); + if (!iRet) + return iRet; + // + // ### TERMINATE HOOPS EXCHANGE + // + + // Check memory allocations + return (int)ListLeaks(); +} diff --git a/exchange/exchangesource/BrepAdaptor/BrepAdaptor.vcxproj b/exchange/exchangesource/BrepAdaptor/BrepAdaptor.vcxproj new file mode 100644 index 0000000..199b3d5 --- /dev/null +++ b/exchange/exchangesource/BrepAdaptor/BrepAdaptor.vcxproj @@ -0,0 +1,165 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {7CD4F74A-2286-4744-BF8C-C8B55E76730B} + BrepAdaptor + Win32Proj + 10.0 + + + + Application + v145 + true + + + Application + v145 + + + Application + v145 + true + + + Application + v145 + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + true + Console + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + true + Console + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + MaxSpeed + true + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + Level4 + ProgramDatabase + false + + + true + Console + true + true + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + MaxSpeed + true + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + Level4 + ProgramDatabase + false + + + true + Console + true + true + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/BrepAdaptor/BrepAdaptor.vcxproj.filters b/exchange/exchangesource/BrepAdaptor/BrepAdaptor.vcxproj.filters new file mode 100644 index 0000000..98df221 --- /dev/null +++ b/exchange/exchangesource/BrepAdaptor/BrepAdaptor.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + Source Files + + + \ No newline at end of file diff --git a/exchange/exchangesource/CascadedAttributes/CascadedAttributes.cpp b/exchange/exchangesource/CascadedAttributes/CascadedAttributes.cpp new file mode 100644 index 0000000..1c028d7 --- /dev/null +++ b/exchange/exchangesource/CascadedAttributes/CascadedAttributes.cpp @@ -0,0 +1,462 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file CascadedAttributes.cpp + +This file demonstrates how to programmatically set the mechanism of the cascaded attributes using HOOPS Exchange. + +***********************************************************************************************************************/ + +#define INITIALIZE_A3D_API +#include + +#include "../common.hpp" + +//###################################################################################################################### +struct MiscCascadedAttributesGuard +{ + A3DMiscCascadedAttributes* ptr_; + + MiscCascadedAttributesGuard(A3DMiscCascadedAttributes* ptr): ptr_(ptr) + {} + + ~MiscCascadedAttributesGuard() + { + TEST_RET(A3DMiscCascadedAttributesDelete(ptr_)) + ptr_ = NULL; + } +}; + +//###################################################################################################################### +static A3DUTF8Char stpcWinTitle[_MAX_PATH]; + +//###################################################################################################################### +/*! Given an A3DRootBaseWithGraphics*, will return the name of that entity in the out parameter m_ppcName. + */ +A3DStatus stGetName( + const A3DRootBaseWithGraphics* pPartOrProduct, + A3DUTF8Char** m_ppcName) +{ + A3DRootBaseData sRootBaseData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sRootBaseData); + CHECK_RET(A3DRootBaseGet(pPartOrProduct, &sRootBaseData)); + const DATAGUARD(A3DRootBase) sGuard(sRootBaseData, A3DRootBaseGet); + + if (sRootBaseData.m_pcName != NULL) + { + *m_ppcName = static_cast(malloc(strlen(sRootBaseData.m_pcName) + 1)); + strncpy(*m_ppcName, sRootBaseData.m_pcName, strlen(sRootBaseData.m_pcName)); + (*m_ppcName)[strlen(sRootBaseData.m_pcName)] = '\0'; + } + return A3D_SUCCESS; +} + +//###################################################################################################################### +/*! Gets the color values for a A3DRootBaseWithGraphics, then prints it to the console. + */ +A3DStatus stExtractColorFromGraphicData( + const A3DRootBaseWithGraphics* pRootBaseWithGraphics, + const A3DGraphStyleData& sGraphStyleData) +{ + // Get its name + A3DUTF8Char* pcName = NULL; + const A3DStatus iRet = stGetName(pRootBaseWithGraphics, &pcName); + const MemoryGuard sGuard(pcName); + CHECK_RET(iRet); + + // First get non-inherited color information + A3DRootBaseWithGraphicsData rbwgData; + A3D_INITIALIZE_DATA(A3DRootBaseWithGraphicsData, rbwgData); + A3DRootBaseWithGraphicsGet(pRootBaseWithGraphics, &rbwgData); + if (rbwgData.m_pGraphics != NULL) + { + // this entity has an attached graphics object + A3DGraphicsData graphicsData; + A3D_INITIALIZE_DATA(A3DGraphicsData, graphicsData); + A3DGraphicsGet(rbwgData.m_pGraphics, &graphicsData); + + A3DGraphStyleData styleData; + A3D_INITIALIZE_DATA(A3DGraphStyleData, styleData); + A3DGlobalGetGraphStyleData(graphicsData.m_uiStyleIndex, &styleData); + + A3DGraphRgbColorData sColorData; + A3D_INITIALIZE_DATA(A3DGraphRgbColorData, sColorData); + + if (!sGraphStyleData.m_bMaterial) + { + if (A3DGlobalGetGraphRgbColorData(styleData.m_uiRgbColorIndex, &sColorData) == A3D_SUCCESS) + { + fprintf( + GetLogFile(), + "\tcolor without inheritance of %s: %f %f %f\n", + pcName, + sColorData.m_dRed, + sColorData.m_dGreen, + sColorData.m_dBlue); + } + + A3DGlobalGetGraphRgbColorData(A3D_DEFAULT_COLOR_INDEX, &sColorData); + + } + else + { + fprintf( + GetLogFile(), + "\t local material of %s: %u\n", + pcName, + sGraphStyleData.m_uiRgbColorIndex + ); + } + + A3DGlobalGetGraphStyleData(A3D_DEFAULT_STYLE_INDEX, &styleData); + A3DGraphicsGet(NULL, &graphicsData); + } + + // Then get inherited color information + if (!sGraphStyleData.m_bMaterial) + { + A3DGraphRgbColorData sColorData; + A3D_INITIALIZE_DATA(A3DGraphRgbColorData, sColorData); + + + if (A3DGlobalGetGraphRgbColorData(sGraphStyleData.m_uiRgbColorIndex, &sColorData) == A3D_SUCCESS) + { + fprintf( + GetLogFile(), + "\tcolor with inheritance of %s: %f %f %f\n", + pcName, + sColorData.m_dRed, + sColorData.m_dGreen, + sColorData.m_dBlue); + } + + A3DGlobalGetGraphRgbColorData(A3D_DEFAULT_COLOR_INDEX, &sColorData); + } + else + { + fprintf( + GetLogFile(), + "\t inheritance material of %s: %u\n", + pcName, + sGraphStyleData.m_uiRgbColorIndex + ); + } + return A3D_SUCCESS; +} + +//###################################################################################################################### +/*! Creates an A3DMiscCascadedAttributes structure and computes the attributes + * based on the input A3DRootBaseWithGraphics structure pBase. + */ +static A3DStatus stCreateAndPushCascadedAttributes( + const A3DRootBaseWithGraphics* pBase, + const A3DMiscCascadedAttributes* pFatherAttr, + A3DMiscCascadedAttributes** ppAttr, + A3DMiscCascadedAttributesData* psAttrData) +{ + CHECK_RET(A3DMiscCascadedAttributesCreate(ppAttr)); + CHECK_RET(A3DMiscCascadedAttributesPush(*ppAttr, pBase, pFatherAttr)); + + A3D_INITIALIZE_DATA(A3DMiscCascadedAttributesData, (*psAttrData)); + CHECK_RET(A3DMiscCascadedAttributesGet(*ppAttr, psAttrData)); + CHECK_RET(stExtractColorFromGraphicData(pBase, psAttrData->m_sStyle)); + return A3D_SUCCESS; +} + +//###################################################################################################################### +/*! Parses a face, then computes cascaded attributes for that face. + */ +static A3DStatus stParseFace( + const A3DTopoFace* pFace, + const A3DMiscCascadedAttributes* pFatherAttr) +{ + PrintLogMessage("Face level\n"); + + A3DMiscCascadedAttributes* pAttr; + A3DMiscCascadedAttributesData sAttrData; + CHECK_RET(stCreateAndPushCascadedAttributes(pFace, pFatherAttr, &pAttr, &sAttrData)); + const MiscCascadedAttributesGuard sMCAttrGuard(pAttr); + return A3D_SUCCESS; +} + +//###################################################################################################################### +/*! Parses a shell, then calls stParseFace for each face found in the shell. + */ +static A3DStatus stParseShell(const A3DTopoShell* pShell, const A3DMiscCascadedAttributes* pFatherAttr) +{ + PrintLogMessage("Shell level\n"); + + A3DMiscCascadedAttributes* pAttr; + A3DMiscCascadedAttributesData sAttrData; + CHECK_RET(stCreateAndPushCascadedAttributes(pShell, pFatherAttr, &pAttr, &sAttrData)); + const MiscCascadedAttributesGuard sMCAttrGuard(pAttr); + + A3DTopoShellData sTopoShellData; + A3D_INITIALIZE_DATA(A3DTopoShellData, sTopoShellData); + CHECK_RET(A3DTopoShellGet(pShell, &sTopoShellData)); + const DATAGUARD(A3DTopoShell) sGuard(sTopoShellData, A3DTopoShellGet); + + for (unsigned int ui = 0; ui < sTopoShellData.m_uiFaceSize; ++ui) + CHECK_RET(stParseFace(sTopoShellData.m_ppFaces[ui], pAttr)); + + return A3D_SUCCESS; +} + +//###################################################################################################################### +/*! Parses a connex, then calls stParseShell for each shell found in the connex. + */ +static A3DStatus stParseConnex( + const A3DTopoConnex* pConnex, + const A3DMiscCascadedAttributes* pFatherAttr) +{ + PrintLogMessage("Connex level\n"); + + A3DMiscCascadedAttributes* pAttr; + A3DMiscCascadedAttributesData sAttrData; + CHECK_RET(stCreateAndPushCascadedAttributes(pConnex, pFatherAttr, &pAttr, &sAttrData)); + const MiscCascadedAttributesGuard sMCAttrGuard(pAttr); + + A3DTopoConnexData sTopoConnexData; + A3D_INITIALIZE_DATA(A3DTopoConnexData, sTopoConnexData); + CHECK_RET(A3DTopoConnexGet(pConnex, &sTopoConnexData)); + const DATAGUARD(A3DTopoConnex) sGuard(sTopoConnexData, A3DTopoConnexGet); + + for (unsigned int ui = 0; ui < sTopoConnexData.m_uiShellSize; ++ui) + CHECK_RET(stParseShell(sTopoConnexData.m_ppShells[ui], pAttr)); + + return A3D_SUCCESS; +} + +//###################################################################################################################### +/*! Parses a representation item and computes cascaded attributes for it. + * Calls stParseConnex for each connex in this representation item. + */ +static A3DStatus stParseRepresentationItem( + const A3DRiRepresentationItem* pRepItem, + const A3DMiscCascadedAttributes* pFatherAttr) +{ + PrintLogMessage("Representation item level\n"); + + A3DMiscCascadedAttributes* pAttr; + A3DMiscCascadedAttributesData sAttrData; + + // Compute the cascaded attributes for this representation item + CHECK_RET(stCreateAndPushCascadedAttributes(pRepItem, pFatherAttr, &pAttr, &sAttrData)); + const MiscCascadedAttributesGuard sMCAttrGuard(pAttr); + + A3DEEntityType eType = kA3DTypeUnknown; + CHECK_RET(A3DEntityGetType(pRepItem, &eType)); + + if(eType == kA3DTypeRiBrepModel) + { + const A3DRiBrepModel* pBrepModel = static_cast(pRepItem); + + A3DRiBrepModelData sBrepModelData; + A3D_INITIALIZE_DATA(A3DRiBrepModelData, sBrepModelData); + CHECK_RET(A3DRiBrepModelGet(pBrepModel, &sBrepModelData)); + const DATAGUARD(A3DRiBrepModel) sGuard1(sBrepModelData, A3DRiBrepModelGet); + + A3DTopoBrepDataData sTopoBrepDataData; + A3D_INITIALIZE_DATA(A3DTopoBrepDataData, sTopoBrepDataData); + CHECK_RET(A3DTopoBrepDataGet(sBrepModelData.m_pBrepData, &sTopoBrepDataData)); + const DATAGUARD(A3DTopoBrepData) sGuard2(sTopoBrepDataData, A3DTopoBrepDataGet); + + for (unsigned int ui = 0; ui < sTopoBrepDataData.m_uiConnexSize; ++ui) + CHECK_RET(stParseConnex(sTopoBrepDataData.m_ppConnexes[ui], pAttr)); + } + return A3D_SUCCESS; +} + +//###################################################################################################################### +/*! Iterates over all the representation items in the part pPart, and calls + * stParseRepresentationItem on each one. + */ +static A3DStatus stParsePartDefinition( + const A3DAsmPartDefinition* pPart, + const A3DMiscCascadedAttributes* pFatherAttr) +{ + PrintLogMessage("Part definition level\n"); + + A3DMiscCascadedAttributes* pAttr; + A3DMiscCascadedAttributesData sAttrData; + CHECK_RET(stCreateAndPushCascadedAttributes(pPart, pFatherAttr, &pAttr, &sAttrData)); + const MiscCascadedAttributesGuard sMCAttrGuard(pAttr); + + A3DAsmPartDefinitionData sPartData; + A3D_INITIALIZE_DATA(A3DAsmPartDefinitionData, sPartData); + CHECK_RET(A3DAsmPartDefinitionGet(pPart, &sPartData)); + const DATAGUARD(A3DAsmPartDefinition) sGuard(sPartData, A3DAsmPartDefinitionGet); + + for (unsigned int ui = 0; ui < sPartData.m_uiRepItemsSize; ++ui) + CHECK_RET(stParseRepresentationItem(sPartData.m_ppRepItems[ui], pAttr)); + + return A3D_SUCCESS; +} + +//###################################################################################################################### +/*! Returns a part definition from a product occurrence. Part definition is returned as + * the out parameter ppPart. + */ +static A3DStatus stProductOccurrenceGetPart( + const A3DAsmProductOccurrenceData* psPOccData, + A3DAsmPartDefinition** ppPart) +{ + if(psPOccData == NULL) + return A3D_ERROR; + + *ppPart = NULL; + if(psPOccData->m_pPart != NULL) + { + *ppPart = psPOccData->m_pPart; + return A3D_SUCCESS; + } + + A3DAsmProductOccurrence* pProductPrototype = psPOccData->m_pPrototype; + while(pProductPrototype != NULL) + { + A3DAsmProductOccurrenceData sProductPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductPrototypeData); + CHECK_RET(A3DAsmProductOccurrenceGet(pProductPrototype, &sProductPrototypeData)); + const DATAGUARD(A3DAsmProductOccurrence) sGuard(sProductPrototypeData, A3DAsmProductOccurrenceGet); + + if(sProductPrototypeData.m_pPart != NULL) + { + *ppPart = sProductPrototypeData.m_pPart; + return A3D_SUCCESS; + } + else + pProductPrototype = sProductPrototypeData.m_pPrototype; + } + return A3D_SUCCESS; +} + +//###################################################################################################################### +/*! Parses a product occurrence recursively. When a part + * definition is found, it is then passed to stParsePartDefinition. + */ +static A3DStatus stParseProductOccurrence( + const A3DAsmProductOccurrence* pOccurrence, + const A3DMiscCascadedAttributes* pFatherAttr) +{ + PrintLogMessage("Product Occurrence level\n"); + + A3DMiscCascadedAttributes* pAttr; + A3DMiscCascadedAttributesData sAttrData; + CHECK_RET(stCreateAndPushCascadedAttributes(pOccurrence, pFatherAttr, &pAttr, &sAttrData)); + const MiscCascadedAttributesGuard sMCAttrGuard(pAttr); + + A3DAsmProductOccurrenceData sData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sData); + CHECK_RET(A3DAsmProductOccurrenceGet(pOccurrence, &sData)); + const DATAGUARD(A3DAsmProductOccurrence) sGuard(sData, A3DAsmProductOccurrenceGet); + + + A3DAsmPartDefinition* pPart = NULL; + TEST_RET(stProductOccurrenceGetPart(&sData, &pPart)); + + if (pPart) + CHECK_RET(stParsePartDefinition(pPart, pAttr)); + + if (sData.m_uiPOccurrencesSize > 0) + { + for (unsigned int ui = 0; ui < sData.m_uiPOccurrencesSize; ui++) + { + CHECK_RET(stParseProductOccurrence(sData.m_ppPOccurrences[ui], pAttr)); + } + } + + return A3D_SUCCESS; +} + +//###################################################################################################################### +/*! Calls stParseProductOccurrence for each product occurrence in the input parameter pModelFile. + */ +A3DStatus stParseCascadedAttributes(const A3DAsmModelFile* pModelFile) +{ + // allocate model file structure + A3DAsmModelFileData sData; + A3D_INITIALIZE_DATA(A3DAsmModelFileData, sData); + CHECK_RET(A3DAsmModelFileGet(pModelFile, &sData)); + const DATAGUARD(A3DAsmModelFile) sGuard(sData, A3DAsmModelFileGet); + + // allocate cascaded attributes + A3DMiscCascadedAttributes* pAttr; + CHECK_RET(A3DMiscCascadedAttributesCreate(&pAttr)); + const MiscCascadedAttributesGuard sMCAttrGuard(pAttr); + + for (A3DUns32 ui = 0; ui < sData.m_uiPOccurrencesSize; ++ui) + // traverse the model tree + CHECK_RET(stParseProductOccurrence(sData.m_ppPOccurrences[ui], pAttr)); + + return A3D_SUCCESS; +} + +static MY_CHAR acSrcFileName[_MAX_PATH * 2]; +static MY_CHAR acLogFileName[_MAX_PATH * 2]; + +//###################################################################################################################### +// Main function +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + + // + // ### COMMAND LINE ARGUMENTS + // + + if (iArgc > 3) + { + MY_PRINTF2("Usage:\n %s [input CAD file] [output LOG file]\n", ppcArgv[0]); + MY_PRINTF(" Default output LOG file is [input CAD file]_Log.txt\n\n"); + return A3D_ERROR; + } + + if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]); + else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD); + if (iArgc > 2) MY_STRCPY(acLogFileName, ppcArgv[2]); + else MY_SPRINTF(acLogFileName, "%s_Log.txt", acSrcFileName); + GetLogFile(acLogFileName); // Initialize log file + + // + // ### INITIALIZE HOOPS EXCHANGE + // + + A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); + CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus); + + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + // + // ### PROCESS SAMPLE CODE + // + + // Initialize importer + A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + + A3DStatus iRet = sHoopsExchangeLoader.Import(sImport); + if (iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS) + CHECK_RET(iRet); + + // Parse model for cascaded attributes + CHECK_RET(stParseCascadedAttributes(sHoopsExchangeLoader.m_psModelFile)); + + // + // ### TERMINATE HOOPS EXCHANGE + // + + // Check memory allocations + // Check memory allocations + return (int)ListLeaks(); +} diff --git a/exchange/exchangesource/CascadedAttributes/CascadedAttributes.vcxproj b/exchange/exchangesource/CascadedAttributes/CascadedAttributes.vcxproj new file mode 100644 index 0000000..7464b30 --- /dev/null +++ b/exchange/exchangesource/CascadedAttributes/CascadedAttributes.vcxproj @@ -0,0 +1,195 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {C7C85E0A-87B5-4E20-9F62-7C16802ABA00} + CascadedAttributes + Win32Proj + 10.0 + + + + Application + v145 + false + true + + + Application + v145 + false + + + Application + v145 + false + true + + + Application + v145 + false + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + Sync + EnableFastChecks + MultiThreadedDebugDLL + true + + Level4 + ProgramDatabase + false + + + LinkVerboseLib + $(OutDir)$(ProjectName).exe + true + Console + false + + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + X64 + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + Sync + EnableFastChecks + MultiThreadedDebugDLL + true + + Level4 + ProgramDatabase + false + + + LinkVerboseLib + $(OutDir)$(ProjectName).exe + true + Console + false + + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level4 + ProgramDatabase + false + + + $(OutDir)$(ProjectName).exe + .\glut\lib;%(AdditionalLibraryDirectories) + false + Console + true + true + false + + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + X64 + + + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level4 + ProgramDatabase + false + + + $(OutDir)$(ProjectName).exe + .\glut\lib;%(AdditionalLibraryDirectories) + false + Console + true + true + false + + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/CascadedAttributes/CascadedAttributes.vcxproj.filters b/exchange/exchangesource/CascadedAttributes/CascadedAttributes.vcxproj.filters new file mode 100644 index 0000000..074ea19 --- /dev/null +++ b/exchange/exchangesource/CascadedAttributes/CascadedAttributes.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + + + Source Files + + + \ No newline at end of file diff --git a/exchange/exchangesource/Collision/Collision.cpp b/exchange/exchangesource/Collision/Collision.cpp new file mode 100644 index 0000000..e20c21b --- /dev/null +++ b/exchange/exchangesource/Collision/Collision.cpp @@ -0,0 +1,425 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file Collision.cpp + +This program demonstrates how to programmatically use the A3DCollisionCompute function. + +This program reads a model file and outputs a text file. Specify these files on the command line (see 'Usage'). + +A sample file can be find in data directory : data\inventor\collision.iam + +Usage: +Collision [INPUT] [OUTPUT] [UUIDs...] +INPUT The input CAD file. Default is '00242AC8' +OUTPUT The output result file. Default is 'CURRENT_DIR/Collision.txt' +UUID1 UUID2... Any number of space separated UUIDs of representation items to be checked to each other. If not set, two relevant UUIDs from the CAD file will be picked + +***********************************************************************************************************************/ + +#ifdef _MSC_VER +# define SAMPLE_DEFAULT_CAD_FILE _T(SAMPLES_DATA_DIRECTORY"\\inventor\\collision.iam") +# define SAMPLE_DEFAULT_RESULT_FILE _T("Collision.txt") +#else +# define SAMPLE_DEFAULT_CAD_FILE SAMPLES_DATA_DIRECTORY"/inventor/collision.iam" +# define SAMPLE_DEFAULT_RESULT_FILE "Collision.txt" +#endif + +#define INITIALIZE_A3D_API +#include + +#include "../common.hpp" + +#include "visitor/VisitorContainer.h" +#include "visitor/VisitorCascadedAttribute.h" +#include "visitor/VisitorTree.h" +#include "visitor/VisitorTransfo.h" +#include "visitor/CascadedAttributeConnector.h" +#include "visitor/TransfoConnector.h" +#include +#ifdef _MSC_VER +# include +#endif +#include +#include +#include +#include + +using string_t = std::basic_string; + +// function declared in createssellatedbox.cpp +A3DStatus CreatePolyBrepModelFromABBox(A3DBoundingBoxData const & sABBox, A3DRiPolyBrepModel ** pRiPolyBrepModel); + +//###################################################################################################################### +struct A3DFlattenVisitor : public A3DTreeVisitor +{ + std::vector m_vA3DRiBrepModel; + std::vector m_vA3DMatrix4x4; + std::vector m_vProductIdentifier; + + A3DUTF8Char * m_pcProductIdentifier = nullptr; + + double m_dScaleToMm = 1.; + + A3DFlattenVisitor(A3DVisitorContainer* psContainer = NULL) : A3DTreeVisitor(psContainer) { psContainer->SetTraverseInstance(true); } + + ~A3DFlattenVisitor() + { + for (A3DUTF8Char* p: m_vProductIdentifier) + free(p); + } + + A3DStatus visitEnter(const A3DPartConnector& sConnector) override + { + A3DStatus iRet = A3DTreeVisitor::visitEnter(sConnector); + if (iRet == A3D_SUCCESS) + { + A3DAsmProductOccurrenceGetIdentifier(sConnector.GetProductOccurrenceFather(), &m_pcProductIdentifier); + } + + return iRet; + } + + A3DStatus visitLeave(const A3DPartConnector& sConnector) override + { + A3DStatus iRet = A3DTreeVisitor::visitLeave(sConnector); + if (m_pcProductIdentifier) + { + A3DAsmProductOccurrenceGetIdentifier(nullptr, &m_pcProductIdentifier); + } + + return iRet; + } + + virtual A3DStatus visitEnter(const A3DRiConnector& sConnector) override + { + A3DStatus iRet = A3DTreeVisitor::visitEnter(sConnector); + + const A3DEntity* pRi = sConnector.GetA3DEntity(); + A3DEEntityType eType = kA3DTypeUnknown; + iRet = A3DEntityGetType(pRi, &eType); + if ((iRet == A3D_SUCCESS) && (eType == kA3DTypeRiBrepModel || eType == kA3DTypeRiPolyBrepModel)) + { + A3DVisitorColorMaterials *pA3DCascadedVisitor = static_cast(m_psContainer->GetVisitorByName("CascadedAttribute")); + if (pA3DCascadedVisitor) + { + ColorMaterialsConnector sColorConnector(nullptr); + pA3DCascadedVisitor->GetColorMaterialConnector(sColorConnector); + + if (!sColorConnector.IsShow()) + return A3D_SUCCESS; + } + + m_vA3DRiBrepModel.push_back((A3DRiRepresentationItem*)sConnector.GetA3DEntity()); + + A3DVisitorTransfo* psVisitorTransfo = static_cast(m_psContainer->GetVisitorByName("Transformation")); + A3DTransfoConnector* pConnector = psVisitorTransfo->GetTransfoConnector(); + A3DMatrix4x4 sTransfo; + pConnector->GetGlobalTransfo(sTransfo); + delete pConnector; + + // Get global transfo + if (m_dScaleToMm != 1.) + { + A3DMatrix4x4 sScale; + sScale.ResetToIdentity(); + sScale.m_adM[0] = m_dScaleToMm; + sScale.m_adM[5] = m_dScaleToMm; + sScale.m_adM[10] = m_dScaleToMm; + sScale.m_adM[15] = m_dScaleToMm; + + A3DMatrix4x4 sScaledTransfo; + sScaledTransfo = sTransfo * sScale; + sScaledTransfo.m_adM[15] = 1.; + m_vA3DMatrix4x4.push_back(sScaledTransfo); + } + else + m_vA3DMatrix4x4.push_back(sTransfo); + + // Get product occurence identifier ... assuming that there only on rep item by part + A3DUTF8Char * pcProductID = nullptr; + if (m_pcProductIdentifier != nullptr) + { + size_t iLen = strlen(m_pcProductIdentifier); + pcProductID = static_cast(malloc(sizeof(A3DUTF8Char)*(iLen + 1))); + strcpy(pcProductID, m_pcProductIdentifier); + } + m_vProductIdentifier.push_back(pcProductID); + + } + return iRet; + } +}; + +//##################################################################################################################### +A3DStatus stGetFlattenRepItemInMmFromModelFile( A3DAsmModelFile * pModelFile, + std::vector & apRepItem, + std::vector & asIdentifiers) +{ + A3DAsmModelFileData sMFData; + A3D_INITIALIZE_DATA(A3DAsmModelFileData, sMFData); + A3DAsmModelFileGet(pModelFile, &sMFData); + double dUnitInMm = sMFData.m_dUnit; + A3DAsmModelFileGet(NULL, &sMFData); + + A3DVisitorContainer sA3DVisitorContainer(CONNECT_TRANSFO); + sA3DVisitorContainer.SetTraverseInstance(true); + + A3DVisitorColorMaterials *pA3DCascadedVisitor = new A3DVisitorColorMaterials(&sA3DVisitorContainer); + sA3DVisitorContainer.push(pA3DCascadedVisitor); + + A3DFlattenVisitor *pA3DFlattenVisitor = new A3DFlattenVisitor(&sA3DVisitorContainer); + sA3DVisitorContainer.push(pA3DFlattenVisitor); + pA3DFlattenVisitor->m_dScaleToMm = dUnitInMm; + + A3DModelFileConnector sModelFileConnector(pModelFile); + A3DStatus sStatus = sModelFileConnector.Traverse(&sA3DVisitorContainer); + if (sStatus != A3D_SUCCESS) + return A3D_ERROR; + + size_t uiRI, uiNbRepItem = pA3DFlattenVisitor->m_vA3DRiBrepModel.size(); + if (uiNbRepItem == 0) + return A3D_MODELFILE_INCONSISTENT_EMPTY; + + apRepItem.resize(uiNbRepItem); + asIdentifiers.resize(uiNbRepItem); + for (uiRI = 0; uiRI < uiNbRepItem; uiRI++) + { + A3DTransfoRepresentationItemData & sTransfRI = apRepItem[uiRI]; + A3D_INITIALIZE_DATA(A3DTransfoRepresentationItemData, sTransfRI); + + sTransfRI.m_pRepItem = pA3DFlattenVisitor->m_vA3DRiBrepModel[uiRI]; + + sTransfRI.m_pOptPlacement = new double[16]; + memcpy( const_cast(sTransfRI.m_pOptPlacement), pA3DFlattenVisitor->m_vA3DMatrix4x4[uiRI].m_adM, 16 * sizeof(double)); + + if (A3DUTF8Char* psId = pA3DFlattenVisitor->m_vProductIdentifier[uiRI]) + { + std::basic_ostringstream stream; + stream << psId; + asIdentifiers[uiRI] = stream.str(); + } + } + + return A3D_SUCCESS; +} + +void PrintUsage() +{ + std::cout << "Usage:" << std::endl + << "Collision [INPUT] [OUTPUT] [UUIDs...]" << std::endl + << "\tINPUT The input CAD file. Default is '" << SAMPLE_DEFAULT_CAD_FILE << "'" << std::endl + << "\tOUTPUT The output result file. Default is 'CURRENT_DIR/Collision.txt'" << std::endl + << "\tUUID1 UUID2... Any number of space separated UUIDs of representation items to be checked to each other. If not set, two relevant UUIDs from the CAD file will be picked" << std::endl; +} + +//###################################################################################################################### +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + PrintUsage(); + + // INITIALIZE HOOPS EXCHANGE + A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); + CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus); + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + // Parsing arguments + string_t acInputCADFile = SAMPLE_DEFAULT_CAD_FILE; + string_t acResultFile = SAMPLE_DEFAULT_RESULT_FILE; + std::vector asInputUUID; + + // Default Input CAD overridden by first argument + if (iArgc > 1) + { + acInputCADFile = ppcArgv[1]; + } + + // Default result file overridden by second argument + if (iArgc > 2) + { + acResultFile = ppcArgv[2]; + } + + // Get all UUIDs + for (A3DInt32 i = 3; i < iArgc; ++i) + { + asInputUUID.emplace_back(ppcArgv[i]); + } + + //##################################### + // ### Import input XML file + //##################################### + A3DImport sImport(acInputCADFile.c_str()); + + A3DStatus iRet = A3D_ERROR; + const size_t uiSize = acInputCADFile.size(); + if (uiSize >= 4) + { + const string_t sExtension = acInputCADFile.substr(uiSize - 4, 4); +#ifdef _MSC_VER + if (sExtension == _T(".xml") || sExtension == _T(".XML") || sExtension == _T(".Xml")) + { + std::wstring_convert> converter; + const std::string aScrFileNameUTF8 = converter.to_bytes(acInputCADFile); + iRet = A3DAsmModelFileLoadFromXMLFile(aScrFileNameUTF8.c_str(), &sImport.m_sLoadData, &sHoopsExchangeLoader.m_psModelFile); + } +#else + if (sExtension == ".xml" || sExtension == ".XML" || sExtension == ".Xml") + iRet = A3DAsmModelFileLoadFromXMLFile(acInputCADFile.c_str(), &sImport.m_sLoadData, &sHoopsExchangeLoader.m_psModelFile); +#endif + else + iRet = sHoopsExchangeLoader.Import(sImport); + } + else + iRet = sHoopsExchangeLoader.Import(sImport); + + if (iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS) + CHECK_RET(iRet); + + //##################################### + // ### Flatten Representation Items + //##################################### + std::vector apRepItem; + std::vector asIdentifier; + iRet = stGetFlattenRepItemInMmFromModelFile(sHoopsExchangeLoader.m_psModelFile, apRepItem, asIdentifier); + CHECK_RET(iRet); + + //##################################### + // ### Some Checks + //##################################### + if (apRepItem.size() < 2) + { + std::cout << "Collision sample needs at least 2 representation items in the model file to process." << std::endl; + return A3D_ERROR; + } + assert(apRepItem.size() == asIdentifier.size()); + + // If no UUID given by the user, take the first available + if (asInputUUID.empty()) + { + asInputUUID.push_back(asIdentifier.front()); + } + + ////##################################### + //// ### Build collision group + ////##################################### + std::vector asGroup1, asGroup2; + std::vector auiGroupIndex1, auiGroupIndex2; + for (size_t iIndex = 0; iIndex < apRepItem.size(); iIndex++) + { + bool bInSecondGroup = true; + string_t const & sCurID = asIdentifier[iIndex]; + for (auto const & sInputID : asInputUUID) + { + if (sCurID.compare(sInputID) == 0) + { + asGroup1.push_back(apRepItem[iIndex]); + auiGroupIndex1.push_back(iIndex); + bInSecondGroup = false; + break; + } + } + if (bInSecondGroup) + { + asGroup2.push_back(apRepItem[iIndex]); + auiGroupIndex2.push_back(iIndex); + } + } + + // fill first group structure + A3DCollisionGroupData sGroup1; + A3D_INITIALIZE_DATA(A3DCollisionGroupData, sGroup1); + sGroup1.m_uRepItemSize = (A3DUns32)asGroup1.size(); + if (sGroup1.m_uRepItemSize) + sGroup1.m_apRepItems = &asGroup1[0]; + else + { + printf("Invalid first group\n"); + return -1; + } + + // fill second group structure + A3DCollisionGroupData sGroup2; + A3D_INITIALIZE_DATA(A3DCollisionGroupData, sGroup2); + sGroup2.m_uRepItemSize = (A3DUns32)asGroup2.size(); + if (sGroup2.m_uRepItemSize) + sGroup2.m_apRepItems = &asGroup2[0]; + + + //##################################### + // ### Specify collision parameters + //##################################### + + A3DCollisionParameterData sCollisionParameter; + A3D_INITIALIZE_DATA(A3DCollisionParameterData, sCollisionParameter); + sCollisionParameter.m_dContactLimit = 0.1; + sCollisionParameter.m_dSafetyDistance = 1.; + sCollisionParameter.m_dTessellationTolerance = 0.01; + + //##################################### + // ### Compute + //##################################### + + A3DUns32 uCollisionResultsSize = 0; + A3DCollisionResultData * apCollisionResults = nullptr; + iRet = A3DCollisionCompute(&sGroup1, sGroup2.m_uRepItemSize?&sGroup2:nullptr, + &sCollisionParameter, + &uCollisionResultsSize, &apCollisionResults); + CHECK_RET(iRet); + + std::basic_ofstream sOutput; + sOutput.open(acResultFile); + if (sOutput.is_open()) + { + for (A3DUns32 uiRes = 0; uiRes < uCollisionResultsSize; uiRes++) + { + A3DCollisionResultData const & sCurResult = apCollisionResults[uiRes]; + + size_t iGlobalIndex1 = auiGroupIndex1[sCurResult.m_iRepItemIndex1]; + size_t iGlobalIndex2 = (sGroup2.m_uRepItemSize != 0) ? auiGroupIndex2[sCurResult.m_iRepItemIndex2] : auiGroupIndex1[sCurResult.m_iRepItemIndex2]; + + sOutput << "Check " << asIdentifier[iGlobalIndex1] << " with " << asIdentifier[iGlobalIndex2] << " : "; + + switch (sCurResult.m_eStatus) + { + case A3DCollision_Unknown: sOutput << "Unknown"; break; + case A3DCollision_NoCollision: sOutput << "No Collision"; break; + case A3DCollision_Clearance: sOutput << "Clearance"; break; + case A3DCollision_Contact: sOutput << "Contact"; break; + case A3DCollision_Collision: sOutput << "Collision"; break; + case A3DCollision_FirstInside: sOutput << "First is Inside"; break; + case A3DCollision_SecondInside: sOutput << "Second is Inside"; break; + } + + sOutput << std::endl; + } + + sOutput.close(); + } + + // Free memory + iRet = A3DCollisionCompute(nullptr, nullptr, nullptr, &uCollisionResultsSize, &apCollisionResults); + CHECK_RET(iRet); + + for (auto & sTransfoRep : apRepItem) + { + delete [] sTransfoRep.m_pOptPlacement; + } + + // Check memory allocations + return (int)ListLeaks(); +} + diff --git a/exchange/exchangesource/Collision/Collision.vcxproj b/exchange/exchangesource/Collision/Collision.vcxproj new file mode 100644 index 0000000..ae59062 --- /dev/null +++ b/exchange/exchangesource/Collision/Collision.vcxproj @@ -0,0 +1,199 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {EC2593D7-2AB1-4EFC-B412-9C5A70939DF9} + Collisision + Win32Proj + 10.0 + + + + Application + v145 + true + + + Application + v145 + + + Application + v145 + true + + + Application + v145 + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + true + Console + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + true + Console + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + MaxSpeed + true + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + Level4 + ProgramDatabase + false + + + true + Console + true + true + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + MaxSpeed + true + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + Level4 + ProgramDatabase + false + + + true + Console + true + true + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/Collision/Collision.vcxproj.filters b/exchange/exchangesource/Collision/Collision.vcxproj.filters new file mode 100644 index 0000000..bd7d379 --- /dev/null +++ b/exchange/exchangesource/Collision/Collision.vcxproj.filters @@ -0,0 +1,126 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + {7d804a86-38ae-4203-91de-03178fd72c1b} + + + {9fc7e631-8e85-48c8-bf89-40c346f0dc9d} + + + + + Source Files\Visitor + + + Source Files\Visitor + + + Source Files\Visitor + + + Source Files\Visitor + + + Source Files\Visitor + + + Source Files\Visitor + + + Source Files\Visitor + + + Source Files\Visitor + + + Source Files\Visitor + + + Source Files\Visitor + + + Source Files\Visitor + + + Source Files\Visitor + + + Source Files\Visitor + + + Source Files\Visitor + + + Source Files + + + Source Files + + + + + Header Files\Visitors Headers + + + Header Files\Visitors Headers + + + Header Files\Visitors Headers + + + Header Files\Visitors Headers + + + Header Files\Visitors Headers + + + Header Files\Visitors Headers + + + Header Files\Visitors Headers + + + Header Files\Visitors Headers + + + Header Files\Visitors Headers + + + Header Files\Visitors Headers + + + Header Files\Visitors Headers + + + Header Files\Visitors Headers + + + Header Files\Visitors Headers + + + Header Files\Visitors Headers + + + Header Files\Visitors Headers + + + Header Files\Visitors Headers + + + Header Files\Visitors Headers + + + \ No newline at end of file diff --git a/exchange/exchangesource/Collision/createtessellatedbox.cpp b/exchange/exchangesource/Collision/createtessellatedbox.cpp new file mode 100644 index 0000000..1ebde31 --- /dev/null +++ b/exchange/exchangesource/Collision/createtessellatedbox.cpp @@ -0,0 +1,175 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file createtessellatedbox.cpp + +This file demonstrates how to create a simple A3DPolyBrepModel with triangle only from a A3DBoundingBoxData. +It's based on the CreatePRCCubes samples + +***********************************************************************************************************************/ +#include +#include "../common.hpp" + +static A3DDouble stCubeNormals[18] = { + 1., 0., 0., + -1., 0., 0., + 0., 1., 0., + 0., -1., 0., + 0., 0., 1., + 0., 0., -1. +}; + +static A3DUns32 stCubeFacesNormalPTriangles[48] = +{ +// N, P, P, P, N, P, P, P + 12, 0, 3, 6, 12, 6, 3, 9, // Face 0 + 6, 6, 9, 12, 6, 12, 9, 15, // Face 1 + 15, 12, 15, 18, 15, 18, 15, 21, // Face 2 + 9, 18, 21, 0, 9, 0, 21, 3, // Face 3 + 0, 3, 21, 9, 0, 9, 21, 15, // Face 4 + 3, 18, 0, 12, 3, 12, 0, 6, // Face 5 +}; + +//##################################################################################################################### +static void freeTess3DData(A3DTess3DData& sTess3DData) +{ + free(sTess3DData.m_pdNormals); + free(sTess3DData.m_puiTriangulatedIndexes); + for (A3DUns32 ui = 0; ui < sTess3DData.m_uiFaceTessSize; ++ui) + { + free(sTess3DData.m_psFaceTessData[ui].m_puiSizesTriangulated); + } + free(sTess3DData.m_psFaceTessData); + +} + +//##################################################################################################################### +// Create a A3DTess3D from a A3DBoundingBoxData with only triangles +static A3DStatus CreateA3DTess3DFromABBox(A3DBoundingBoxData const & sABBox, A3DTess3D ** ppTess3D) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DTess3DData sTess3DData; + A3D_INITIALIZE_DATA(A3DTess3DData, sTess3DData); + + // Normal coordinates + sTess3DData.m_uiNormalSize = 18; + sTess3DData.m_pdNormals = static_cast(malloc((size_t)sTess3DData.m_uiNormalSize * sizeof(A3DDouble))); + for (A3DUns32 ui = 0; ui < sTess3DData.m_uiNormalSize; ++ui) + sTess3DData.m_pdNormals[ui] = stCubeNormals[ui]; + + sTess3DData.m_uiTriangulatedIndexSize = 8 * 6; + sTess3DData.m_puiTriangulatedIndexes = (A3DUns32*)malloc((size_t)sTess3DData.m_uiTriangulatedIndexSize * sizeof(A3DUns32)); + for (A3DUns32 ui = 0; ui < sTess3DData.m_uiTriangulatedIndexSize; ++ui) + { + sTess3DData.m_puiTriangulatedIndexes[ui] = stCubeFacesNormalPTriangles[ui]; + } + + // Faces + sTess3DData.m_bHasFaces = true; + sTess3DData.m_uiFaceTessSize = 6; + sTess3DData.m_psFaceTessData = static_cast(malloc((size_t)sTess3DData.m_uiFaceTessSize * sizeof(A3DTessFaceData))); + for (A3DUns32 ui = 0; ui < sTess3DData.m_uiFaceTessSize; ++ui) + { + A3DTessFaceData& sFace = sTess3DData.m_psFaceTessData[ui]; + A3D_INITIALIZE_DATA(A3DTessFaceData, sFace); + + sFace.m_usUsedEntitiesFlags = kA3DTessFaceDataTriangleOneNormal; + sFace.m_uiStartTriangulated = ui * 8; + + sFace.m_uiSizesTriangulatedSize = 1; // size of the next array + sFace.m_puiSizesTriangulated = (A3DUns32*)malloc(sFace.m_uiSizesTriangulatedSize * A3DUns32(sizeof(A3DUns32))); + sFace.m_puiSizesTriangulated[0] = 2; // number of triangles for this face + } + + iRet = A3DTess3DCreate(&sTess3DData, ppTess3D); + freeTess3DData(sTess3DData); + CHECK_RET(iRet); + + A3DTessBaseData sTessBaseData; + A3D_INITIALIZE_DATA(A3DTessBaseData, sTessBaseData); + + sTessBaseData.m_bIsCalculated = false; + + // Point coordinates + sTessBaseData.m_uiCoordSize = 8 * 3; + sTessBaseData.m_pdCoords = static_cast(malloc((size_t)sTessBaseData.m_uiCoordSize * sizeof(A3DDouble))); + + sTessBaseData.m_pdCoords[0] = sABBox.m_sMin.m_dX; + sTessBaseData.m_pdCoords[1] = sABBox.m_sMin.m_dY; + sTessBaseData.m_pdCoords[2] = sABBox.m_sMax.m_dZ; + + sTessBaseData.m_pdCoords[3] = sABBox.m_sMax.m_dX; + sTessBaseData.m_pdCoords[4] = sABBox.m_sMin.m_dY; + sTessBaseData.m_pdCoords[5] = sABBox.m_sMax.m_dZ; + + sTessBaseData.m_pdCoords[6] = sABBox.m_sMin.m_dX; + sTessBaseData.m_pdCoords[7] = sABBox.m_sMax.m_dY; + sTessBaseData.m_pdCoords[8] = sABBox.m_sMax.m_dZ; + + sTessBaseData.m_pdCoords[9] = sABBox.m_sMax.m_dX; + sTessBaseData.m_pdCoords[10] = sABBox.m_sMax.m_dY; + sTessBaseData.m_pdCoords[11] = sABBox.m_sMax.m_dZ; + + sTessBaseData.m_pdCoords[12] = sABBox.m_sMin.m_dX; + sTessBaseData.m_pdCoords[13] = sABBox.m_sMax.m_dY; + sTessBaseData.m_pdCoords[14] = sABBox.m_sMin.m_dZ; + + + sTessBaseData.m_pdCoords[15] = sABBox.m_sMax.m_dX; + sTessBaseData.m_pdCoords[16] = sABBox.m_sMax.m_dY; + sTessBaseData.m_pdCoords[17] = sABBox.m_sMin.m_dZ; + + sTessBaseData.m_pdCoords[18] = sABBox.m_sMin.m_dX; + sTessBaseData.m_pdCoords[19] = sABBox.m_sMin.m_dY; + sTessBaseData.m_pdCoords[20] = sABBox.m_sMin.m_dZ; + + sTessBaseData.m_pdCoords[21] = sABBox.m_sMax.m_dX; + sTessBaseData.m_pdCoords[22] = sABBox.m_sMin.m_dY; + sTessBaseData.m_pdCoords[23] = sABBox.m_sMin.m_dZ; + + iRet = A3DTessBaseSet(*ppTess3D, &sTessBaseData); + free(sTessBaseData.m_pdCoords); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus createPolyBrepModelFromA3DTess3D(A3DRiPolyBrepModel** ppPolyBREP, A3DTess3D* pTess3D) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DRiPolyBrepModelData sPolyBrepModelData; + A3D_INITIALIZE_DATA(A3DRiPolyBrepModelData, sPolyBrepModelData); + sPolyBrepModelData.m_bIsClosed = TRUE; + CHECK_RET(A3DRiPolyBrepModelCreate(&sPolyBrepModelData, ppPolyBREP)); + + // assign the cube tessellation to the PolyBrepModel + A3DRiRepresentationItemData sRiData; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, sRiData); + sRiData.m_pTessBase = pTess3D; + sRiData.m_pCoordinateSystem = NULL; + CHECK_RET(A3DRiRepresentationItemSet(*ppPolyBREP, &sRiData)); + + return iRet; +} + +//##################################################################################################################### +// Create a A3DRiPolyBrepModel from a A3DBoundingBoxData with only triangles +A3DStatus CreatePolyBrepModelFromABBox(A3DBoundingBoxData const & sABBox, A3DRiPolyBrepModel ** pRiPolyBrepModel) +{ + A3DTess3D * pTess3D = nullptr; + CHECK_RET(CreateA3DTess3DFromABBox(sABBox, &pTess3D)); + + CHECK_RET(createPolyBrepModelFromA3DTess3D(pRiPolyBrepModel, pTess3D)); + + return A3D_SUCCESS; +} diff --git a/exchange/exchangesource/Collision/visitor/A3DVector.h b/exchange/exchangesource/Collision/visitor/A3DVector.h new file mode 100644 index 0000000..64028f8 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/A3DVector.h @@ -0,0 +1,121 @@ +#ifndef A3DVECTOR_H +#define A3DVECTOR_H + +#include +#include +#include +#include +#include +#include +#include + +class A3DVector3d +{ +public: + double x; + double y; + double z; + + A3DVector3d() {} + A3DVector3d(double dX, double dY, double dZ) : x(dX), y(dY), z(dZ) {} + A3DVector3d(const A3DVector3dData& sV) : x(sV.m_dX), y(sV.m_dY), z(sV.m_dZ) {} + inline void set(double dX, double dY, double dZ) + { x = dX; y = dY; z = dZ; } + + A3DVector3d(const A3DVector3d& toCopy) : x(toCopy.x), y(toCopy.y), z(toCopy.z) {} + + inline double Length() const { return sqrt(x*x + y*y + z*z); } + + inline double LenghtSquared() const{ return x*x + y*y + z*z; } + + inline A3DStatus normalize() + { + double d = this->Length(); + if(d == 0) + return A3D_ERROR; + x/=d; + y/=d; + z/=d; + return A3D_SUCCESS; + } + + inline double Distance(const A3DVector3d& sOther) const + { + return sqrt(this->SquareDistance(sOther)); + } + + inline double SquareDistance(const A3DVector3d& sOther) const + { + double d=0,dd; + dd = x; dd -= sOther.x; dd *= dd; d += dd; + dd = y; dd -= sOther.y; dd *= dd; d += dd; + dd = z; dd -= sOther.z; dd *= dd; d += dd; + return d; + } + + inline double Dot(const A3DVector3d& sOther) const + { + return x*sOther.x + y*sOther.y + z*sOther.z; + } + + inline A3DVector3d Cross(const A3DVector3d& sOther) + { + return A3DVector3d(y*sOther.z - z*sOther.y, z*sOther.x - x*sOther.z, x*sOther.y - y*sOther.x); + } + + + // in-place vector algebra + inline A3DVector3d& operator += ( const A3DVector3d& sOther ) + { + x+=sOther.x; + y+=sOther.y; + z+=sOther.z; + return *this; + } + + inline A3DVector3d& operator -= ( const A3DVector3d& sOther ) + { + x-=sOther.x; + y-=sOther.y; + z-=sOther.z; + return *this; + } + + inline A3DVector3d operator + ( const A3DVector3d& sOther ) const + { + return A3DVector3d(x+sOther.x, y+sOther.y, z+sOther.z); + } + + inline A3DVector3d operator - ( const A3DVector3d& sOther ) const + { + return A3DVector3d(x-sOther.x, y-sOther.y, z-sOther.z); + } + + inline A3DVector3d& operator *= ( double dValue ) + { + x*=dValue; + y*=dValue; + z*=dValue; + return *this; + } + + inline A3DVector3d& operator /= ( double dValue ) + { + x/=dValue; + y/=dValue; + z/=dValue; + return *this; + } + + inline A3DVector3d operator * ( double dValue ) const + { + return A3DVector3d(x*dValue, y*dValue, z*dValue); + } + + inline A3DVector3d operator / ( double dValue ) const + { + return A3DVector3d(x/dValue, y/dValue, z/dValue); + } +}; + +#endif diff --git a/exchange/exchangesource/Collision/visitor/BrepTraverse.cpp b/exchange/exchangesource/Collision/visitor/BrepTraverse.cpp new file mode 100644 index 0000000..4ddb05e --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/BrepTraverse.cpp @@ -0,0 +1,312 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file BrepTraverse.cpp +This file demonstrates how to programmatically traverse the Brep structure + +***********************************************************************************************************************/ + +#include "VisitorContainer.h" +#include "BrepTraverse.h" +#include + + +////////////////////////////////////////////////////////////////////////////// +// Traverse Brep +////////////////////////////////////////////////////////////////////////////// + +A3DBrepDataConnector::A3DBrepDataConnector(const A3DTopoBrepData *pBrep) : A3DConnector(pBrep) +{ + A3D_INITIALIZE_DATA(A3DTopoBrepDataData, m_sBrepData); + A3DTopoBrepDataGet(pBrep, &m_sBrepData); +} + +A3DBrepDataConnector::~A3DBrepDataConnector() +{ + A3DTopoBrepDataGet(NULL, &m_sBrepData); +} + +A3DStatus A3DBrepDataConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + + //TopoContext + A3DTopoBody *psTopoBody = (A3DTopoBody*) GetA3DEntity(); + A3DTopoBodyData sA3DTopoBodyData; + A3D_INITIALIZE_DATA( A3DTopoBodyData, sA3DTopoBodyData); + CHECK_RET(A3DTopoBodyGet(psTopoBody, &sA3DTopoBodyData)); + A3DTopoContext* psContext = sA3DTopoBodyData.m_pContext; + + A3DTopoContextData sA3DTopoContextData; + A3D_INITIALIZE_DATA( A3DTopoContextData, sA3DTopoContextData); + CHECK_RET(A3DTopoContextGet(psContext, &sA3DTopoContextData)); + //m_dScale = sA3DTopoContextData.m_dScale; + + CHECK_RET(psVisitor->visitEnter(*this)); + A3DUns32 uNbConnex = m_sBrepData.m_uiConnexSize; + for(A3DUns32 uI = 0; uI < uNbConnex; uI++) + { + A3DConnexConnector sConnecConnector(m_sBrepData.m_ppConnexes[uI]); + CHECK_RET(sConnecConnector.Traverse(psVisitor)); + } + + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////// +// Connex +////////////////////////////////////////////////////////////////////////////// + +A3DConnexConnector::A3DConnexConnector(const A3DTopoConnex *pConnex) : A3DConnector(pConnex) +{ + A3D_INITIALIZE_DATA(A3DTopoConnexData, m_sConnexData); + A3DTopoConnexGet(pConnex, &m_sConnexData); +} + +A3DConnexConnector::~A3DConnexConnector() +{ + A3DTopoConnexGet(NULL, &m_sConnexData); +} + +A3DStatus A3DConnexConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned uI, uNbShell = m_sConnexData.m_uiShellSize; + for(uI = 0; uI < uNbShell; uI++) + { + A3DShellConnector sShellConnector(m_sConnexData.m_ppShells[uI]); + CHECK_RET(sShellConnector.Traverse(psVisitor)); + } + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////// +// Shell +////////////////////////////////////////////////////////////////////////////// + +A3DShellConnector::A3DShellConnector(const A3DTopoShell *pShell) : A3DConnector(pShell) +{ + A3D_INITIALIZE_DATA(A3DTopoShellData, m_sShellData); + A3DTopoShellGet(pShell, &m_sShellData); +} + +A3DShellConnector::~A3DShellConnector() +{ + A3DTopoShellGet(NULL, &m_sShellData); +} + +A3DStatus A3DShellConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned int uI, uFaceSize = m_sShellData.m_uiFaceSize; + for(uI = 0; uI < uFaceSize; uI++) + { + A3DFaceConnector sFaceConnector(m_sShellData.m_ppFaces[uI]); + CHECK_RET(sFaceConnector.Traverse(psVisitor)); + } + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////// +// Face +////////////////////////////////////////////////////////////////////////////// + +A3DFaceConnector::A3DFaceConnector(const A3DTopoFace* pFace) : A3DConnector(pFace) +{ + A3D_INITIALIZE_DATA(A3DTopoFaceData, m_sFaceData); + A3DTopoFaceGet(pFace, &m_sFaceData); +} + +A3DFaceConnector::~A3DFaceConnector() +{ + A3DTopoFaceGet(NULL, &m_sFaceData); +} + +A3DStatus A3DFaceConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned int uI, uLoopSize = m_sFaceData.m_uiLoopSize; + for(uI = 0; uI < uLoopSize; uI++) + { + A3DLoopConnector sLoopConnector(m_sFaceData.m_ppLoops[uI]); + CHECK_RET(sLoopConnector.Traverse(psVisitor)); + } + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////// +// Loop +////////////////////////////////////////////////////////////////////////////// + +A3DLoopConnector::A3DLoopConnector(const A3DTopoLoop *pLoop) : A3DConnector(pLoop) +{ + A3D_INITIALIZE_DATA(A3DTopoLoopData, m_sLoopData); + A3DTopoLoopGet(pLoop, &m_sLoopData); +} + +A3DLoopConnector::~A3DLoopConnector() +{ + A3DTopoLoopGet(NULL, &m_sLoopData); +} + +A3DStatus A3DLoopConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + unsigned uI, uCoEdgeSize = m_sLoopData.m_uiCoEdgeSize; + for(uI = 0; uI < uCoEdgeSize; uI++) + { + A3DCoEdgeConnector sCoEdgeConnector(m_sLoopData.m_ppCoEdges[uI]); + CHECK_RET(sCoEdgeConnector.Traverse(psVisitor)); + } + + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////// +// CoEdge +////////////////////////////////////////////////////////////////////////////// + +A3DCoEdgeConnector::A3DCoEdgeConnector(const A3DTopoCoEdge *pCoEdge) : A3DConnector(pCoEdge) +{ + A3D_INITIALIZE_DATA(A3DTopoCoEdgeData, m_sCoEdgeData); + A3DTopoCoEdgeGet(pCoEdge, &m_sCoEdgeData); +} + +A3DCoEdgeConnector::~A3DCoEdgeConnector() +{ + A3DTopoCoEdgeGet(NULL, &m_sCoEdgeData); +} + +A3DStatus A3DCoEdgeConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + if(!(psVisitor->FindInMap(m_sCoEdgeData.m_pEdge))) + { + psVisitor->SetInMap(m_sCoEdgeData.m_pEdge,(void*) this->GetA3DEntity()); + A3DEdgeConnector sEdgeConnector(m_sCoEdgeData.m_pEdge); + CHECK_RET(sEdgeConnector.Traverse(psVisitor)); + } + CHECK_RET(psVisitor->visitLeave(*this)); + + return A3D_SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////// +// Edge +////////////////////////////////////////////////////////////////////////////// + +A3DEdgeConnector::A3DEdgeConnector(const A3DTopoEdge *pEdge) + : A3DConnector(pEdge) +{ + A3D_INITIALIZE_DATA(A3DTopoEdgeData, m_sEdgeData); + A3DTopoEdgeGet(pEdge, &m_sEdgeData); +} + +A3DEdgeConnector::~A3DEdgeConnector() +{ + A3DTopoEdgeGet(NULL, &m_sEdgeData); +} + +A3DStatus A3DEdgeConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + A3DEEntityType eType; + //Start Vertex + if(m_sEdgeData.m_pStartVertex != NULL) + { + CHECK_RET(A3DEntityGetType(m_sEdgeData.m_pStartVertex,&eType)); + if(eType == kA3DTypeTopoMultipleVertex) + { + A3DMultipleVertexConnector sStart(m_sEdgeData.m_pStartVertex); + sStart.Traverse(psVisitor); + } + else if(eType == kA3DTypeTopoUniqueVertex) + { + A3DUniqueVertexConnector sStart(m_sEdgeData.m_pStartVertex); + sStart.Traverse(psVisitor); + } + } + + //End Vertex + if(m_sEdgeData.m_pEndVertex != NULL) + { + CHECK_RET(A3DEntityGetType(m_sEdgeData.m_pEndVertex,&eType)); + if(eType == kA3DTypeTopoMultipleVertex) + { + A3DMultipleVertexConnector sStart(m_sEdgeData.m_pEndVertex); + sStart.Traverse(psVisitor); + } + else if(eType == kA3DTypeTopoUniqueVertex) + { + A3DUniqueVertexConnector sStart(m_sEdgeData.m_pEndVertex); + sStart.Traverse(psVisitor); + } + } + + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////// +// Vertex +////////////////////////////////////////////////////////////////////////////// + +A3DUniqueVertexConnector::A3DUniqueVertexConnector(const A3DTopoVertex *pVertex) + : A3DConnector(pVertex) +{ + A3D_INITIALIZE_DATA(A3DTopoUniqueVertexData, m_sVertexData); + A3DTopoUniqueVertexGet(pVertex, &m_sVertexData); +} + +A3DUniqueVertexConnector::~A3DUniqueVertexConnector() +{ + A3DTopoUniqueVertexGet(NULL, &m_sVertexData); +} + +A3DStatus A3DUniqueVertexConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + return A3D_SUCCESS; +} + + +A3DMultipleVertexConnector::A3DMultipleVertexConnector(const A3DTopoVertex *pVertex) : A3DConnector(pVertex) +{ + A3D_INITIALIZE_DATA(A3DTopoMultipleVertexData, m_sVertexData); + A3DTopoMultipleVertexGet(pVertex, &m_sVertexData); +} + +A3DMultipleVertexConnector::~A3DMultipleVertexConnector() +{ + A3DTopoMultipleVertexGet(NULL, &m_sVertexData); +} + +A3DStatus A3DMultipleVertexConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + return A3D_SUCCESS; +} diff --git a/exchange/exchangesource/Collision/visitor/BrepTraverse.h b/exchange/exchangesource/Collision/visitor/BrepTraverse.h new file mode 100644 index 0000000..41d52b7 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/BrepTraverse.h @@ -0,0 +1,146 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef TOPO_TRAVERSE +#define TOPO_TRAVERSE + +#include "Connector.h" + +class A3DVisitor; + +//////////////////////////////////////////////// +// Brep +//////////////////////////////////////////////// +class A3DBrepDataConnector : public A3DConnector +{ +public: + + A3DTopoBrepDataData m_sBrepData; + + A3DBrepDataConnector(const A3DTopoBrepData *pBrep); + ~A3DBrepDataConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + +//////////////////////////////////////////////// +// connex +//////////////////////////////////////////////// +class A3DConnexConnector : public A3DConnector +{ +public: + A3DTopoConnexData m_sConnexData; + + A3DConnexConnector(const A3DTopoConnex *pConnex); + ~A3DConnexConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + +//////////////////////////////////////////////// +// Shell +//////////////////////////////////////////////// +class A3DShellConnector : public A3DConnector +{ +public: + A3DTopoShellData m_sShellData; + + A3DShellConnector(const A3DTopoShell *pShell); + ~A3DShellConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + +//////////////////////////////////////////////// +// Face +//////////////////////////////////////////////// +class A3DFaceConnector : public A3DConnector +{ +public: + A3DTopoFaceData m_sFaceData; + + A3DFaceConnector(const A3DTopoFace *pFace); + ~A3DFaceConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + +//////////////////////////////////////////////// +// Loop +//////////////////////////////////////////////// +class A3DLoopConnector : public A3DConnector +{ +public: + A3DTopoLoopData m_sLoopData; + + A3DLoopConnector(const A3DTopoLoop *pLoop); + ~A3DLoopConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + +//////////////////////////////////////////////// +// CoEdge +//////////////////////////////////////////////// +class A3DCoEdgeConnector : public A3DConnector +{ +public: + A3DTopoCoEdgeData m_sCoEdgeData; + + A3DCoEdgeConnector(const A3DTopoCoEdge *pCoEdge); + ~A3DCoEdgeConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + +//////////////////////////////////////////////// +// Edge +//////////////////////////////////////////////// +class A3DEdgeConnector : public A3DConnector +{ +public: + A3DTopoEdgeData m_sEdgeData; + + A3DEdgeConnector(const A3DTopoEdge *pEdge); + ~A3DEdgeConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + +//////////////////////////////////////////////// +// Vertex +//////////////////////////////////////////////// +class A3DUniqueVertexConnector : public A3DConnector +{ +public: + + A3DTopoUniqueVertexData m_sVertexData; + + A3DUniqueVertexConnector(const A3DTopoVertex *pVertex); + ~A3DUniqueVertexConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + + +class A3DMultipleVertexConnector : public A3DConnector +{ +public: + A3DTopoMultipleVertexData m_sVertexData; + + A3DMultipleVertexConnector(const A3DTopoVertex *pVertex); + ~A3DMultipleVertexConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + + +#endif \ No newline at end of file diff --git a/exchange/exchangesource/Collision/visitor/CascadedAttributeConnector.cpp b/exchange/exchangesource/Collision/visitor/CascadedAttributeConnector.cpp new file mode 100644 index 0000000..6f061e2 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/CascadedAttributeConnector.cpp @@ -0,0 +1,213 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "CascadedAttributeConnector.h" +#include "Visitors.h" + +ColorMaterialsConnector::ColorMaterialsConnector(A3DMiscCascadedAttributes* pAttr) : A3DConnector(pAttr) +{ + A3D_INITIALIZE_DATA(A3DMiscCascadedAttributesData, m_sCascadedAttributeData); + A3DMiscCascadedAttributesGet(pAttr, &(m_sCascadedAttributeData)); +} + +ColorMaterialsConnector::~ColorMaterialsConnector() +{ + A3DMiscCascadedAttributesGet(NULL, &(m_sCascadedAttributeData)); +} + + +bool ColorMaterialsConnector::IsShow() +{ + return m_sCascadedAttributeData.m_bShow ? true : false; +} + +bool ColorMaterialsConnector::IsRemoved() +{ + return m_sCascadedAttributeData.m_bRemoved ? true : false; +} + +bool ColorMaterialsConnector::IsMaterial() +{ + //Todo Test it's not a texture + return m_sCascadedAttributeData.m_sStyle.m_bMaterial ? true : false; +} + +bool ColorMaterialsConnector::IsRGBColor() +{ + return !(IsMaterial()); +} + +bool ColorMaterialsConnector::IsTranparent() +{ + return m_sCascadedAttributeData.m_sStyle.m_bIsTransparencyDefined ? true : false; +} + +A3DStatus ColorMaterialsConnector::GetRGB(double adRGB[3])//, char& cInheritance = 0) +{ + A3DStatus iRet = A3D_SUCCESS; + A3DGraphRgbColorData sA3DGraphRgbColorData; + A3D_INITIALIZE_DATA(A3DGraphRgbColorData, sA3DGraphRgbColorData); + if(A3DGlobalGetGraphRgbColorData(m_sCascadedAttributeData.m_sStyle.m_uiRgbColorIndex, &sA3DGraphRgbColorData) == A3D_DEFAULT_COLOR) + { + adRGB[0] = 192.0 / 255.0; + adRGB[1] = 192.0 / 255.0; + adRGB[2] = 192.0 / 255.0; + } + else + { + CHECK_RET(iRet); + adRGB[0] = sA3DGraphRgbColorData.m_dRed; + adRGB[1] = sA3DGraphRgbColorData.m_dGreen; + adRGB[2] = sA3DGraphRgbColorData.m_dBlue; + } + + return A3D_SUCCESS; +} + +A3DStatus ColorMaterialsConnector::Transparency(unsigned char& cTransparenty) +{ + cTransparenty = m_sCascadedAttributeData.m_sStyle.m_ucTransparency; + return A3D_SUCCESS; +} + +A3DStatus ColorMaterialsConnector::Compare( + ColorMaterialsConnector const & sOtherCascadedAttribute, + bool& bSameDispalyParameter, + bool& bSamebSameDispalyParameterOnFace) +{ + if( + sOtherCascadedAttribute.m_sCascadedAttributeData.m_bShow != m_sCascadedAttributeData.m_bShow + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_bRemoved != m_sCascadedAttributeData.m_bRemoved + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_usLayer != m_sCascadedAttributeData.m_usLayer + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_dWidth != m_sCascadedAttributeData.m_sStyle.m_dWidth + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_bVPicture != m_sCascadedAttributeData.m_sStyle.m_bVPicture + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_uiLinePatternIndex != m_sCascadedAttributeData.m_sStyle.m_uiLinePatternIndex + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_bMaterial != m_sCascadedAttributeData.m_sStyle.m_bMaterial + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_uiRgbColorIndex != m_sCascadedAttributeData.m_sStyle.m_uiRgbColorIndex + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_bIsTransparencyDefined != m_sCascadedAttributeData.m_sStyle.m_bIsTransparencyDefined + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_ucTransparency != m_sCascadedAttributeData.m_sStyle.m_ucTransparency + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_bSpecialCulling != m_sCascadedAttributeData.m_sStyle.m_bSpecialCulling + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_bFrontCulling != m_sCascadedAttributeData.m_sStyle.m_bFrontCulling + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_bBackCulling != m_sCascadedAttributeData.m_sStyle.m_bBackCulling + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_bNoLight != m_sCascadedAttributeData.m_sStyle.m_bNoLight) + + bSameDispalyParameter = bSamebSameDispalyParameterOnFace = false; + else + bSameDispalyParameter = true; + + return A3D_SUCCESS; +} + +int ColorMaterialsConnector::GetMaterial(double dEmmisive[4], + double dDiffuse[4], + double dAmbient[4], + double dSpecular[4], + double& dShininess) +{ + int iRet = eBAD_Diffuse + eBAD_Emissive + eBAD_Specular + eBAD_Ambient; + A3DStatus iErr = A3D_SUCCESS; + A3DGraphMaterialData sMaterialData; + + memset(dEmmisive, 0, sizeof(double) * 4); + memset(dDiffuse, 0, sizeof(double) * 4); + memset(dAmbient, 0, sizeof(double) * 4); + memset(dSpecular, 0, sizeof(double) * 4); + dShininess = 0; + + A3D_INITIALIZE_DATA(A3DGraphMaterialData, sMaterialData); + iErr = A3DGlobalGetGraphMaterialData(m_sCascadedAttributeData.m_sStyle.m_uiRgbColorIndex, &sMaterialData); + if(iErr == A3D_SUCCESS) + { + iRet = 0; + A3DGraphRgbColorData sColorData; + A3D_INITIALIZE_DATA(A3DGraphRgbColorData, sColorData); + + if(sMaterialData.m_uiDiffuse != A3D_DEFAULT_COLOR_INDEX) + { + A3DGlobalGetGraphRgbColorData(sMaterialData.m_uiDiffuse, &sColorData); + + dDiffuse[0] = sColorData.m_dRed; + dDiffuse[1] = sColorData.m_dGreen; + dDiffuse[2] = sColorData.m_dBlue; + if(m_sCascadedAttributeData.m_sStyle.m_bIsTransparencyDefined) + { + dDiffuse[3] = (double)(m_sCascadedAttributeData.m_sStyle.m_ucTransparency) / 255.0; + } + else + { + dDiffuse[3] = 1.0; + } + } + else + iRet |= eBAD_Diffuse; + + if(sMaterialData.m_uiEmissive != A3D_DEFAULT_COLOR_INDEX) + { + A3DGlobalGetGraphRgbColorData(sMaterialData.m_uiEmissive, &sColorData); + dEmmisive[0] = sColorData.m_dRed; + dEmmisive[1] = sColorData.m_dGreen; + dEmmisive[2] = sColorData.m_dBlue; + if(m_sCascadedAttributeData.m_sStyle.m_bIsTransparencyDefined) + { + dEmmisive[3] = sMaterialData.m_dEmissiveAlpha; + } + else + { + dEmmisive[3] = 1.0; + } + } + else + iRet |= eBAD_Emissive; + + + dShininess = sMaterialData.m_dShininess; + + if(sMaterialData.m_uiSpecular != A3D_DEFAULT_COLOR_INDEX) + { + A3DGlobalGetGraphRgbColorData(sMaterialData.m_uiSpecular, &sColorData); + + dSpecular[0] = sColorData.m_dRed; + dSpecular[1] = sColorData.m_dGreen; + dSpecular[2] = sColorData.m_dBlue; + if(m_sCascadedAttributeData.m_sStyle.m_bIsTransparencyDefined) + { + dSpecular[3] = sMaterialData.m_dSpecularAlpha; + } + else + { + dSpecular[3] = 1.0; + } + } + else + iRet |= eBAD_Specular; + + if(sMaterialData.m_uiAmbient != A3D_DEFAULT_COLOR_INDEX) + { + A3DGlobalGetGraphRgbColorData(sMaterialData.m_uiAmbient, &sColorData); + + dAmbient[0] = sColorData.m_dRed; + dAmbient[1] = sColorData.m_dGreen; + dAmbient[2] = sColorData.m_dBlue; + if(m_sCascadedAttributeData.m_sStyle.m_bIsTransparencyDefined) + { + dAmbient[3] = sMaterialData.m_dAmbientAlpha; + } + else + { + dAmbient[3] = 1.0; + } + } + else + iRet |= eBAD_Ambient; + } + return iRet; +} + diff --git a/exchange/exchangesource/Collision/visitor/CascadedAttributeConnector.h b/exchange/exchangesource/Collision/visitor/CascadedAttributeConnector.h new file mode 100644 index 0000000..2c66b44 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/CascadedAttributeConnector.h @@ -0,0 +1,59 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_CASCADED_ATTRIBUTE_CLASS +#define A3D_CASCADED_ATTRIBUTE_CLASS + +#include "Connector.h" + + +class ColorMaterialsConnector : public A3DConnector +{ + +public: + A3DMiscCascadedAttributesData m_sCascadedAttributeData; + + ColorMaterialsConnector(A3DMiscCascadedAttributes* pAttr); + + virtual ~ColorMaterialsConnector(); + + bool IsShow(); + + bool IsRemoved(); + + bool IsTexture(); + + bool IsMaterial(); + //A3DStatus GetMaterial(A3DMaterial& sMaterial); + enum eMaterialState + { + eBAD_Emissive = 1, + eBAD_Diffuse = 2, + eBAD_Ambient = 4, + eBAD_Specular = 8 + }; + + + int GetMaterial(double dEmisive[4], double dDiffuse[4], double dAmbient[4], double dSpecular[4], double& dShininess); + + bool IsRGBColor(); + A3DStatus GetRGB(double adRG[4]); + //From 0 (transparent) to 255 (opaque). + bool IsTranparent(); + A3DStatus Transparency(unsigned char& cTransparenty); + + A3DStatus Compare( + ColorMaterialsConnector const & sOtherCascadedAttribute, + bool& bSameColor, + bool& bSameFaceColor); + +}; +#endif diff --git a/exchange/exchangesource/Collision/visitor/Connector.h b/exchange/exchangesource/Collision/visitor/Connector.h new file mode 100644 index 0000000..f19a428 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/Connector.h @@ -0,0 +1,35 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_CONNECTOR +#define A3D_CONNECTOR + +#include +//#include +#ifndef WIN32 +#define strcpy_s(dst, dst_size, src) strcpy((dst), (src)) +#endif +class A3DConnector +{ +protected: + + const A3DEntity* m_pEntity; + + A3DConnector(const A3DEntity* pEntity) : m_pEntity(pEntity) {} + A3DConnector() {}; +public: + + const A3DEntity* GetA3DEntity() const { return m_pEntity; } + virtual A3DEEntityType GetType() const { return kA3DTypeUnknown; } + +}; + +#endif \ No newline at end of file diff --git a/exchange/exchangesource/Collision/visitor/MarkupTessConnector.cpp b/exchange/exchangesource/Collision/visitor/MarkupTessConnector.cpp new file mode 100644 index 0000000..3141e3b --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/MarkupTessConnector.cpp @@ -0,0 +1,653 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file MarkupConnector.cpp + +This file provides tools to get the visual representation of markup + +***********************************************************************************************************************/ +#include "MarkupTessConnector.h" +#include "Visitors.h" +#include +#include "Matrix.h" +#include + + #define DEFAULT_OFFSET {\ + pData += *(puiStart+1); \ + puiStart += (uiCount + 1); \ + } +#define MAKE_OFFSET(CountInt, CountFloats) {\ + pData += CountFloats; \ + puiStart += (CountInt + 1); \ + } + +A3DMarkupTessDataConnectorCreator::A3DMarkupTessDataConnectorCreator(std::vector& a_rvMkpTessConnector) + : m_bStartToDrawSet(false), m_bFaceViewActivated(false), m_bFramedrawActivated(false), m_bFixedSizeActivated(false), + m_rvMarkupTessData(a_rvMkpTessConnector) +{ + m_rvMarkupTessData.push_back(new A3DMarkupTessConnector()); + + //Set Indentity On Matrix + memset(&m_adCurrentWorldMatrix[0], 0, sizeof(double) * 16); + m_adCurrentWorldMatrix[0] = m_adCurrentWorldMatrix[5] = m_adCurrentWorldMatrix[10] = m_adCurrentWorldMatrix[15] = 1; + m_adPushedWorldMatrices.resize(16); + memcpy(&m_adPushedWorldMatrices[0], m_adCurrentWorldMatrix, sizeof(double) * 16); + +} + +A3DMarkupTessDataConnectorCreator::~A3DMarkupTessDataConnectorCreator() +{ +} + +A3DStatus A3DMarkupTessDataConnectorCreator::pushMatrix(const double* a_pdLocalMatrix) +{ + size_t uSize = m_adPushedWorldMatrices.size(); + if(uSize < 16) + return A3D_ERROR; + m_adPushedWorldMatrices.resize(uSize + 16); + + MultiplyMatrix(&m_adCurrentWorldMatrix[0], a_pdLocalMatrix, &m_adPushedWorldMatrices[uSize]); + memcpy( &m_adCurrentWorldMatrix[0],&m_adPushedWorldMatrices[uSize], sizeof(double) * 16); + return A3D_SUCCESS; +} + +A3DStatus A3DMarkupTessDataConnectorCreator::popMatrix() +{ + size_t uSize = m_adPushedWorldMatrices.size() -16; + m_adPushedWorldMatrices.resize(uSize); + memcpy( &m_adCurrentWorldMatrix[0],&m_adPushedWorldMatrices[uSize - 16], sizeof(double) * 16); + return A3D_SUCCESS; +} + +A3DMarkupTessConnector& A3DMarkupTessDataConnectorCreator::GetMarkupTessConnector(const double* pdMatrix) +{ + bool bSameMatrix = true; + size_t uI, uSize = m_rvMarkupTessData.size(); + assert(uSize > 0); + for(uI = 0; uI < 16; uI++) + { + if(m_adCurrentWorldMatrix[uI] != pdMatrix[uI]) + { + bSameMatrix = false; + break; + } + } + if(!bSameMatrix/* && m_bStartToDrawSet*/) + { + m_rvMarkupTessData.push_back(new A3DMarkupTessConnector(*m_rvMarkupTessData[uSize - 1])); + m_bStartToDrawSet = false; + uSize++; + } + return *m_rvMarkupTessData[uSize - 1]; +} + + +A3DMarkupTessConnector& A3DMarkupTessDataConnectorCreator::GetMarkupTessConnector(unsigned uiExtraDataValue,bool& bCameraDependant ) +{ + size_t uSize = m_rvMarkupTessData.size(); + assert(uSize > 0); + bCameraDependant = false; + m_bStartToDrawSet = m_rvMarkupTessData.back()->HasAlreadySomethingToDisplay(); + switch (uiExtraDataValue) + { + case A3D_DECODE_EXTRA_DATA(kA3DMarkupFaceViewMask): // 6 : Camera Dependant - Faceview + m_bFaceViewActivated = !m_bFaceViewActivated; + case A3D_DECODE_EXTRA_DATA(kA3DMarkupFrameDrawMask): // 7 : CameraDependant - Frame draw + m_bFramedrawActivated = !m_bFramedrawActivated; + case A3D_DECODE_EXTRA_DATA(kA3DMarkupFixedSizeMask): // 8 : CameraDependant - Fixedsize + m_bFixedSizeActivated = !m_bFixedSizeActivated; + case A3D_DECODE_EXTRA_DATA(kA3DMarkupSymbolMask): // 9 : Camera Dependant - Symbol + case A3D_DECODE_EXTRA_DATA(kA3DMarkupColorMask): // 11 : color + case A3D_DECODE_EXTRA_DATA(kA3DMarkupLineStippleMask): // 12 : line stipple + case A3D_DECODE_EXTRA_DATA(kA3DMarkupLineWidthMask): // 17 : line width + case 0 : // polyline + case A3D_DECODE_EXTRA_DATA(kA3DMarkupTrianglesMask): // 2 : triangles + case A3D_DECODE_EXTRA_DATA(kA3DMarkupCylinderMask): // 10 : cylinder + case A3D_DECODE_EXTRA_DATA(kA3DMarkupFontMask): // 13 : font + case A3D_DECODE_EXTRA_DATA(kA3DMarkupTextMask): // 14 : text + case A3D_DECODE_EXTRA_DATA(kA3DMarkupPointsMask): // 15 : points + case A3D_DECODE_EXTRA_DATA(kA3DMarkupPolygonMask): // 16 : polygon + { + if(m_bStartToDrawSet) + { + A3DMarkupTessConnector *pNewConnector = new A3DMarkupTessConnector(*m_rvMarkupTessData[uSize - 1]); + m_rvMarkupTessData.push_back(pNewConnector); + uSize++; + m_bStartToDrawSet = false; + memcpy(&(pNewConnector->m_adWorldMatrix[0]), + &m_adCurrentWorldMatrix[0], + sizeof(double)*16); + } + } + break; + } + if(m_bFaceViewActivated || m_bFramedrawActivated || m_bFixedSizeActivated) + bCameraDependant = true; + + + return *m_rvMarkupTessData[uSize - 1]; +} + +/******************************************************************************************************************** + + A3DMarkupTessConnector + +*********************************************************************************************************************/ +A3DMarkupTessConnector::A3DMarkupTessConnector() : m_bFaceView(false) ,m_bFrameDraw(false), m_bSymbol(false), m_bFixedSize(false), +m_bIsText(false), m_uiFixedSizePatternIndex(0), m_iGraphStyleIndexLinsStyle(-1), m_dLineWidth(1.0), m_iGraphVPicturePatternIndex(-1) +{ + memset(m_adViewDependantParameter, 0, sizeof(m_adViewDependantParameter)); + memset(m_adWorldMatrix, 0, sizeof(m_adWorldMatrix)); + m_adWorldMatrix[0] = m_adWorldMatrix[5] = m_adWorldMatrix[10] = m_adWorldMatrix[15] = 1.; + memcpy(&m_adModelMatrix[0], &m_adWorldMatrix[0], sizeof(double) * 16); + memcpy(&m_adProjMatrix[0], &m_adWorldMatrix[0], sizeof(double) * 16); + m_adRGB[0] = m_adRGB[1] = m_adRGB[2] = -1.0; +} + +A3DMarkupTessConnector::A3DMarkupTessConnector(A3DMarkupTessConnector& a_PreviousTessConnector) +{ + m_bFaceView = a_PreviousTessConnector.m_bFaceView; + m_bFrameDraw = a_PreviousTessConnector.m_bFrameDraw; + m_bSymbol = a_PreviousTessConnector.m_bSymbol; + m_bFixedSize = a_PreviousTessConnector.m_bFixedSize; + + m_bIsText = a_PreviousTessConnector.m_bIsText; + memcpy(m_adViewDependantParameter, a_PreviousTessConnector.m_adViewDependantParameter, sizeof(m_adViewDependantParameter)); + m_uiFixedSizePatternIndex = a_PreviousTessConnector.m_uiFixedSizePatternIndex; + + m_ucBehaviour = a_PreviousTessConnector.m_ucBehaviour; + + //Graphic + memcpy(m_adRGB, a_PreviousTessConnector.m_adRGB, sizeof(m_adRGB)); + m_dLineWidth = a_PreviousTessConnector.m_dLineWidth; + m_iGraphStyleIndexLinsStyle = a_PreviousTessConnector.m_iGraphStyleIndexLinsStyle; + m_iGraphVPicturePatternIndex = a_PreviousTessConnector.m_iGraphVPicturePatternIndex; + + //Geometrical data + //std::vector m_adPoints; + //std::vector m_aiPolylineIndices; + //std::vector m_adPolylineCoords; + //std::vector m_adTriangleList; + //std::vector m_adCylinder; // n x (m_dRadiusBase, m_dRadiusTop, m_dHeight) + + //Text + //std::vector m_apTexts; +} + +A3DMarkupTessConnector::~A3DMarkupTessConnector() +{ + std::vector::iterator itCur = m_apTexts.begin(); + std::vector::iterator itEnd = m_apTexts.end(); + for(; itCur < itEnd; ++itCur) + { + delete *itCur; + } +} + +#define SIZE_ARROW 15.0 +A3DStatus A3DMarkupTessConnector::GetMarkupTessellation(const A3DTessBaseData& sTessBaseData, + const A3DTessMarkupData* pTessMarkupData, + const bool bIsText, + std::vector& asMarkupTessDataConnector, + double a_dParallelToScreenPMIScale) +{ + A3DMarkupTessDataConnectorCreator sMarkupTessDataConnectorCreator(asMarkupTessDataConnector); + A3DStatus iRet = A3D_SUCCESS; + float afDefaultcolor[3]; + afDefaultcolor[0] = afDefaultcolor[1] = afDefaultcolor[2] = 0.; + + bool bIsScreenMarkupZoomable = true; + unsigned int kSize; + unsigned int uiCount = 0; + + A3DGraphRgbColorData sRgbColorData; + A3D_INITIALIZE_DATA( A3DGraphRgbColorData, sRgbColorData); + A3DGraphStyleData sGraphStyleData; + A3D_INITIALIZE_DATA( A3DGraphStyleData, sGraphStyleData); + + A3DGraphPictureData sPictureData; + A3D_INITIALIZE_DATA( A3DGraphPictureData, sPictureData); + + A3DFontKeyData sFontKeyData; + A3D_INITIALIZE_DATA(A3DFontKeyData, sFontKeyData); + + bIsScreenMarkupZoomable = (pTessMarkupData->m_cBehaviour & kA3DMarkupIsZoomable) != 0; + const A3DDouble* pData = sTessBaseData.m_pdCoords; + const A3DUns32* puiStart = &pTessMarkupData->m_puiCodes[0]; + const A3DUns32* puiEnd = &pTessMarkupData->m_puiCodes[pTessMarkupData->m_uiCodesSize-1]; + + bool bShow = false; + if((pData != NULL) && (puiStart != NULL) && (puiEnd != NULL)) for (; puiStart < puiEnd; puiStart++) + { + uiCount = *puiStart & kA3DMarkupIntegerMask; + bShow = true; + + if (*puiStart & kA3DMarkupIsExtraData) + { + A3DUns32 uiExtraDataValue = A3D_DECODE_EXTRA_DATA(*puiStart); + bool bCameraDependant; + A3DMarkupTessConnector& sCurMarkupTessConnector = + sMarkupTessDataConnectorCreator.GetMarkupTessConnector(uiExtraDataValue, bCameraDependant); + sCurMarkupTessConnector.m_ucBehaviour = pTessMarkupData->m_cBehaviour; + switch (uiExtraDataValue) + { + case A3D_DECODE_EXTRA_DATA(kA3DMarkupTrianglesMask): // 2 : // triangles + { + kSize = *(puiStart+1);// number of triangles * 9 + unsigned int uI; + for(uI = 0; uI < kSize; uI++) + sCurMarkupTessConnector.m_adTriangleList.push_back(*(pData+uI)); + DEFAULT_OFFSET; + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupFaceViewMask): // 6 : // Camera Dependant - Faceview + // Using by circle center/fastener/measurement point/spot welding + // geometrical symbol zoomable + { + if(*(puiStart+1) > 0) + { + sCurMarkupTessConnector.m_bFaceView = true; + sCurMarkupTessConnector.m_adViewDependantParameter[0] = * pData; + sCurMarkupTessConnector.m_adViewDependantParameter[1] = *(pData+1); + sCurMarkupTessConnector.m_adViewDependantParameter[2] = *(pData+2); + MAKE_OFFSET(0, 3) + } + else + { + if(!(sMarkupTessDataConnectorCreator.HasStartToDrawSet())) + sCurMarkupTessConnector.m_bFaceView = false; + MAKE_OFFSET(0, 0); + } + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupFrameDrawMask): // 7 : // CameraDependant - Frame draw + // Usually used for non-zoomable text, but it is possible to change to zoomable (option on CatiaV5) + { + if(*(puiStart+1) > 0) + { + sCurMarkupTessConnector.m_bFrameDraw = true; + sCurMarkupTessConnector.m_adViewDependantParameter[0] = * pData; + sCurMarkupTessConnector.m_adViewDependantParameter[1] = *(pData+1); + sCurMarkupTessConnector.m_adViewDependantParameter[2] = /*bIsText ? 0 : */*(pData+2); + sCurMarkupTessConnector.m_bIsText = bIsText; + MAKE_OFFSET(0, 3) + } + else + { + if(!(sMarkupTessDataConnectorCreator.HasStartToDrawSet())) + sCurMarkupTessConnector.m_bFrameDraw = false; + MAKE_OFFSET(0, 0) + } + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupFixedSizeMask): // 8 : // CameraDependant - Fixedsize + { + if(*(puiStart+1) > 0) + { + sCurMarkupTessConnector.m_bFixedSize = true; + sCurMarkupTessConnector.m_adViewDependantParameter[0] = * pData; + sCurMarkupTessConnector.m_adViewDependantParameter[1] = *(pData+1); + sCurMarkupTessConnector.m_adViewDependantParameter[2] = /*bIsText ? 0 : */*(pData+2); + sCurMarkupTessConnector.m_uiFixedSizePatternIndex = *(puiStart+2); + MAKE_OFFSET(0, 3); + } + else + { + if(!(sMarkupTessDataConnectorCreator.HasStartToDrawSet())) + sCurMarkupTessConnector.m_bFixedSize = false; + MAKE_OFFSET(0, 0) + } + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupSymbolMask): // 9 : // Camera Dependant - Symbol + { + sCurMarkupTessConnector.m_bSymbol = true; + sCurMarkupTessConnector.m_adViewDependantParameter[0] = * pData; + sCurMarkupTessConnector.m_adViewDependantParameter[1] = *(pData+1); + sCurMarkupTessConnector.m_adViewDependantParameter[2] = /*bIsText ? 0 : */*(pData+2); + //unsigned int uiPatternIndex = *(puiStart+2); + DEFAULT_OFFSET + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupCylinderMask): // 10 : cylinder + { + double dRadiusBase = *pData; + double dRadiusTop = *(pData+1); + double dHeight = *(pData+2); + sCurMarkupTessConnector.m_adCylinder.push_back(dRadiusBase); + sCurMarkupTessConnector.m_adCylinder.push_back(dRadiusTop); + sCurMarkupTessConnector.m_adCylinder.push_back(dHeight); + DEFAULT_OFFSET + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupPolygonMask): // 16 : polylines + { + if(sCurMarkupTessConnector.m_adPolylineCoords.empty() == true) + { + sCurMarkupTessConnector.m_aiPolylineIndices.push_back(0); + } + kSize = *(puiStart+1); // number of points + int iNbIndicesBefore = 0; + if(sCurMarkupTessConnector.m_aiPolylineIndices.size() > 0) + { + iNbIndicesBefore = sCurMarkupTessConnector.m_aiPolylineIndices.back(); + } + unsigned int uI; + for(uI = 0; uI < kSize; uI++) + sCurMarkupTessConnector.m_adPolylineCoords.push_back(*(pData+uI)); + sCurMarkupTessConnector.m_aiPolylineIndices.push_back(iNbIndicesBefore + (kSize / 3)); + DEFAULT_OFFSET; + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupColorMask): // 11 : color + { + A3DGlobalGetGraphRgbColorData(*(puiStart+2), &sRgbColorData); + sCurMarkupTessConnector.m_adRGB[0] = sRgbColorData.m_dRed; + sCurMarkupTessConnector.m_adRGB[1] = sRgbColorData.m_dGreen; + sCurMarkupTessConnector.m_adRGB[2] = sRgbColorData.m_dBlue; + DEFAULT_OFFSET; + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupLineStippleMask): // 12 : line stipple + { + if (uiCount > 0) + { + sCurMarkupTessConnector.m_iGraphStyleIndexLinsStyle = *(puiStart+2); + } + else + sCurMarkupTessConnector.m_iGraphStyleIndexLinsStyle = -1; + //glDisable(GL_LINE_STIPPLE); + DEFAULT_OFFSET; + break; + } + + case A3D_DECODE_EXTRA_DATA(kA3DMarkupLineWidthMask): // 17 : line width + // Linewidth are only used on markup arrow of drawings + { + if (*(puiStart+1) > 0) + { + sCurMarkupTessConnector.m_dLineWidth = *pData; + } + else + { + sCurMarkupTessConnector.m_dLineWidth = 1; + } + DEFAULT_OFFSET; + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupPointsMask): // 15 : points + { + kSize = *(puiStart+1); // number of points + unsigned int uI; + for(uI = 0; uI < kSize; uI++) + { + sCurMarkupTessConnector.m_adPoints.push_back(*(pData+uI)); + } + DEFAULT_OFFSET; + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupFontMask): // 13 : font + { + sFontKeyData.m_iFontFamilyIndex = *(puiStart+2); + sFontKeyData.m_iFontStyleIndex = (*(puiStart+3) & kA3DFontKeyStyle) >> 24; + sFontKeyData.m_iFontSizeIndex = (*(puiStart+3) & kA3DFontKeySize) >> 12; + sFontKeyData.m_cAttributes = (A3DInt8)(*(puiStart+3) & kA3DFontKeyAttrib); + DEFAULT_OFFSET; + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupTextMask): // 14: text + { + A3DDouble dTextWidth = *pData; + A3DDouble dTextHeight = *(pData+1); + A3DUns32 uiTextIndex = *(puiStart+2); + if (uiTextIndex < pTessMarkupData->m_uiTextsSize) + { + sCurMarkupTessConnector.m_apTexts.push_back(new A3DPMITextEntry(dTextWidth, dTextHeight, + sFontKeyData, pTessMarkupData->m_ppcTexts[uiTextIndex])); + } + DEFAULT_OFFSET; + break; + } + + default : + DEFAULT_OFFSET; + } + } + else if (*puiStart & kA3DMarkupIsMatrix) + { + if (*(puiStart+1) > 0) // if there are floats it is the beginning of a "matrix" mode + { + A3DMarkupTessConnector& sCurMarkupTessConnector = sMarkupTessDataConnectorCreator.GetMarkupTessConnector((const double*) pData); + sCurMarkupTessConnector.m_ucBehaviour = pTessMarkupData->m_cBehaviour; + CHECK_RET(sMarkupTessDataConnectorCreator.pushMatrix((const double*) pData)); + + memcpy(&(sCurMarkupTessConnector.m_adWorldMatrix[0]), + sMarkupTessDataConnectorCreator.GetCurrentWorldMatrix(), + sizeof(double) *16); + //dScaleText=stGetScaleText(pData); + if(sCurMarkupTessConnector.IsFrameDraw()) + { + sCurMarkupTessConnector.m_adWorldMatrix[0] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[1] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[2] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[4] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[5] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[6] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[7] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[8] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[9] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[11] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[12] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[13] *= a_dParallelToScreenPMIScale; + } + MAKE_OFFSET(0, 16); + } + else // if there is no float, the matrix mode ends + { + sMarkupTessDataConnectorCreator.popMatrix(); + MAKE_OFFSET(0, 0); + } + } + else // It's a polyline + { + bool bCameraDependant; + A3DMarkupTessConnector& sCurMarkupTessConnector = + sMarkupTessDataConnectorCreator.GetMarkupTessConnector(0, bCameraDependant); + if(sCurMarkupTessConnector.m_adPolylineCoords.empty() == true) + { + sCurMarkupTessConnector.m_aiPolylineIndices.push_back(0); + } + kSize = *(puiStart+1); // Number of points + unsigned int i = 0; + for(i = 0; i < kSize; i++) + { + sCurMarkupTessConnector.m_adPolylineCoords.push_back(*(pData + i)); + } + + if(sCurMarkupTessConnector.IsFrameDraw()) + { + std::vector::iterator itRescaleCur = sCurMarkupTessConnector.m_adPolylineCoords.begin(); + std::vector::iterator itRescaleEnd = sCurMarkupTessConnector.m_adPolylineCoords.end(); + for(; itRescaleCur != itRescaleEnd; ++itRescaleCur) + { + *itRescaleCur *= a_dParallelToScreenPMIScale; + } + } + + sCurMarkupTessConnector.m_aiPolylineIndices.push_back(int(sCurMarkupTessConnector.m_adPolylineCoords.size())/3); + DEFAULT_OFFSET; + } + } + return iRet; +} + +/// Is the order important? Like if FaceView set after Framedraw +A3DStatus A3DMarkupTessConnector::ComputeCameraDependantMatrix( + double const * pdProjMatrix, + int const * aiViewport, + long const * Rect, // TOP_LEFT(X,Y) BOTTOM_RIGHT(X,Y) + double* /*pdPerViewMatrix*/) +{ + + A3DStatus iRet = A3D_SUCCESS; + + double dScaling = 1, dFixedSize = 1.0 * 15 / dScaling; + if(m_bFaceView) // faceview + // using for circlecenter/fastener/measurementpoint/spotwelding + // geometrical symbol zoomable + { + double sO[3]; sO[0]=0; sO[1] = 0; sO[2] = 0; + double sX[3]; sX[0] = 1; sX[1] = 0; sX[2] = 0; + double sY[3]; sY[0] = 0; sY[1] = 1; sY[2] = 0; + + double adP0[3], adP1[3], adP2[3]; + UnProject(&sO[0], m_adModelMatrix, pdProjMatrix, aiViewport, &adP0[0]); + UnProject(&sX[0], m_adModelMatrix, pdProjMatrix, aiViewport, &adP1[0]); + UnProject(&sY[0], m_adModelMatrix, pdProjMatrix, aiViewport, &adP2[0]); + + double adVectX[3]; + adVectX[0] = adP1[0] - adP0[0]; + adVectX[1] = adP1[1] - adP0[1]; + adVectX[2] = adP1[2] - adP0[2]; + + double adVectY[3]; + adVectY[0] = adP2[0] - adP0[0]; + adVectY[1] = adP2[1] - adP0[1]; + adVectY[2] = adP2[2] - adP0[2]; + double adPlaneNormal[3]; + //Cross Product + adPlaneNormal[0] = adVectX[1] * adVectY[2] - adVectX[2] * adVectY[1]; + adPlaneNormal[0] = adVectX[2] * adVectY[0] - adVectX[0] * adVectY[2]; + adPlaneNormal[0] = adVectX[0] * adVectY[1] - adVectX[1] * adVectY[0]; + double adMat[16]; + CHECK_RET(Calculate(&adVectX[0], &adVectY[0], &adPlaneNormal[0],&adMat[0])); + + adMat[12] = m_adViewDependantParameter[0]; + adMat[13] = m_adViewDependantParameter[1]; + adMat[14] = m_adViewDependantParameter[2]; + adMat[15] = 1.; + double adOldModelMatrix[16]; + memcpy(&adOldModelMatrix[0], &m_adModelMatrix[0], sizeof(double) * 16); + CHECK_RET(MultiplyMatrix(&adOldModelMatrix[0], &adMat[0],&m_adModelMatrix[0])); + + } + + if(m_bFrameDraw) // Usually used for non-zoomable text, but it is possible to change to zoomable (option on CatiaV5) + { + double dXProj, dYProj ,dZProj; + if (m_bIsText) + { + dXProj=m_adViewDependantParameter[0]; + dYProj=m_adViewDependantParameter[1]; + dZProj=0.; + } + else + { + + // Ex : turbine de N2688 + // if (GetMatrixOwnerGroup(sMatGroup)) + // sMatGroup.TransformScaled(adViewDependantParameter[0], adViewDependantParameter[1], adViewDependantParameter[2]); + Project(m_adViewDependantParameter[0], m_adViewDependantParameter[1], m_adViewDependantParameter[2], + m_adModelMatrix, pdProjMatrix, aiViewport, &dXProj, &dYProj, &dZProj); + } + + double adIentity[16]; + Identity(&adIentity[0]); + double adOrthoMatrix[16]; + Ortho(&adIentity[0], + 0.0, (double) (Rect[3] - Rect[1]), // Right, Left + 0.0, (double) (Rect[0] - Rect[2]), //Top, Bottom + -1.0, 1.0, //Near, Fast + &adOrthoMatrix[0]); + + double adTranslat[16]; + Identity(&adTranslat[0]); + adTranslat[3] = dXProj; + adTranslat[7] = dYProj; + adTranslat[11] = dZProj; + + CHECK_RET(MultiplyMatrix(&adOrthoMatrix[0],&adTranslat[0],&m_adProjMatrix[0])); + + if(IsZoomable()) + { + double adScale[16]; + Identity(&adScale[0]); + adScale[0] = adScale[5] = adScale[10] = adScale[15] = dFixedSize; + double adOldModelMatrix[16]; + memcpy(&adOldModelMatrix[0], &m_adModelMatrix[0], sizeof(double) * 16); + CHECK_RET(MultiplyMatrix(&adOldModelMatrix[0], &adScale[0], &m_adModelMatrix[0])); + + } + } + + if(m_bFixedSize) + { + double adTranslat[16]; + Identity(&adTranslat[0]); + adTranslat[3] = m_adViewDependantParameter[0]; + adTranslat[7] = m_adViewDependantParameter[1]; + adTranslat[11] = m_adViewDependantParameter[2]; + + double adScale[16]; + Identity(&adScale[0]); + adScale[0] = adScale[5] = adScale[10] = adScale[15] = dFixedSize; + + double adOldModelMatrix[16]; + memcpy(&adOldModelMatrix[0], &m_adModelMatrix[0], sizeof(double) * 16); + CHECK_RET(MultiplyMatrix(&adOldModelMatrix[0], &adTranslat[0], &m_adModelMatrix[0])); + + memcpy(&adOldModelMatrix[0], &m_adModelMatrix[0], sizeof(double) * 16); + CHECK_RET(MultiplyMatrix(&adOldModelMatrix[0], &adScale[0], &m_adModelMatrix[0])); + } + + if(m_bSymbol) + { + double dXProj, dYProj ,dZProj; + if (m_bIsText) + { + dXProj=m_adViewDependantParameter[0]; + dYProj=m_adViewDependantParameter[1]; + dZProj=0.; + } + else + { + // Ex : turbine de N2688 + // if (GetMatrixOwnerGroup(sMatGroup)) + // sMatGroup.TransformScaled(sPntFrame.x,sPntFrame.y,sPntFrame.z); + + CHECK_RET(Project(m_adViewDependantParameter[0], m_adViewDependantParameter[1], m_adViewDependantParameter[2], + m_adModelMatrix, pdProjMatrix, aiViewport, &dXProj, &dYProj, &dZProj)); + } + + double adIentity[16]; + Identity(&adIentity[0]); + double adOrthoMatrix[16]; + CHECK_RET(Ortho(&adIentity[0], + 0.0, (double) (Rect[3] - Rect[1]), // Right, Left + 0.0, (double) (Rect[0] - Rect[2]), //Top, Bottom + -1.0, 1.0, //Near, Fast + &adOrthoMatrix[0])); + + double adTranslat[16]; + Identity(&adTranslat[0]); + adTranslat[3] = dXProj; + adTranslat[7] = dYProj; + adTranslat[11] = dZProj; + + CHECK_RET(MultiplyMatrix(&adOrthoMatrix[0],&adTranslat[0],&m_adProjMatrix[0])); + + //Pattern not used + } + return A3D_SUCCESS; +} + + + diff --git a/exchange/exchangesource/Collision/visitor/MarkupTessConnector.h b/exchange/exchangesource/Collision/visitor/MarkupTessConnector.h new file mode 100644 index 0000000..40eabce --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/MarkupTessConnector.h @@ -0,0 +1,216 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_MKP_CONNECTOR +#define A3D_MKP_CONNECTOR + +#include +#include "Connector.h" +#include +#include + +/********************************************************************************************* + A3DMarkupTessDataConnectorCreator is in charge of creating new A3DMarkupTessConnector + each time a graphical state change when traversing markup tessellation structure + + At the end, A3DMarkupTessDataConnectorCreator ensure that + Tesselated data (point, polyline, triangles, Cone, text) that have the same Graphical data + (color, linestyle , pattern) and same local Matrix are group in the same MarkupTessConnector + +**********************************************************************************************/ +class A3DMarkupTessConnector; +class A3DMarkupTessDataConnectorCreator +{ +public: + A3DMarkupTessDataConnectorCreator(std::vector& a_rvMkpTessConnector); + ~A3DMarkupTessDataConnectorCreator(); + + A3DStatus pushMatrix(const double* a_pdLocalMatrix); + A3DStatus popMatrix(); + const double* GetCurrentWorldMatrix() { return &m_adCurrentWorldMatrix[0]; } + + A3DMarkupTessConnector& GetMarkupTessConnector(const double* pdMatrix); + A3DMarkupTessConnector& GetMarkupTessConnector(unsigned uiExtraDataValue, bool& bCameraDependant); + + bool HasStartToDrawSet() const { return m_bStartToDrawSet; } + +private: + // assignement operator can't work because of the ref member (std::vector&) + A3DMarkupTessDataConnectorCreator& operator= (const A3DMarkupTessDataConnectorCreator&) { assert(false); return *this; } + +private: + bool m_bStartToDrawSet; + + //Camera dependant Parameter: + bool m_bFaceViewActivated; + bool m_bFramedrawActivated; + bool m_bFixedSizeActivated; + + std::vector& m_rvMarkupTessData; + double m_adCurrentWorldMatrix[16]; + std::vector m_adPushedWorldMatrices; +}; + +/********************************************************************************************* + PMI Text entry +*********************************************************************************************/ +class A3DPMITextEntry +{ +public: + + A3DPMITextEntry() : m_dTextWidth(0.0), m_dTextHeight(0.0f), m_apcText(NULL) {} + + A3DPMITextEntry(A3DDouble a_dTextWidth, A3DDouble a_dTextHeight, + A3DFontKeyData const& a_rFontKeyData, A3DUTF8Char* a_apcText) : + m_dTextWidth(a_dTextWidth), m_dTextHeight(a_dTextHeight), m_oFontKeyData(a_rFontKeyData) + { + SetText(a_apcText); + } + + ~A3DPMITextEntry() + { + free(m_apcText); + } + + void SetTextWidth(A3DDouble a_dValue) { m_dTextWidth = a_dValue; } + void SetTextHeight(A3DDouble a_dValue) { m_dTextHeight = a_dValue; } + A3DDouble GetTextWidth() const { return m_dTextWidth; } + A3DDouble GetTextHeight() const { return m_dTextHeight; } + void SetText(A3DUTF8Char const * a_apcText) + { + auto iSize = strlen(a_apcText); + m_apcText = (A3DUTF8Char*)malloc(iSize + 1); + strcpy_s(m_apcText, iSize + 1, a_apcText); + } + A3DUTF8Char* GetText() const { return m_apcText; } + A3DFontKeyData const& GetFontKeyData() { return m_oFontKeyData; } + +private: + A3DDouble m_dTextWidth; + A3DDouble m_dTextHeight; + A3DFontKeyData m_oFontKeyData; + A3DUTF8Char* m_apcText; +}; + + /********************************************************************************************* + Markup Tessellation +**********************************************************************************************/ +class A3DMarkupTessConnector : public A3DConnector +{ + friend class A3DMarkupConnector; + friend class A3DMarkupTessDataConnectorCreator; + +public: + A3DMarkupTessConnector(); + A3DMarkupTessConnector(A3DMarkupTessConnector& a_PreviousTessConnector); + ~A3DMarkupTessConnector(); + + bool HasAlreadySomethingToDisplay() const { return (m_adPoints.size() != 0) || (m_adPolylineCoords.size() != 0) + || (m_aiPolylineIndices.size() != 0) + || (m_adTriangleList.size() != 0) || (m_adCylinder.size() != 0) + || (m_apTexts.size() != 0); } + + // Geometrical Data + std::vector const& GetPolyLineCoords() const { return m_adPolylineCoords; } + std::vector const& GetPolyLineIndices() const { return m_aiPolylineIndices; } + std::vector const& GetTextEntries() const { return m_apTexts; } + std::vector const& GetTriangles() const { return m_adTriangleList; } + std::vector const& GetCylinder() const { return m_adCylinder;} + std::vector const& GetPoints() const { return m_adPoints;} + + // Transfo + double const * GetWorldMatrix() const { return &m_adWorldMatrix[0]; } + + void GetFrameDrawWorldOffset(double a_adOfs[3]) const + { memcpy(a_adOfs, m_adViewDependantParameter, sizeof(m_adViewDependantParameter)); } + + A3DStatus ComputeCameraDependantMatrix( double const * pdProjMatrix, + int const * aiViewport, + long const * Rect, // TOP_LEFT(X,Y) BOTTOM_RIGHT(X,Y) + double* m_adPerViewMatrix); + + bool IsHidden() const { return (m_ucBehaviour&0x01) == 0 ? false : true; } + bool HasFrame() const { return (m_ucBehaviour&0x02) == 0 ? false : true; } + bool IsNotModifiable() const { return (m_ucBehaviour&0x04) == 0 ? false : true; } + bool IsZoomable() const { return (m_ucBehaviour&0x08) == 0 ? false : true; } + bool IsOnTop() const { return (m_ucBehaviour&0x10) == 0 ? false : true; } + bool IsFacingView() const { return m_bFaceView ; } + bool IsFrameDraw() const { return m_bFrameDraw ; } + bool HasColorSetup() const { return m_adRGB[0] >= 0.0; } + + // Graphic + void GetColor(double a_adRGB[3]) const + { + memcpy(a_adRGB, m_adRGB, sizeof(m_adRGB)); + } + double GetLineWidth() const { return m_dLineWidth;} + int GetStyleIndexLineStyle() const { return m_iGraphStyleIndexLinsStyle;} + int GetPicturePattennIndex() const { return m_iGraphVPicturePatternIndex;} + +private: + static A3DStatus GetMarkupTessellation( const A3DTessBaseData& sTessBaseData, + const A3DTessMarkupData* pTessMarkupData, + const bool bIsText, + std::vector& asMarkupTessDataConnector, + double a_dParallelToScreenPMIScale); + +private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) // Suppress the warning C4251 because it leads to have that kind of warning : "warning + // C4251: 'A3DVisitorColorMaterials::m_apsCascadedAttribute' : class 'std::vector<_Ty>' needs to have dll-interface to + // be used by clients of class 'A3DVisitorColorMaterials" + // This is because of the "dllexport" on the visitor classes, as they use stl members and it seems that stl causes + // warning with dllexport with microsoft compiler +#endif // _MSC_VER + + // Parameter useful to compute camera dependant Matrix + bool m_bFaceView; + bool m_bFrameDraw; + bool m_bSymbol; + bool m_bFixedSize; + + bool m_bIsText; + double m_adViewDependantParameter[3]; + unsigned m_uiFixedSizePatternIndex; + + char m_ucBehaviour; + + double m_adModelMatrix[16]; + double m_adProjMatrix[16]; + + //Transfo + double m_adWorldMatrix[16]; + + //Graphic + double m_adRGB[3]; + double m_dLineWidth; + int m_iGraphStyleIndexLinsStyle; + int m_iGraphVPicturePatternIndex; + + //Geometrical data + std::vector m_adPoints; + std::vector m_aiPolylineIndices; + std::vector m_adPolylineCoords; + std::vector m_adTriangleList; + std::vector m_adCylinder; // n x (m_dRadiusBase, m_dRadiusTop, m_dHeight) + + //Text + std::vector m_apTexts; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif // _MSC_VER +}; + +#endif + + \ No newline at end of file diff --git a/exchange/exchangesource/Collision/visitor/MarkupTraverse.cpp b/exchange/exchangesource/Collision/visitor/MarkupTraverse.cpp new file mode 100644 index 0000000..3493c9d --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/MarkupTraverse.cpp @@ -0,0 +1,228 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file MarkupTraverse.cpp + +This file contains functionalities to traverse a PRC Markup Tree + +***********************************************************************************************************************/ + +#include "VisitorContainer.h" +#include "MarkupTraverse.h" +#include +#include +#include "MarkupTessConnector.h" + +////////////////////////////////////////////////////////////////////////////// +// Traverse Markup +////////////////////////////////////////////////////////////////////////////// +A3DStatus A3DMkpAnnotationEntityConnector::TraverseAnnotationEntity(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + + A3DEEntityType eType=kA3DTypeUnknown; + A3DStatus iRet = A3DEntityGetType(m_pEntity,&eType); + CHECK_RET(iRet); + switch(eType) + { + case kA3DTypeMkpAnnotationSet: + { + A3DMkpAnnotationSetConnector sMkpAnnotationSetConnector((A3DMkpAnnotationSet*) m_pEntity); + iRet=sMkpAnnotationSetConnector.TraverseAnnotationSet(pVisitor); + break; + } + case kA3DTypeMkpAnnotationReference: + { + A3DMkpAnnotationReferenceConnector sMkpAnnotationReferenceConnector((A3DMkpAnnotationReference*) m_pEntity); + iRet=sMkpAnnotationReferenceConnector.TraverseAnnotationReference(pVisitor); + break; + } + case kA3DTypeMkpAnnotationItem: + { + A3DMkpAnnotationItemConnector sMkpAnnotationItemConnector((A3DMkpAnnotationItem*) m_pEntity); + iRet=sMkpAnnotationItemConnector.TraverseAnnotationItem(pVisitor); + break; + } + default: + iRet=A3D_ERROR; + break; + } + pVisitor->visitLeave(*this); + + return A3D_SUCCESS; +} + +A3DStatus A3DMkpAnnotationSetConnector::TraverseAnnotationSet(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + A3DUns32 uNbAnnotEntity = m_sAnnotSetData.m_uiAnnotationsSize; + for(A3DUns32 uI = 0; uI < uNbAnnotEntity; uI++) + { + A3DMkpAnnotationEntityConnector sMkpAnnotationEntityConnector(m_sAnnotSetData.m_ppAnnotations[uI]); + sMkpAnnotationEntityConnector.TraverseAnnotationEntity(pVisitor); + } + pVisitor->visitLeave(*this); + return A3D_SUCCESS; +} + +A3DStatus A3DMkpAnnotationReferenceConnector::TraverseAnnotationReference(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + pVisitor->visitLeave(*this); + return A3D_SUCCESS; +} + +A3DStatus A3DMkpAnnotationItemConnector::TraverseAnnotationItem(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + if(m_sAnnotItemData.m_pMarkup == NULL) + { + pVisitor->visitLeave(*this); + return A3D_SUCCESS; + } + + A3DMarkupConnector sMarkupConnector((A3DMkpMarkup*) m_sAnnotItemData.m_pMarkup); + /*A3DStatus iRet=*/sMarkupConnector.TraverseMarkup(pVisitor); + + pVisitor->visitLeave(*this); + return A3D_SUCCESS; +} + +A3DStatus A3DMarkupConnector::TraverseMarkupTessellation(std::vector& asMarkupTessConnector, + double a_dParallelToScreenPMIScale) +{ + A3DStatus iRet = A3D_SUCCESS; + A3DTessMarkupData sMarkupTessData; + A3D_INITIALIZE_DATA(A3DTessMarkupData, sMarkupTessData); + CHECK_RET(A3DTessMarkupGet(m_sMarkupData.m_pTessellation, &sMarkupTessData)); + + A3DTessBaseData sTessBaseData; + A3D_INITIALIZE_DATA(A3DTessBaseData, sTessBaseData); + CHECK_RET(A3DTessBaseGet(m_sMarkupData.m_pTessellation, &sTessBaseData)); + + bool bIsText = m_sMarkupData.m_eType == kA3DMarkupTypeText; + + CHECK_RET(A3DMarkupTessConnector::GetMarkupTessellation(sTessBaseData, &sMarkupTessData, bIsText, + asMarkupTessConnector, a_dParallelToScreenPMIScale)); + + CHECK_RET(A3DTessBaseGet(NULL, &sTessBaseData)); + CHECK_RET(A3DTessMarkupGet(NULL, &sMarkupTessData)); + + unsigned int uI, uJ; + for(uI = 0; uI < m_sMarkupData.m_uiLeadersSize; uI++) + { + A3DMkpLeader* psLeader = m_sMarkupData.m_ppLeaders[uI]; + if(psLeader == NULL) + { + continue; + } + A3DMkpLeaderData sMarkupLeaderData; + A3D_INITIALIZE_DATA(A3DMkpLeaderData, sMarkupLeaderData); + CHECK_RET(A3DMkpLeaderGet(psLeader, &sMarkupLeaderData)); + + A3DTessMarkupData sMarkupLeaderTessData; + A3D_INITIALIZE_DATA(A3DTessMarkupData, sMarkupLeaderTessData); + CHECK_RET(A3DTessMarkupGet(sMarkupLeaderData.m_pTessellation, &sMarkupLeaderTessData)); + + A3DTessBaseData sLeaderTessBaseData; + A3D_INITIALIZE_DATA(A3DTessBaseData, sLeaderTessBaseData); + CHECK_RET(A3DTessBaseGet(sMarkupLeaderData.m_pTessellation, &sLeaderTessBaseData)); + + std::vector asMarkupLeaderConnector; + + CHECK_RET(A3DMarkupTessConnector::GetMarkupTessellation(sLeaderTessBaseData, &sMarkupLeaderTessData, bIsText, + asMarkupLeaderConnector, a_dParallelToScreenPMIScale)); + + for(uJ= 0; uJ < asMarkupLeaderConnector.size(); uJ++) + asMarkupTessConnector.push_back(asMarkupLeaderConnector[uJ]); + + CHECK_RET(A3DTessBaseGet(NULL, &sLeaderTessBaseData)); + CHECK_RET(A3DTessMarkupGet(NULL, &sMarkupLeaderTessData)); + CHECK_RET(A3DMkpLeaderGet(NULL, &sMarkupLeaderData)); + } + + return A3D_SUCCESS; +} + +A3DStatus A3DMarkupConnector::TraverseMarkup(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + + A3DEEntityType eType = kA3DTypeUnknown; + A3DStatus iRet = A3DEntityGetType( this->GetA3DEntity(), &eType); + switch (eType) + { + + case kA3DTypeMarkupText: + break; + case kA3DTypeMarkupRichText: + break; + case kA3DTypeMarkupCoordinate: + break; + case kA3DTypeMarkupBalloon: + break; + case kA3DTypeMarkupDatum: + { + A3DMarkupDatumConnector sMkpDatumConnector((A3DMkpMarkup*) this->GetA3DEntity()); + iRet=sMkpDatumConnector.TraverseDatum(pVisitor); + } + break; + case kA3DTypeMarkupGDT: + { + A3DMarkupGDTConnector sMkpGDTConnector((A3DMkpMarkup*) this->GetA3DEntity()); + iRet=sMkpGDTConnector.TraverseGDT(pVisitor); + } + break; + case kA3DTypeMarkupRoughness: + break; + case kA3DTypeMarkupDimension: + { + A3DMarkupDimensionConnector sMkpDimensionConnector((A3DMkpMarkup*) this->GetA3DEntity()); + iRet=sMkpDimensionConnector.TraverseDimension(pVisitor); + } + break; + case kA3DTypeMarkupLocator: + break; + case kA3DTypeMarkupMeasurementPoint: + break; + case kA3DTypeMarkupFastener: + break; + case kA3DTypeMarkupSpotWelding: + break; + case kA3DTypeMarkupLineWelding: + break; + default: + break; + } + pVisitor->visitLeave(*this); + return A3D_SUCCESS; +} + +A3DStatus A3DMarkupDimensionConnector::TraverseDimension(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + pVisitor->visitLeave(*this); + return A3D_SUCCESS; +} +A3DStatus A3DMarkupGDTConnector::TraverseGDT(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + pVisitor->visitLeave(*this); + return A3D_SUCCESS; +} + +A3DStatus A3DMarkupDatumConnector::TraverseDatum(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + pVisitor->visitLeave(*this); + return A3D_SUCCESS; +} + diff --git a/exchange/exchangesource/Collision/visitor/MarkupTraverse.h b/exchange/exchangesource/Collision/visitor/MarkupTraverse.h new file mode 100644 index 0000000..50616d7 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/MarkupTraverse.h @@ -0,0 +1,198 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_MARKUP_TRAVERSE +#define A3D_MARKUP_TRAVERSE + +#include +#include "Connector.h" + +/*######################################################################## + Markup Hierarchy +##########################################################################*/ + +class A3DVisitorContainer; +class A3DMkpAnnotationEntityConnector : public A3DConnector +{ +public: + + A3DMkpAnnotationEntityConnector(const A3DMkpAnnotationEntity *pAnnotEntity) + : A3DConnector(pAnnotEntity) {} + + ~A3DMkpAnnotationEntityConnector(){} + + A3DStatus TraverseAnnotationEntity(A3DVisitorContainer* psVisitor); + +}; + +class A3DMkpAnnotationSetConnector : public A3DConnector +{ +public: + + A3DMkpAnnotationSetConnector(const A3DMkpAnnotationSet *pAnnotSet) : A3DConnector(pAnnotSet) + { + A3D_INITIALIZE_DATA( A3DMkpAnnotationSetData, m_sAnnotSetData); + A3DMkpAnnotationSetGet(pAnnotSet,&m_sAnnotSetData); + } + + ~A3DMkpAnnotationSetConnector() + { + A3DMkpAnnotationSetGet(NULL, &m_sAnnotSetData); + } + + A3DStatus TraverseAnnotationSet(A3DVisitorContainer* pVisitor); + +public : + + A3DMkpAnnotationSetData m_sAnnotSetData; +}; + +class A3DMkpAnnotationReferenceConnector : public A3DConnector +{ +public: + A3DMkpAnnotationReferenceConnector(const A3DMkpAnnotationReference *pAnnotReference) : A3DConnector(pAnnotReference) + { + A3D_INITIALIZE_DATA( A3DMkpAnnotationReferenceData, m_sAnnotReferenceData); + A3DMkpAnnotationReferenceGet(pAnnotReference,&m_sAnnotReferenceData); + } + + ~A3DMkpAnnotationReferenceConnector() + { + A3DMkpAnnotationReferenceGet(NULL, &m_sAnnotReferenceData); + } + + A3DStatus TraverseAnnotationReference(A3DVisitorContainer* pVisitor); +public : + + A3DMkpAnnotationReferenceData m_sAnnotReferenceData; +}; + +class A3DMkpAnnotationItemConnector : public A3DConnector +{ + +public: + + A3DMkpAnnotationItemConnector(const A3DMkpAnnotationItem *pAnnotItem) : A3DConnector(pAnnotItem) + { + A3D_INITIALIZE_DATA( A3DMkpAnnotationItemData, m_sAnnotItemData); + A3DMkpAnnotationItemGet(pAnnotItem,&m_sAnnotItemData); + } + + ~A3DMkpAnnotationItemConnector() + { + A3DMkpAnnotationItemGet(NULL, &m_sAnnotItemData); + } + + A3DStatus TraverseAnnotationItem(A3DVisitorContainer* pVisitor); + +public: + + A3DMkpAnnotationItemData m_sAnnotItemData; +}; + +class A3DMarkupTessConnector; +class A3DMarkupConnector : public A3DConnector +{ + +public: + + A3DMarkupConnector(const A3DMkpMarkup *pMarkup) : A3DConnector(pMarkup) + { + A3D_INITIALIZE_DATA( A3DMkpMarkupData, m_sMarkupData); + A3DMkpMarkupGet(pMarkup,&m_sMarkupData); + } + + ~A3DMarkupConnector() + { + A3DMkpMarkupGet(NULL, &m_sMarkupData); + } + + A3DStatus TraverseMarkup(A3DVisitorContainer* pVisitor); + A3DStatus TraverseMarkupTessellation(std::vector& asMarkupTessConnector, + double a_dParallelToScreenPMIScale); + +public: + + A3DMkpMarkupData m_sMarkupData; + +}; + + +class A3DMarkupDimensionConnector : public A3DConnector +{ + +public: + + A3DMarkupDimensionConnector(const A3DMarkupDimension *pMarkup) : A3DConnector(pMarkup) + { + A3D_INITIALIZE_DATA( A3DMarkupDimensionData, m_sDimensionData); + A3DMarkupDimensionGet(pMarkup,&m_sDimensionData); + } + + ~A3DMarkupDimensionConnector() + { + A3DMarkupDimensionGet(NULL, &m_sDimensionData); + } + + A3DStatus TraverseDimension(A3DVisitorContainer* pVisitor); + +public: + + A3DMarkupDimensionData m_sDimensionData; +}; + +class A3DMarkupDatumConnector : public A3DConnector +{ + +public: + + A3DMarkupDatumConnector(const A3DMarkupDatum *pMarkup) : A3DConnector(pMarkup) + { + A3D_INITIALIZE_DATA( A3DMarkupDatumData, m_sDatumData); + A3DMarkupDatumGet(pMarkup,&m_sDatumData); + } + + ~A3DMarkupDatumConnector() + { + A3DMarkupDatumGet(NULL, &m_sDatumData); + } + + A3DStatus TraverseDatum(A3DVisitorContainer* pVisitor); + +public: + + A3DMarkupDatumData m_sDatumData; +}; + +class A3DMarkupGDTConnector : public A3DConnector +{ + +public: + + A3DMarkupGDTConnector(const A3DMarkupGDT *pMarkup) : A3DConnector(pMarkup) + { + A3D_INITIALIZE_DATA( A3DMarkupGDTData, m_sGDTData); + A3DMarkupGDTGet(pMarkup,&m_sGDTData); + } + + ~A3DMarkupGDTConnector() + { + A3DMarkupGDTGet(NULL, &m_sGDTData); + } + + A3DStatus TraverseGDT(A3DVisitorContainer* pVisitor); + +public: + + A3DMarkupGDTData m_sGDTData; +}; + +#endif //A3D_MARKUP_TRAVERSE \ No newline at end of file diff --git a/exchange/exchangesource/Collision/visitor/Matrix.cpp b/exchange/exchangesource/Collision/visitor/Matrix.cpp new file mode 100644 index 0000000..2d5bb16 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/Matrix.cpp @@ -0,0 +1,688 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "Matrix.h" +#include + +#include +#include "A3DVector.h" + +//////////////////////////////////////////////////////////////////////// +// A3DMatrix4x4 +/////////////////////////////////////////////////////////////////////// + + +A3DStatus A3DMatrix4x4::CreateIdentity(A3DMatrix4x4*& psIdentity) +{ + // by default A3DMatrix4x4() call a ResetToIdentity + psIdentity = new A3DMatrix4x4(); + return A3D_SUCCESS; +} + + +A3DMatrix4x4 A3DMatrix4x4 :: operator * (const A3DMatrix4x4& matrix) const +{ + A3DMatrix4x4 result; + for (int i=0;i<4;i++) + { + for (int j=0;j<4;j++) + { + result.m_adM[i+4*j] = 0.; + for (int k=0;k<4;k++) + result.m_adM[i+4*j] += m_adM[i+4*k] * matrix.m_adM[k+4*j]; + } + } + return result; +} + + +A3DVector3d A3DMatrix4x4 :: operator * (const A3DVector3d& v) const +{ + A3DVector3d Result; + Result.x = m_adM[0] * v.x + m_adM[4] * v.y + m_adM[8] * v.z + m_adM[12]; + Result.y = m_adM[1] * v.x + m_adM[5] * v.y + m_adM[9] * v.z + m_adM[13]; + Result.z = m_adM[2] * v.x + m_adM[6] * v.y + m_adM[10] * v.z + m_adM[14]; + return Result; +} + +A3DStatus A3DMatrix4x4::Invert(A3DMatrix4x4& sResult) +{ + return Invert4x4(m_adM, sResult.m_adM); +} + +A3DStatus A3DMatrix4x4::GetTranslation(A3DVector3d& sTranslation) +{ + sTranslation.x = m_adM[12]; + sTranslation.y = m_adM[13]; + sTranslation.z = m_adM[14]; + return A3D_SUCCESS; +} + +void A3DMatrix4x4::ResetToIdentity() +{ + memset(m_adM, 0, sizeof(double) * 16); + m_adM[0] = m_adM[5] = m_adM[10] = m_adM[15] = 1; +} + +bool A3DMatrix4x4::IsIdentity() const +{ + if((m_adM[0] != 1.0) || (m_adM[1] != 0.0) || (m_adM[2] != 0.0) || (m_adM[3] != 0.0) + || (m_adM[4] != 0.0) || (m_adM[5] != 1.0) || (m_adM[6] != 0.0) || (m_adM[7] != 0.0) + || (m_adM[8] != 0.0) || (m_adM[9] != 0.0) || (m_adM[10] != 1.0) || (m_adM[11] != 0.0) + || (m_adM[12] != 0.0) || (m_adM[13] != 0.0) || (m_adM[14] != 0.0) || (m_adM[15] != 1.0)) + { + return false; + } + return true; +} + +void A3DMatrix4x4::GetTranslation( double& rdTX, double& rdTY, double& rdTZ ) const +{ + rdTX = m_adM[12]; + rdTY = m_adM[13]; + rdTZ = m_adM[14]; +} + +void A3DMatrix4x4::GetScales( double& rdSX, double& rdSY, double& rdSZ ) const +{ + rdSX = sqrt(m_adM[0]*m_adM[0] + m_adM[1]*m_adM[1] + m_adM[2]*m_adM[2]); + rdSY = sqrt(m_adM[4]*m_adM[4] + m_adM[5]*m_adM[5] + m_adM[6]*m_adM[6]); + rdSZ = sqrt(m_adM[8]*m_adM[8] + m_adM[9]*m_adM[9] + m_adM[10]*m_adM[10]); +} + +void A3DMatrix4x4::GetXYZRadianAngles( double& rdXAngle, double& rdYAngle, double& rdZAngle ) const +{ + //matrix3x3 of rotation without scale + double dSx, dSy, dSz; + GetScales(dSx, dSy, dSz); + double rot[9]; + rot[0] = m_adM[0]/dSx; rot[3] = m_adM[4]/dSy; rot[6] = m_adM[8]/dSz; + rot[1] = m_adM[1]/dSx; rot[4] = m_adM[5]/dSy; rot[7] = m_adM[9]/dSz; + rot[2] = m_adM[2]/dSx; rot[5] = m_adM[6]/dSy; rot[8] = m_adM[10]/dSz; + + +// rdYAngle = asin(rot[2]); //attitude : +// if(rdYAngle < A3D_HALF_PI) +// if(rdYAngle > - A3D_HALF_PI) +// { +// rdXAngle = atan2(-rot[5], rot[8]);//bank : rotation along the "look at axis" (1 0 0) +// rdZAngle = atan2(-rot[1], rot[0]);//heading : rotation along up axis (0 0 1) +// } +// else +// { +// rdZAngle = 0.0; // multiple solutions +// rdXAngle = -atan2(rot[4], rot[5]); +// } +// else +// { +// rdZAngle = 0.0; // multiple solutions +// rdXAngle = atan2(rot[4], rot[5]); +// } + if(rot[1] > 0.998) + { + rdZAngle = atan2(rot[6], rot[8]); + rdYAngle = A3D_HALF_PI; + rdXAngle = 0.0; + } + else if(rot[1] < -.998) + { + rdZAngle = atan2(rot[6], rot[8]); + rdYAngle = -A3D_HALF_PI; + rdXAngle = 0.0; + } + else + { + rdZAngle = atan2(-rot[2], rot[0]); + rdYAngle = asin(rot[1]); + if(rot[7] == 0.0 && rot[4] == 0) + { + int sign = (rot[7] > 0) - (rot[7] < 0); + if(sign >= 0) + rdXAngle = A3D_HALF_PI; + else + rdXAngle = -A3D_HALF_PI; + } + else + rdXAngle = atan2(-rot[7], rot[4]); + } + +// +// double cX = cos(rdXAngle); +// double sX = sin(rdXAngle); +// double cY = cos(rdYAngle); +// double sY = sin(rdYAngle); +// double cZ = cos(rdZAngle); +// double sZ = sin(rdZAngle); +// +// A3DMatrix4x4 testResult; +// testResult.m_adM[0] = cZ*cY; testResult.m_adM[4] = -cZ*sY*cX + sZ*sX; testResult.m_adM[8] = cZ*sY*sX + sZ*cX; +// testResult.m_adM[1] = sY; testResult.m_adM[5] = cY*cX; testResult.m_adM[9] = -cY*sX; +// testResult.m_adM[2] = -sZ*cY; testResult.m_adM[6] = sZ*sY*cX + cZ*sX; testResult.m_adM[10] = -sZ*sY*sX + cZ*cX; +// bool bRes = testResult.Compare(this); + +} + +void A3DMatrix4x4::setRotations(double const& dXAngle, double const& dYAngle, double const& dZAngle) +{ + // Real fCos, fSin; + +// fCos = Math::Cos(fYAngle); +// fSin = Math::Sin(fYAngle); +// Matrix3 kXMat(1.0,0.0,0.0,0.0,fCos,-fSin,0.0,fSin,fCos); +// +// fCos = Math::Cos(fPAngle); +// fSin = Math::Sin(fPAngle); +// Matrix3 kYMat(fCos,0.0,fSin,0.0,1.0,0.0,-fSin,0.0,fCos); +// +// fCos = Math::Cos(fRAngle); +// fSin = Math::Sin(fRAngle); +// Matrix3 kZMat(fCos,-fSin,0.0,fSin,fCos,0.0,0.0,0.0,1.0); +// +// *this = kXMat*(kYMat*kZMat); + + double dCos, dSin; + dCos = cos(dXAngle); + dSin = sin(dXAngle); + + A3DMatrix4x4 AX; + AX.m_adM[5] = dCos; + AX.m_adM[6] = -dSin; + AX.m_adM[9] = dSin; + AX.m_adM[10] = dCos; + + dCos = cos(dYAngle); + dSin = sin(dYAngle); + + A3DMatrix4x4 AY; + AY.m_adM[0] = dCos; + AY.m_adM[2] = dSin; + AY.m_adM[8] = -dSin; + AY.m_adM[10] = dCos; + + dCos = cos(dZAngle); + dSin = sin(dZAngle); + + A3DMatrix4x4 AZ; + AZ.m_adM[0] = dCos; + AZ.m_adM[1] = -dSin; + AZ.m_adM[4] = dSin; + AZ.m_adM[5] = dCos; + + + *this = AX * (AY * AZ); +} + +bool A3DMatrix4x4::Compare( A3DMatrix4x4 const& rOther, double dTol ) const +{ + if(dTol != 0.0) + { + for(int i =0; i < 16; i++) + { + if(m_adM[i] != rOther.m_adM[i]) + return false; + } + } + else + { + for(int i =0; i < 16; i++) + { + if(fabs(m_adM[i] - rOther.m_adM[i]) < dTol) + return false; + } + } + return true; +} + +static void MultMatrixVecd(const double matrix[16], + const double in[4], + double out[4]) +{ + int i; + + for (i=0; i<4; i++) { + out[i] = + in[0] * matrix[0*4+i] + + in[1] * matrix[1*4+i] + + in[2] * matrix[2*4+i] + + in[3] * matrix[3*4+i]; + } +} + +/* +** Invert 4x4 matrix. +** Contributed by David Moore (See Mesa bug #6748) +*/ +static bool InvertMatrixd(const double m[16], double invOut[16]) +{ + double inv[16], det; + int i; + + inv[0] = m[5]*m[10]*m[15] - m[5]*m[11]*m[14] - m[9]*m[6]*m[15] + + m[9]*m[7]*m[14] + m[13]*m[6]*m[11] - m[13]*m[7]*m[10]; + inv[4] = -m[4]*m[10]*m[15] + m[4]*m[11]*m[14] + m[8]*m[6]*m[15] + - m[8]*m[7]*m[14] - m[12]*m[6]*m[11] + m[12]*m[7]*m[10]; + inv[8] = m[4]*m[9]*m[15] - m[4]*m[11]*m[13] - m[8]*m[5]*m[15] + + m[8]*m[7]*m[13] + m[12]*m[5]*m[11] - m[12]*m[7]*m[9]; + inv[12] = -m[4]*m[9]*m[14] + m[4]*m[10]*m[13] + m[8]*m[5]*m[14] + - m[8]*m[6]*m[13] - m[12]*m[5]*m[10] + m[12]*m[6]*m[9]; + inv[1] = -m[1]*m[10]*m[15] + m[1]*m[11]*m[14] + m[9]*m[2]*m[15] + - m[9]*m[3]*m[14] - m[13]*m[2]*m[11] + m[13]*m[3]*m[10]; + inv[5] = m[0]*m[10]*m[15] - m[0]*m[11]*m[14] - m[8]*m[2]*m[15] + + m[8]*m[3]*m[14] + m[12]*m[2]*m[11] - m[12]*m[3]*m[10]; + inv[9] = -m[0]*m[9]*m[15] + m[0]*m[11]*m[13] + m[8]*m[1]*m[15] + - m[8]*m[3]*m[13] - m[12]*m[1]*m[11] + m[12]*m[3]*m[9]; + inv[13] = m[0]*m[9]*m[14] - m[0]*m[10]*m[13] - m[8]*m[1]*m[14] + + m[8]*m[2]*m[13] + m[12]*m[1]*m[10] - m[12]*m[2]*m[9]; + inv[2] = m[1]*m[6]*m[15] - m[1]*m[7]*m[14] - m[5]*m[2]*m[15] + + m[5]*m[3]*m[14] + m[13]*m[2]*m[7] - m[13]*m[3]*m[6]; + inv[6] = -m[0]*m[6]*m[15] + m[0]*m[7]*m[14] + m[4]*m[2]*m[15] + - m[4]*m[3]*m[14] - m[12]*m[2]*m[7] + m[12]*m[3]*m[6]; + inv[10] = m[0]*m[5]*m[15] - m[0]*m[7]*m[13] - m[4]*m[1]*m[15] + + m[4]*m[3]*m[13] + m[12]*m[1]*m[7] - m[12]*m[3]*m[5]; + inv[14] = -m[0]*m[5]*m[14] + m[0]*m[6]*m[13] + m[4]*m[1]*m[14] + - m[4]*m[2]*m[13] - m[12]*m[1]*m[6] + m[12]*m[2]*m[5]; + inv[3] = -m[1]*m[6]*m[11] + m[1]*m[7]*m[10] + m[5]*m[2]*m[11] + - m[5]*m[3]*m[10] - m[9]*m[2]*m[7] + m[9]*m[3]*m[6]; + inv[7] = m[0]*m[6]*m[11] - m[0]*m[7]*m[10] - m[4]*m[2]*m[11] + + m[4]*m[3]*m[10] + m[8]*m[2]*m[7] - m[8]*m[3]*m[6]; + inv[11] = -m[0]*m[5]*m[11] + m[0]*m[7]*m[9] + m[4]*m[1]*m[11] + - m[4]*m[3]*m[9] - m[8]*m[1]*m[7] + m[8]*m[3]*m[5]; + inv[15] = m[0]*m[5]*m[10] - m[0]*m[6]*m[9] - m[4]*m[1]*m[10] + + m[4]*m[2]*m[9] + m[8]*m[1]*m[6] - m[8]*m[2]*m[5]; + + det = m[0]*inv[0] + m[1]*inv[4] + m[2]*inv[8] + m[3]*inv[12]; + if (det == 0) + return false; + + det = 1.0 / det; + + for (i = 0; i < 16; i++) + invOut[i] = inv[i] * det; + + return true; +} + +static void MultMatricesd(const double a[16], const double b[16], + double r[16]) +{ + int i, j; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + r[i*4+j] = + a[i*4+0]*b[0*4+j] + + a[i*4+1]*b[1*4+j] + + a[i*4+2]*b[2*4+j] + + a[i*4+3]*b[3*4+j]; + } + } +} + + +A3DStatus UnProject( double winx, + double winy, + double winz, + const double modelMatrix[16], + const double projMatrix[16], + const int viewport[4], + double *objx, double *objy, double *objz) +{ + double finalMatrix[16]; + double in[4]; + double out[4]; + + MultMatricesd(modelMatrix, projMatrix, finalMatrix); + if (!InvertMatrixd(finalMatrix, finalMatrix)) + return A3D_ERROR; + + in[0]=winx; + in[1]=winy; + in[2]=winz; + in[3]=1.0; + + /* Map x and y from window coordinates */ + in[0] = (in[0] - viewport[0]) / viewport[2]; + in[1] = (in[1] - viewport[1]) / viewport[3]; + + /* Map to range -1 to 1 */ + in[0] = in[0] * 2 - 1; + in[1] = in[1] * 2 - 1; + in[2] = in[2] * 2 - 1; + + MultMatrixVecd(finalMatrix, in, out); + if (out[3] == 0.0) + return A3D_ERROR; + out[0] /= out[3]; + out[1] /= out[3]; + out[2] /= out[3]; + *objx = out[0]; + *objy = out[1]; + *objz = out[2]; + return A3D_SUCCESS; +} + +A3DStatus Project(double objx, + double objy, + double objz, + const double modelMatrix[16], + const double projMatrix[16], + const int viewport[4], + double *winx, + double *winy, + double *winz) +{ + double in[4]; + double out[4]; + + in[0]=objx; + in[1]=objy; + in[2]=objz; + in[3]=1.0; + MultMatrixVecd(modelMatrix, in, out); + MultMatrixVecd(projMatrix, out, in); + if (in[3] == 0.0) return A3D_ERROR; + in[0] /= in[3]; + in[1] /= in[3]; + in[2] /= in[3]; + /* Map x, y and z to range 0-1 */ + in[0] = in[0] * 0.5 + 0.5; + in[1] = in[1] * 0.5 + 0.5; + in[2] = in[2] * 0.5 + 0.5; + + /* Map x,y to viewport */ + in[0] = in[0] * viewport[2] + viewport[0]; + in[1] = in[1] * viewport[3] + viewport[1]; + + *winx=in[0]; + *winy=in[1]; + *winz=in[2]; + + return A3D_SUCCESS; +} + + +/******************************************************* + Multiply Matrix + ********************************************************/ +A3DStatus MultiplyMatrix(const double* padFather, const double* pdThisMatrix, double* pdResult) +{ + A3DStatus iRet = A3D_SUCCESS; + pdResult[0] = padFather[0] * pdThisMatrix[0] + padFather[4] * pdThisMatrix[1] + padFather[8] * pdThisMatrix[2] + padFather[12] * pdThisMatrix[3]; + pdResult[1] = padFather[1] * pdThisMatrix[0] + padFather[5] * pdThisMatrix[1] + padFather[9] * pdThisMatrix[2] + padFather[13] * pdThisMatrix[3]; + pdResult[2] = padFather[2] * pdThisMatrix[0] + padFather[6] * pdThisMatrix[1] + padFather[10] * pdThisMatrix[2] + padFather[14] * pdThisMatrix[3]; + pdResult[3] = padFather[3] * pdThisMatrix[0] + padFather[7] * pdThisMatrix[1] + padFather[11] * pdThisMatrix[2] + padFather[15] * pdThisMatrix[3]; + pdResult[4] = padFather[0] * pdThisMatrix[4] + padFather[4] * pdThisMatrix[5] + padFather[8] * pdThisMatrix[6] + padFather[12] * pdThisMatrix[7]; + pdResult[5] = padFather[1] * pdThisMatrix[4] + padFather[5] * pdThisMatrix[5] + padFather[9] * pdThisMatrix[6] + padFather[13] * pdThisMatrix[7]; + pdResult[6] = padFather[2] * pdThisMatrix[4] + padFather[6] * pdThisMatrix[5] + padFather[10] * pdThisMatrix[6] + padFather[14] * pdThisMatrix[7]; + pdResult[7] = padFather[3] * pdThisMatrix[4] + padFather[7] * pdThisMatrix[5] + padFather[11] * pdThisMatrix[6] + padFather[15] * pdThisMatrix[7]; + pdResult[8] = padFather[0] * pdThisMatrix[8] + padFather[4] * pdThisMatrix[9] + padFather[8] * pdThisMatrix[10] + padFather[12] * pdThisMatrix[11]; + pdResult[9] = padFather[1] * pdThisMatrix[8] + padFather[5] * pdThisMatrix[9] + padFather[9] * pdThisMatrix[10] + padFather[13] * pdThisMatrix[11]; + pdResult[10] = padFather[2] * pdThisMatrix[8] + padFather[6] * pdThisMatrix[9] + padFather[10] * pdThisMatrix[10] + padFather[14] * pdThisMatrix[11]; + pdResult[11] = padFather[3] * pdThisMatrix[8] + padFather[7] * pdThisMatrix[9] + padFather[11] * pdThisMatrix[10] + padFather[15] * pdThisMatrix[11]; + pdResult[12] = padFather[0] * pdThisMatrix[12] + padFather[4] * pdThisMatrix[13] + padFather[8] * pdThisMatrix[14] + padFather[12] * pdThisMatrix[15]; + pdResult[13] = padFather[1] * pdThisMatrix[12] + padFather[5] * pdThisMatrix[13] + padFather[9] * pdThisMatrix[14] + padFather[13] * pdThisMatrix[15]; + pdResult[14] = padFather[2] * pdThisMatrix[12] + padFather[6] * pdThisMatrix[13] + padFather[10] * pdThisMatrix[14] + padFather[14] * pdThisMatrix[15]; + pdResult[15] = padFather[3] * pdThisMatrix[12] + padFather[7] * pdThisMatrix[13] + padFather[11] * pdThisMatrix[14] + padFather[15] * pdThisMatrix[15]; + return iRet; +} + + +static void MatrixVectMultiply(const double* pdMatrix, + const double* pdVect, + double* pdresult) +{ + unsigned int uI; + + for (uI = 0; uI < 4; uI++) + { + pdresult[uI] = + pdVect[0] * pdMatrix[uI] + + pdVect[1] * pdMatrix[4+uI] + + pdVect[2] * pdMatrix[8+uI] + + pdVect[3] * pdMatrix[12+uI]; + } +} + +/******************************************************* + Invert Matrix + ********************************************************/ +A3DStatus Calculate(double* pdX, double* pdY, double* pdZ, double* pdMat) +{ + double dLenght = sqrt(pdX[0] * pdX[0] + pdX[1] * pdX[1] + pdX[2] * pdX[2]); + if(dLenght < 1e-12) + return A3D_ERROR; + pdX[0] /= dLenght; pdX[1] /= dLenght; pdX[2] /= dLenght; + + dLenght = sqrt(pdY[0] * pdY[0] + pdY[1] * pdY[1] + pdY[2] * pdY[2]); + if(dLenght < 1e-12) + return A3D_ERROR; + pdY[0] /= dLenght; pdY[1] /= dLenght; pdY[2] /= dLenght; + + dLenght = sqrt(pdZ[0] * pdZ[0] + pdZ[1] * pdZ[1] + pdZ[2] * pdZ[2]); + if(dLenght < 1e-12) + return A3D_ERROR; + pdZ[0] /= dLenght; pdZ[1] /= dLenght; pdZ[2] /= dLenght; + + pdMat[0] = pdX[0]; + pdMat[1] = pdX[1]; + pdMat[2] = pdX[2]; + pdMat[4] = pdY[0]; + pdMat[5] = pdY[1]; + pdMat[6] = pdY[2]; + pdMat[8] = pdZ[0]; + pdMat[9] = pdZ[1]; + pdMat[10]= pdZ[2]; + + pdMat[3] = pdMat[7] = pdMat[11] = pdMat[12] = pdMat[13] = pdMat[14] = pdMat[15] = 0; + + return A3D_SUCCESS; +} + + +/******************************************************* + Invert Matrix +********************************************************/ +double det2x2(double a, double b, double c, double d) +{ + double det; + det = a * d - b * c; + return det; +} + +double det3x3(double a1, double a2, double a3, + double b1, double b2, double b3, + double c1, double c2, double c3) +{ + double det; + det = a1 * det2x2(b2, b3, c2, c3) + - b1 * det2x2(a2, a3, c2, c3) + + c1 * det2x2(a2, a3, b2, b3); + return det; +} + + void adjoint(double* pdMatrix) +{ + double a1, a2, a3, a4, b1, b2, b3, b4; + double c1, c2, c3, c4, d1, d2, d3, d4; + + + a1 = pdMatrix[0]; b1 = pdMatrix[1]; + c1 = pdMatrix[2]; d1 = pdMatrix[3]; + a2 = pdMatrix[4]; b2 = pdMatrix[5]; + c2 = pdMatrix[6]; d2 = pdMatrix[7]; + a3 = pdMatrix[8]; b3 = pdMatrix[9]; + c3 = pdMatrix[10]; d3 = pdMatrix[11]; + a4 = pdMatrix[12]; b4 = pdMatrix[13]; + c4 = pdMatrix[14]; d4 = pdMatrix[15]; + + pdMatrix[0] = det3x3( b2, b3, b4, c2, c3, c4, d2, d3, d4); + pdMatrix[4] = - det3x3( a2, a3, a4, c2, c3, c4, d2, d3, d4); + pdMatrix[8] = det3x3( a2, a3, a4, b2, b3, b4, d2, d3, d4); + pdMatrix[12] = - det3x3( a2, a3, a4, b2, b3, b4, c2, c3, c4); + + pdMatrix[1] = - det3x3( b1, b3, b4, c1, c3, c4, d1, d3, d4); + pdMatrix[5] = det3x3( a1, a3, a4, c1, c3, c4, d1, d3, d4); + pdMatrix[9] = - det3x3( a1, a3, a4, b1, b3, b4, d1, d3, d4); + pdMatrix[13] = det3x3( a1, a3, a4, b1, b3, b4, c1, c3, c4); + + pdMatrix[2] = det3x3( b1, b2, b4, c1, c2, c4, d1, d2, d4); + pdMatrix[6] = - det3x3( a1, a2, a4, c1, c2, c4, d1, d2, d4); + pdMatrix[10] = det3x3( a1, a2, a4, b1, b2, b4, d1, d2, d4); + pdMatrix[14] = - det3x3( a1, a2, a4, b1, b2, b4, c1, c2, c4); + + pdMatrix[3] = - det3x3( b1, b2, b3, c1, c2, c3, d1, d2, d3); + pdMatrix[7] = det3x3( a1, a2, a3, c1, c2, c3, d1, d2, d3); + pdMatrix[11] = - det3x3( a1, a2, a3, b1, b2, b3, d1, d2, d3); + pdMatrix[15] = det3x3( a1, a2, a3, b1, b2, b3, c1, c2, c3); +} + +A3DStatus Invert4x4(const double* pdMat, double* pdMatInv) +{ + double det; + int i,j; + double scale = pdMat[15]; + + if (fabs(scale) < FLT_MIN) + { + /*"Matrice avec Scale == 0.: inversion impossible\n"*/ + return A3D_ERROR; + } + + for (i=0;i<4;i++) + for (j=0;j<4;j++) + pdMatInv[i*4 + j] = pdMat[i*4 + j]; + + adjoint(pdMatInv); + det = det3x3(pdMat[0], pdMat[4], pdMat[8], + pdMat[1], pdMat[5], pdMat[9], + pdMat[2], pdMat[6], pdMat[10]); + + if (fabs(det) < FLT_MIN) + { + /*"Matrice non reguliere: inversion impossible\n"*/ + return A3D_ERROR; + } + + for (i=0;i<4;i++) + for (j=0;j<4;j++) + pdMatInv[i * 4 +j] /= (scale*det); + + return A3D_SUCCESS; +} + + +A3DStatus UnProject(const double * pPt, + const double* pdModelMatrix, + const double* pdProjMatrix, + const int* viewport, + double* pPtresult) +{ + double finalMatrix[16]; + double in[4]; + double out[4]; + + MultiplyMatrix(pdModelMatrix, pdProjMatrix, finalMatrix); + if (!Invert4x4(finalMatrix, finalMatrix)) + return A3D_ERROR; + + in[0]=pPt[0]; + in[1]=pPt[1]; + in[2]=pPt[2]; + in[3]=1.0; + + /* Map x and y from window coordinates */ + in[0] = (in[0] - viewport[0]) / viewport[2]; + in[1] = (in[1] - viewport[1]) / viewport[3]; + + /* Map to range -1 to 1 */ + in[0] = in[0] * 2 - 1; + in[1] = in[1] * 2 - 1; + in[2] = in[2] * 2 - 1; + + MatrixVectMultiply(finalMatrix, in, out); + if (out[3] == 0.0) + return A3D_ERROR; + + out[0] /= out[3]; + out[1] /= out[3]; + out[2] /= out[3]; + + *(pPtresult) = out[0]; + *(pPtresult+1) = out[1]; + *(pPtresult+2) = out[2]; + + double objx, objy, objz; + UnProject(pPt[0], pPt[1], pPt[2], + pdModelMatrix, + pdProjMatrix, + viewport, + &objx, &objy, &objz); + + if( fabs(pPtresult[0] - objx)> 1e-12 + || fabs(pPtresult[1] - objx)> 1e-12 + || fabs(pPtresult[2] - objx)> 1e-12) + return A3D_ERROR; + return A3D_SUCCESS; +} + +A3DStatus Identity(double* pdIdentity) +{ + memset(&pdIdentity[0], 0, 16 * sizeof(double)); + pdIdentity[0] = pdIdentity[5] = pdIdentity[10] = pdIdentity[15] = 1; + return A3D_SUCCESS; +} + +A3DStatus Ortho(const double* pdCurrentMatrix, + double dLeft, + double dRight, + double dTop, + double dBottom, + double dNear, + double dFar, + double* pdOutput) +{ + double adOrthoMatrix[16]; + double tx = - (dRight + dLeft)/(dRight - dLeft); + double ty = - (dTop + dBottom)/(dTop - dBottom); + double tz = - (dFar + dNear)/(dFar - dNear); + + adOrthoMatrix[0] = 2/(dRight - dLeft); + adOrthoMatrix[1] = 0; + adOrthoMatrix[2] = 0; + adOrthoMatrix[3] = tx; + + adOrthoMatrix[4] = 0; + adOrthoMatrix[5] = 2/(dTop - dBottom); + adOrthoMatrix[6] = 0; + adOrthoMatrix[7] = ty; + + adOrthoMatrix[8] = 0; + adOrthoMatrix[9] = 0; + adOrthoMatrix[10] = ( -2)/(dFar - dNear); + adOrthoMatrix[11] = tz; + + adOrthoMatrix[12] = 0; + adOrthoMatrix[13] = 0; + adOrthoMatrix[14] = 0; + adOrthoMatrix[15] = 1; + + MatrixVectMultiply( pdCurrentMatrix,adOrthoMatrix,pdOutput); + return A3D_SUCCESS; +} + +A3DVector3dData CrossProduct(const A3DVector3dData* X, const A3DVector3dData* Y) +{ + A3DVector3dData Z; + Z.m_dX=X->m_dY*Y->m_dZ - X->m_dZ*Y->m_dY; + Z.m_dY=X->m_dZ*Y->m_dX - X->m_dX*Y->m_dZ; + Z.m_dZ=X->m_dX*Y->m_dY - X->m_dY*Y->m_dX; + return Z; +} diff --git a/exchange/exchangesource/Collision/visitor/Matrix.h b/exchange/exchangesource/Collision/visitor/Matrix.h new file mode 100644 index 0000000..a049735 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/Matrix.h @@ -0,0 +1,105 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3DMATRIX_H +#define A3DMATRIX_H + +#include +#include +#include +#include +#include "A3DVector.h" + +#define A3D_PI 3.1415926535897932384626433832795028841971693993751 +#define A3D_HALF_PI 1.5707963267948966192313216916397514420985846996875 + + + +class A3DMatrix4x4 +{ +public: + double m_adM[16]; + //column first + //m_adM[0] = m00 m_adM[4] = m01 m_adM[8] = m02 m_adM[12] = m03 + //m_adM[1] = m10 m_adM[5] = m11 m_adM[9] = m12 m_adM[13] = m13 + //m_adM[2] = m20 m_adM[6] = m21 m_adM[10] = m22 m_adM[14] = m23 + //m_adM[3] = m30 m_adM[7] = m31 m_adM[11] = m32 m_adM[15] = m33 + A3DMatrix4x4(double* pdMat) { memcpy(&m_adM[0], pdMat, sizeof(double) * 16); } + A3DMatrix4x4() { ResetToIdentity(); } + + static A3DStatus CreateIdentity(A3DMatrix4x4*& psIdentity); + + A3DMatrix4x4 operator * (const A3DMatrix4x4& matrix) const; + + A3DVector3d operator * (const A3DVector3d& pt) const; + + A3DStatus Invert(A3DMatrix4x4& sResult); + + A3DStatus GetTranslation(A3DVector3d& sTranslation); + + void ResetToIdentity(); + bool IsIdentity() const; + + void GetScales(double& rdSX, double& rdSY, double& rdSZ) const; + void GetTranslation(double& rdTX, double& rdTY, double& rdTZ) const; + void GetXYZRadianAngles(double& rdXAngle, double& rdYAngle, double& rdZAngle) const; + + double const& operator[](const unsigned& u) const { return m_adM[u]; } + void setRotations(double const& dXAngle, double const& dYAngle, double const& dZAngle); + + A3DMatrix4x4& operator = (const A3DMatrix4x4& rFrom) + { + memcpy(m_adM, rFrom.m_adM, sizeof(double) * 16); + return *this; + } + bool Compare(A3DMatrix4x4 const& rOther, double dTol = 0.0) const; + +}; + + +A3DStatus MultiplyMatrix(const double* padFather, const double* pdThisMatrix, double* pdResult); + +A3DStatus Invert4x4(const double* pdMat, double* pdMatInv); + +A3DStatus Calculate(double* pdX, double* pdY, double* pdZ, double* pdMat); + +A3DStatus UnProject( const double * pPt, + const double* pdModelMatrix, + const double* pdProjMatrix, + const int* viewport, + double* pPtresult); + +A3DStatus Project(double objx, + double objy, + double objz, + const double pdModelMatrix[16], + const double pdProjMatrix[16], + const int viewport[4], + double *winx, + double *winy, + double *winz); + + +A3DStatus Ortho(const double* pdCurrentMatrix, + double dLeft, + double dRight, + double dTop, + double dBottom, + double dNear, + double dfar, + double* pdOutput); + +A3DStatus Identity(double* pdIdentity); + +A3DVector3dData CrossProduct(const A3DVector3dData* X, const A3DVector3dData* Y); + +static const A3DMatrix4x4 stIdentity; +#endif diff --git a/exchange/exchangesource/Collision/visitor/TessConnector.cpp b/exchange/exchangesource/Collision/visitor/TessConnector.cpp new file mode 100644 index 0000000..c83659c --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/TessConnector.cpp @@ -0,0 +1,1431 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file TessConnector.cpp +This file provide tools to get the tessellation of Cad Models + +***********************************************************************************************************************/ + +#include "TessConnector.h" +#include "VisitorContainer.h" +#include + +//////////////////////////////////////// +// A3DTessDataConnector +/////////////////////////////////////// +A3DTessDataConnector::A3DTessDataConnector(const A3DTess3D* pTess3D) : A3DConnector(pTess3D) +{ + A3D_INITIALIZE_DATA(A3DTess3DData, m_sTessData); + A3DTess3DGet( pTess3D, &m_sTessData); + + A3D_INITIALIZE_DATA(A3DTessBaseData, m_sBaseTessData); + A3DTessBaseGet((const A3DTessBase*) pTess3D,&m_sBaseTessData); +} + +A3DTessDataConnector::~A3DTessDataConnector() +{ + A3DTess3DGet( NULL, &m_sTessData); + A3DTessBaseGet(NULL, &m_sBaseTessData); +} + +A3DStatus A3DTessDataConnector::Traverse(A3DVisitorContainer* psVisitor) +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned uNbFaces = FacesSize(); + + for(unsigned uFace = 0; uFace < uNbFaces; uFace++) + { + A3DFaceTessDataConnector sFaceConnector(&m_sTessData.m_psFaceTessData[uFace], uFace, this); + sFaceConnector.Traverse(psVisitor); + } + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +// Retrieve all the point of the Tess3DData +A3DStatus A3DTessDataConnector::Points(double*& pPoint, unsigned int& uSize) const +{ + pPoint = m_sBaseTessData.m_pdCoords; + uSize = m_sBaseTessData.m_uiCoordSize; + return A3D_SUCCESS; +} + +// Retrieve all the normals of the Tess3DData +A3DStatus A3DTessDataConnector::Normals(double*& pNormal, unsigned int& uSize) const +{ + pNormal = m_sTessData.m_pdNormals; + uSize = m_sTessData.m_uiNormalSize; + return A3D_SUCCESS; +} + +// Retrieve all the textures of the Tess3DData +A3DStatus A3DTessDataConnector::UV(double*& pUV, unsigned int& uSize) const +{ + pUV = m_sTessData.m_pdTextureCoords; + uSize = m_sTessData.m_uiTextureCoordSize; + return A3D_SUCCESS; +} + +#define COPY(dest,src,size_) if(size_ != 0) {\ + size_t uTempSize = dest.size();\ + dest.resize(uTempSize + size_);\ + std::copy(src ,src+ size_, dest.begin() + uTempSize);\ + src+= size_; \ + size_ = 0;\ + } + +#define COPY_(dest,src,size_) /*if(size_)*/ {\ + size_t uTempSize = dest.size();\ + dest.resize(uTempSize + size_);\ + std::copy(src,src+size_, dest.begin() + uTempSize);\ + } + + +// Retrieve the index as triangle for each Face of the Tess3DData +A3DStatus A3DTessDataConnector::IndicesAsTriangle( + std::vector& auTriangleWithPoint_Normals, + std::vector& auTriangleWithPoint_Normals_UV_Indices) const +{ + A3DStatus iRet = A3D_SUCCESS; + unsigned uFaceCount, uFaceSize = m_sTessData.m_uiFaceTessSize; + for(uFaceCount = 0;uFaceCount < uFaceSize; uFaceCount++) + { + CHECK_RET(IndicesPerFaceAsTriangle( + uFaceCount, + auTriangleWithPoint_Normals, + auTriangleWithPoint_Normals_UV_Indices)); + } + return A3D_SUCCESS; +} + +// Retrieve the index as triangle per face of the Tess3DData +A3DStatus A3DTessDataConnector::IndicesPerFaceAsTriangle( + const unsigned& uFaceIndice, + std::vector& auTriangleWithPoint_Normals_Indices, + std::vector& auTriangleWithPoint_Normals_UV_Indices) const +{ + A3DTessFaceData* pFaceTessData = &(m_sTessData.m_psFaceTessData[uFaceIndice]); + + if (!pFaceTessData->m_uiSizesTriangulatedSize) + return A3D_SUCCESS; + + A3DUns32* puiTriangulatedIndexes = m_sTessData.m_puiTriangulatedIndexes + + pFaceTessData->m_uiStartTriangulated; + unsigned uiCurrentSize = 0; + + // Triangle One Normal Per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangle) + { + unsigned uiNbIndice = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 6; + COPY(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, uiNbIndice); + } + + // Fan One Normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFan) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32* pFanPointIndice = puiTriangulatedIndexes; + puiTriangulatedIndexes+=2; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes+2, 2); + puiTriangulatedIndexes+=2; + } + puiTriangulatedIndexes+=2; + } + } + + // stripe One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripe) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + puiTriangulatedIndexes+=2; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes,2); + if( uIPoint%2) + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 2,2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2,2); + } + else + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2,2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 2,2); + } + puiTriangulatedIndexes+=2; + } + puiTriangulatedIndexes+=2; + } + } + + //Triangle one Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormal) + { + A3DUns32 uNbTriangles = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]/* & kA3DTessFaceDataNormalMask*/; + for(A3DUns32 uI = 0; uI < uNbTriangles; uI++) + { + A3DUns32* pNormalIndice = puiTriangulatedIndexes; + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes,2); + puiTriangulatedIndexes+=2; + COPY_(auTriangleWithPoint_Normals_Indices, pNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes,1); + puiTriangulatedIndexes+=1; + COPY_(auTriangleWithPoint_Normals_Indices, pNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes,1); + puiTriangulatedIndexes+=1; + } + } + + // Fan One normal per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormal) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if(bIsOneNormal == false) + { + return A3D_ERROR; + } + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32* pFanPointIndice = puiTriangulatedIndexes; + puiTriangulatedIndexes+=2; + for (A3DUns32 uIPoint = 0; uIPoint < uiNbPoint-2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 2); + + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 1); + + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 1, 1); + puiTriangulatedIndexes+=1; + } + puiTriangulatedIndexes++; + } + } + + // Stripe One normal per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormal) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + A3DUns32* pStripeNormalIndice = puiTriangulatedIndexes; + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + puiTriangulatedIndexes+=2; + + // Is there only one normal for the entire stripe? + if(bIsOneNormal == false) + { + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes,2); + if( uIPoint%2) + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 2,2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2,2); + } + else + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2,2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 2,2); + } + puiTriangulatedIndexes+=2; + } + puiTriangulatedIndexes+=2; + continue; + } + + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes,1); + if(uIPoint%2) + { + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 1,1); + + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 1,1); + } + else + { + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 1,1); + + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 1,1); + } + puiTriangulatedIndexes+=1; + } + puiTriangulatedIndexes+=1; + } + } + + // Textured triangle One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleTextured) + { + unsigned uiNbIndice = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 9; + COPY(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, uiNbIndice); + } + + // Textured Fan One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanTextured) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32* pFanPointIndice = puiTriangulatedIndexes; + puiTriangulatedIndexes+=3; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint-2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes+3, 3); + puiTriangulatedIndexes+=3; + } + puiTriangulatedIndexes+=3; + } + } + + //Textured Stripe One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeTextured) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + puiTriangulatedIndexes+=3; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes ,3); + if(uIPoint%2) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 3,3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3,3); + } + else + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3,3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 3,3); + } + puiTriangulatedIndexes+=3; + } + puiTriangulatedIndexes += 3; + } + } + + // Textured One normal per Triangle + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormalTextured) + { + A3DUns32 uNbTriangles = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for(A3DUns32 uI = 0; uI < uNbTriangles; uI++) + { + A3DUns32* pNormalIndice = puiTriangulatedIndexes; + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes,3); + puiTriangulatedIndexes+=3; + COPY_(auTriangleWithPoint_Normals_UV_Indices, pNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes,2); + puiTriangulatedIndexes+=2; + COPY_(auTriangleWithPoint_Normals_UV_Indices, pNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes,2); + puiTriangulatedIndexes+=2; + } + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormalTextured) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if(bIsOneNormal == false) + { + return A3D_ERROR; + } + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32* pFanPointIndice = puiTriangulatedIndexes; + puiTriangulatedIndexes+=2; + for (A3DUns32 uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 3); + + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 1); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 2); + + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 1); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 2, 2); + puiTriangulatedIndexes+=2; + } + puiTriangulatedIndexes+=2; + } + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormalTextured) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if(bIsOneNormal == false) + { + return A3D_ERROR; + } + A3DUns32* pStripeNormalIndice = puiTriangulatedIndexes; + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + puiTriangulatedIndexes+=3; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice,1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes,2); + if( uIPoint%2) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice,1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 2, 2); + + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice,1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 2, 2); + } + else + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice,1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 2, 2); + + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice,1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 2, 2); + + } + puiTriangulatedIndexes+=2; + } + } + } + + return A3D_SUCCESS; +} + +A3DStatus A3DTessDataConnector::IndicesPerFace( + const unsigned& uFaceIndice, + std::vector& /*auTrianglesOneNormal*/, //(normal, point, point,..., point) + std::vector& /*auFanOneNormal*/, + std::vector& /*auStripeOneNormal*/, + std::vector& auTrianglesWithNormals, //normal, point, ... , normal, point + std::vector& auFanWithNormals, + std::vector& auStripeWithNormal, + std::vector& /*auTrianglesOneNormalTexture*/, //normal,{texture...},point,{texture...},point,{texture...},point + std::vector& /*auFanOneNormalTextured*/, + std::vector& /*auStripeOneNormalTextured*/, + std::vector& /*auTrianglesWithNormalsTextured*/, //normal,{texture...},point,...,normal,{texture...},point + std::vector& /*auFanWithNormalsTextured*/, + std::vector& /*auStripeWithNormalsTextured*/) const +{ + A3DTessFaceData* pFaceTessData = &(m_sTessData.m_psFaceTessData[uFaceIndice]); + if (!pFaceTessData->m_uiSizesTriangulatedSize) + return A3D_SUCCESS; + + A3DUns32 uiCurrentSize = 0; + A3DUns32* puiTriangulatedIndexes = m_sTessData.m_puiTriangulatedIndexes + + pFaceTessData->m_uiStartTriangulated; + A3DUns32 uiNbIndice = 0; + + // One Normal Per Vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangle) + { + uiNbIndice = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 6; + COPY(auTrianglesWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFan) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + uiNbIndice+= pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]*2; + COPY(auFanWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripe) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + uiNbIndice+= pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]*2; + COPY(auStripeWithNormal, puiTriangulatedIndexes, uiNbIndice); + } + + //One Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormal) + { + uiNbIndice = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]/* & kA3DTessFaceDataNormalMask*/) * 4; + } + COPY(auTrianglesWithNormals, puiTriangulatedIndexes, uiNbIndice); + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormal) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if(bIsOneNormal == false) + { + return A3D_ERROR; + } + uiNbIndice+= pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] + 1; + } + COPY(auFanWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormal) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if(bIsOneNormal == false) + { + return A3D_ERROR; + } + uiNbIndice+= pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] + 1; + } + COPY(auStripeWithNormal, puiTriangulatedIndexes, uiNbIndice); + } + + // Textured + //One Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleTextured) + uiNbIndice = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 9; + COPY(auTrianglesWithNormals, puiTriangulatedIndexes, uiNbIndice); + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanTextured) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + uiNbIndice+= pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 3 ; + COPY(auFanWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeTextured) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + uiNbIndice+= pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 3; + COPY(auStripeWithNormal, puiTriangulatedIndexes, uiNbIndice); + } + + + // Textured + //One Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormalTextured) + { + uiNbIndice = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]/* & kA3DTessFaceDataNormalMask*/) * 7; + } + COPY(auTrianglesWithNormals, puiTriangulatedIndexes, uiNbIndice); + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormalTextured) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if(bIsOneNormal == false) + { + return A3D_ERROR; + } + uiNbIndice+= (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask) * 2 + 1 ; + } + COPY(auFanWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormalTextured) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if(bIsOneNormal == false) + { + return A3D_ERROR; + } + uiNbIndice+= (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask) * 2 + 1; + } + COPY(auStripeWithNormal, puiTriangulatedIndexes, uiNbIndice); + } + + return A3D_SUCCESS; +} + +A3DStatus A3DTessDataConnector::Indices( + std::vector& auTrianglesOneNormal, //(normal, point, point,..., point) + std::vector& auFanOneNormal, + std::vector& auStripeOneNormal, + std::vector& auTrianglesWithNormals, //normal, point, ... , normal, point + std::vector& auFanWithNormals, + std::vector& auStripeWithNormal, + std::vector& auTrianglesOneNormalTexture, //normal,{texture...},point,{texture...},point,{texture...},point + std::vector& auFanOneNormalTextured, + std::vector& auStripeOneNormalTextured, + std::vector& auTrianglesWithNormalsTextured, //normal,{texture...},point,...,normal,{texture...},point + std::vector& auFanWithNormalsTextured, + std::vector& auStripeWithNormalsTextured) const +{ + A3DStatus iRet = A3D_SUCCESS; + unsigned uFaceCount, uFaceSize = m_sTessData.m_uiFaceTessSize; + for(uFaceCount = 0;uFaceCount < uFaceSize; uFaceCount++) + CHECK_RET(IndicesPerFace( + uFaceCount, + auTrianglesOneNormal, + auFanOneNormal, + auStripeOneNormal, + auTrianglesWithNormals, + auFanWithNormals, + auStripeWithNormal, + auTrianglesOneNormalTexture, + auFanOneNormalTextured, + auStripeOneNormalTextured, + auTrianglesWithNormalsTextured, + auFanWithNormalsTextured, + auStripeWithNormalsTextured)); + return A3D_SUCCESS; +} + +//////////////////////////////////////// +// A3DFaceTessDataConnector +/////////////////////////////////////// +A3DFaceTessDataConnector::A3DFaceTessDataConnector(const A3DTessFaceData* pFaceTess3D, + unsigned uCurrentFaceIndex, + const A3DTessDataConnector* pTessConnector) + : A3DConnector(pFaceTess3D), + m_pTessConnector(pTessConnector), + m_uCurrentFaceIndex(uCurrentFaceIndex) +{ +} + +A3DFaceTessDataConnector::~A3DFaceTessDataConnector() +{ +} + +A3DStatus A3DFaceTessDataConnector::Traverse( A3DVisitorContainer* psVisitor ) +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + + +A3DStatus A3DFaceTessDataConnector::IndicesAsTriangle( + std::vector& auTriangleWithPoint_Normals_Indices, + std::vector& auTriangleWithPoint_Normals_UV_Indices) const +{ + A3DTessFaceData* pFaceTessData = (A3DTessFaceData*)this->GetA3DEntity(); + if (!pFaceTessData->m_uiSizesTriangulatedSize) + return A3D_SUCCESS; + + A3DUns32* puiTriangulatedIndexes = m_pTessConnector->GetTess3DData()->m_puiTriangulatedIndexes + + pFaceTessData->m_uiStartTriangulated; + unsigned uiCurrentSize = 0; + + // Triangle One Normal Per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangle) + { + unsigned uiNbIndice = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]) * 6; + COPY(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, uiNbIndice); + puiTriangulatedIndexes += uiNbIndice; + } + + // Fan One Normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFan) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32* pFanPointIndice = puiTriangulatedIndexes; + puiTriangulatedIndexes+=2; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2, 2); + puiTriangulatedIndexes+=2; + } + puiTriangulatedIndexes+=2; + } + } + + // stripe One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripe) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + puiTriangulatedIndexes+=2; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes,2); + if( uIPoint%2) + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 2,2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2,2); + } + else + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2,2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 2,2); + } + puiTriangulatedIndexes+=2; + } + puiTriangulatedIndexes+=2; + } + } + + //Triangle one Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormal) + { + A3DUns32 uNbTriangles = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]/* & kA3DTessFaceDataNormalMask*/; + for(A3DUns32 uI = 0; uI < uNbTriangles; uI++) + { + A3DUns32* pNormalIndice = puiTriangulatedIndexes; + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes,2); + puiTriangulatedIndexes+=2; + COPY_(auTriangleWithPoint_Normals_Indices, pNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes,1); + puiTriangulatedIndexes+=1; + COPY_(auTriangleWithPoint_Normals_Indices, pNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes,1); + puiTriangulatedIndexes+=1; + } + } + + // Fan One normal per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormal) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32* pFanPointIndice = puiTriangulatedIndexes; + puiTriangulatedIndexes+=1; + + if(bIsOneNormal == false) + { + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2, 2); + puiTriangulatedIndexes+=2; + } + puiTriangulatedIndexes+=2; + continue; + } + + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 1; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 2); + + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 1); + + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 1, 1); + puiTriangulatedIndexes+=1; + } + puiTriangulatedIndexes+=1; + } + } + + // Stripe One normal per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormal) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + A3DUns32* pStripeNormalIndice = puiTriangulatedIndexes; + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + puiTriangulatedIndexes+=2; + + if(bIsOneNormal == false) + { + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes,2); + if( uIPoint%2) + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 2,2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2,2); + } + else + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2,2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 2,2); + } + puiTriangulatedIndexes+=2; + } + puiTriangulatedIndexes+=2; + continue; + } + + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes,1); + if(uIPoint%2) + { + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 1,1); + + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 1,1); + } + else + { + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 1,1); + + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 1,1); + } + puiTriangulatedIndexes+=1; + } + puiTriangulatedIndexes+=1; + } + } + + // Textured triangle One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleTextured) + { + unsigned uiNbIndice = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 9; + COPY(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, uiNbIndice); + puiTriangulatedIndexes += uiNbIndice; + } + + // Textured Fan One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanTextured) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32* pFanPointIndice = puiTriangulatedIndexes; + puiTriangulatedIndexes+=3; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3, 3); + puiTriangulatedIndexes+=3; + } + puiTriangulatedIndexes+=3; + } + } + + //Textured Stripe One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeTextured) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + puiTriangulatedIndexes+=3; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes ,3); + if(uIPoint%2) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 3,3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3,3); + } + else + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3,3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 3,3); + } + puiTriangulatedIndexes+=3; + } + puiTriangulatedIndexes+=3; + } + } + + // Textured One normal per Triangle + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormalTextured) + { + A3DUns32 uNbTriangles = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for(A3DUns32 uI = 0; uI < uNbTriangles; uI++) + { + A3DUns32* pNormalIndice = puiTriangulatedIndexes; + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes,3); + puiTriangulatedIndexes+=3; + COPY_(auTriangleWithPoint_Normals_UV_Indices, pNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes,2); + puiTriangulatedIndexes+=2; + COPY_(auTriangleWithPoint_Normals_UV_Indices, pNormalIndice,1); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes,2); + puiTriangulatedIndexes+=2; + } + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormalTextured) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32* pFanPointIndice = puiTriangulatedIndexes; + puiTriangulatedIndexes+=2; + + if(bIsOneNormal == false) + { + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3, 3); + puiTriangulatedIndexes+=3; + } + puiTriangulatedIndexes+=3; + continue; + } + + for (A3DUns32 uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 3); + + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 1); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 2); + + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 1); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 2, 2); + puiTriangulatedIndexes+=2; + } + puiTriangulatedIndexes+=2; + } + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormalTextured) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + A3DUns32* pStripeNormalIndice = puiTriangulatedIndexes; + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + puiTriangulatedIndexes+=3; + + if(bIsOneNormal == false) + { + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes ,3); + if(uIPoint%2) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 3,3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3,3); + } + else + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3,3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 3,3); + } + puiTriangulatedIndexes+=3; + } + puiTriangulatedIndexes+=3; + continue; + } + + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice,1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes,2); + if( uIPoint%2) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice,1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 2, 2); + + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice,1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 2, 2); + } + else + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice,1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 2, 2); + + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice,1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 2, 2); + + } + puiTriangulatedIndexes+=2; + } + puiTriangulatedIndexes+=2; + } + } + + return A3D_SUCCESS; +} + +A3DStatus A3DFaceTessDataConnector::ColorsAsTriangle(std::vector& auTriangleWithPoint_Colors, bool &bIsRGBA) const +{ + A3DTessFaceData* pFaceTessData = (A3DTessFaceData*)this->GetA3DEntity(); + if (!pFaceTessData->m_uiSizesTriangulatedSize || pFaceTessData->m_uiRGBAVerticesSize == 0) + return A3D_SUCCESS; + + A3DUns8* puiTriangulatedColors = pFaceTessData->m_pucRGBAVertices; + //+ pFaceTessData->m_uiStartTriangulated; + + bIsRGBA = (pFaceTessData->m_bIsRGBA) > 0; + unsigned uiColorComponents = bIsRGBA ? 4 : 3; + unsigned uiCurrentSize = 0; + + // Triangle One Normal Per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangle) + { + unsigned uiNbIndice = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]) * 3 * uiColorComponents; + COPY(auTriangleWithPoint_Colors, puiTriangulatedColors, uiNbIndice); + } + + // Fan One Normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFan) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns8* pFanPointColors = puiTriangulatedColors; + puiTriangulatedColors += uiColorComponents; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Colors, pFanPointColors, uiColorComponents); + COPY_(auTriangleWithPoint_Colors, puiTriangulatedColors, uiColorComponents); + COPY_(auTriangleWithPoint_Colors, puiTriangulatedColors + uiColorComponents, uiColorComponents); + puiTriangulatedColors += uiColorComponents; + } + puiTriangulatedColors += uiColorComponents; + } + } + + // stripe One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripe) + { + int test = 0; + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + puiTriangulatedColors += uiColorComponents; + + for (A3DUns32 uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Colors, puiTriangulatedColors, uiColorComponents); + + if (uIPoint % 2) + { + COPY_(auTriangleWithPoint_Colors, puiTriangulatedColors - uiColorComponents, uiColorComponents); + COPY_(auTriangleWithPoint_Colors, puiTriangulatedColors + uiColorComponents, uiColorComponents); + } + else + { + COPY_(auTriangleWithPoint_Colors, puiTriangulatedColors + uiColorComponents, uiColorComponents); + COPY_(auTriangleWithPoint_Colors, puiTriangulatedColors - uiColorComponents, uiColorComponents); + } + puiTriangulatedColors += uiColorComponents; + } + puiTriangulatedColors += uiColorComponents; + } + test = test; + } + + //Triangle one Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormal) + { + unsigned uiNbIndice = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]) * 3 * uiColorComponents; + COPY(auTriangleWithPoint_Colors, puiTriangulatedColors, uiNbIndice); + } + + // Fan One normal per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormal) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns8* pFanPointColors = puiTriangulatedColors; + puiTriangulatedColors += uiColorComponents; + + if (bIsOneNormal == false) + { + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Colors, pFanPointColors, uiColorComponents); + COPY_(auTriangleWithPoint_Colors, puiTriangulatedColors, uiColorComponents); + COPY_(auTriangleWithPoint_Colors, puiTriangulatedColors + uiColorComponents, uiColorComponents); + puiTriangulatedColors += uiColorComponents; + } + puiTriangulatedColors += uiColorComponents; + continue; + } + + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 1; uIPoint++) + { + COPY_(auTriangleWithPoint_Colors, pFanPointColors, uiColorComponents); + COPY_(auTriangleWithPoint_Colors, puiTriangulatedColors, uiColorComponents); + COPY_(auTriangleWithPoint_Colors, puiTriangulatedColors + uiColorComponents, uiColorComponents); + puiTriangulatedColors += uiColorComponents; + } + puiTriangulatedColors += uiColorComponents; + } + } + + // Stripe One normal per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormal) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + puiTriangulatedColors += uiColorComponents; + + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Colors, puiTriangulatedColors, uiColorComponents); + + if (uIPoint % 2) + { + COPY_(auTriangleWithPoint_Colors, puiTriangulatedColors - uiColorComponents, uiColorComponents); + COPY_(auTriangleWithPoint_Colors, puiTriangulatedColors + uiColorComponents, uiColorComponents); + } + else + { + COPY_(auTriangleWithPoint_Colors, puiTriangulatedColors + uiColorComponents, uiColorComponents); + COPY_(auTriangleWithPoint_Colors, puiTriangulatedColors - uiColorComponents, uiColorComponents); + } + puiTriangulatedColors += uiColorComponents; + } + puiTriangulatedColors += uiColorComponents; + } + } + return A3D_SUCCESS; +} + +A3DStatus A3DFaceTessDataConnector::Indices( + std::vector& /*auTrianglesOneNormal*/, //(normal, point, point,..., point) + std::vector& /*auFanOneNormal*/, + std::vector& /*auStripeOneNormal*/, + std::vector& auTrianglesWithNormals, //normal, point, ... , normal, point + std::vector& auFanWithNormals, + std::vector& auStripeWithNormal, + std::vector& /*auTrianglesOneNormalTexture*/, //normal,{texture...},point,{texture...},point,{texture...},point + std::vector& /*auFanOneNormalTextured*/, + std::vector& /*auStripeOneNormalTextured*/, + std::vector& /*auTrianglesWithNormalsTextured*/, //normal,{texture...},point,...,normal,{texture...},point + std::vector& /*auFanWithNormalsTextured*/, + std::vector& /*auStripeWithNormalsTextured*/) const +{ + A3DTessFaceData* pFaceTessData = (A3DTessFaceData*)this->GetA3DEntity(); + if (!pFaceTessData->m_uiSizesTriangulatedSize) + return A3D_SUCCESS; + + A3DUns32 uiCurrentSize = 0; + A3DUns32* puiTriangulatedIndexes = m_pTessConnector->GetTess3DData()->m_puiTriangulatedIndexes + + pFaceTessData->m_uiStartTriangulated; + A3DUns32 uiNbIndice = 0; + + // One Normal Per Vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangle) + { + uiNbIndice = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 6; + COPY(auTrianglesWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFan) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + uiNbIndice+= pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]*2; + COPY(auFanWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripe) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + uiNbIndice+= pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]*2; + COPY(auStripeWithNormal, puiTriangulatedIndexes, uiNbIndice); + } + + //One Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormal) + { +// bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; +// if(bIsOneNormal == false) +// { +// return A3D_ERROR; +// } + uiNbIndice = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]/* & kA3DTessFaceDataNormalMask*/) * 4; + } + COPY(auTrianglesWithNormals, puiTriangulatedIndexes, uiNbIndice); + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormal) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if(bIsOneNormal == false) + { + return A3D_ERROR; + } + uiNbIndice+= (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask) + 1; + } + COPY(auFanWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormal) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if(bIsOneNormal == false) + { + return A3D_ERROR; + } + uiNbIndice+= pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] + 1; + } + COPY(auStripeWithNormal, puiTriangulatedIndexes, uiNbIndice); + } + + // Textured + //One Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleTextured) + uiNbIndice = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 9; + COPY(auTrianglesWithNormals, puiTriangulatedIndexes, uiNbIndice); + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanTextured) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + uiNbIndice+= pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 3 ; + COPY(auFanWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeTextured) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + uiNbIndice+= pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 3; + COPY(auStripeWithNormal, puiTriangulatedIndexes, uiNbIndice); + } + + + // Textured + //One Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormalTextured) + { + uiNbIndice = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]/* & kA3DTessFaceDataNormalMask*/) * 7; + } + COPY(auTrianglesWithNormals, puiTriangulatedIndexes, uiNbIndice); + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormalTextured) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if(bIsOneNormal == false) + { + return A3D_ERROR; + } + uiNbIndice+= (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask) * 2 + 1 ; + } + COPY(auFanWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormalTextured) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if(bIsOneNormal == false) + { + return A3D_ERROR; + } + uiNbIndice+= (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask) * 2 + 1; + } + COPY(auStripeWithNormal, puiTriangulatedIndexes, uiNbIndice); + } + + return A3D_SUCCESS; +} + +unsigned A3DFaceTessDataConnector::GetWireNumber() const +{ + A3DTessFaceData* pFaceTessData = (A3DTessFaceData*)this->GetA3DEntity(); + return pFaceTessData->m_uiSizesWiresSize; +} + +A3DStatus A3DFaceTessDataConnector::GetEdgeIndices(unsigned uEdgeIndice, std::vector& auEdgeIndice) const +{ + A3DTessFaceData* pFaceTessData = (A3DTessFaceData*)this->GetA3DEntity(); + unsigned int uI, uNbVertices = pFaceTessData->m_puiSizesWires[uEdgeIndice]; + + + if((uNbVertices & kA3DTessFaceDataWireIsNotDrawn) != 0) + uNbVertices = uNbVertices & (~kA3DTessFaceDataWireIsNotDrawn); + + bool bClosed = (uNbVertices & kA3DTessFaceDataWireIsClosing) != 0; + if(bClosed) + uNbVertices = uNbVertices & (~kA3DTessFaceDataWireIsClosing); + + + //Compute Start Indice: + unsigned uStartIndex = pFaceTessData->m_uiStartWire, uTemp; + for(uI = 0; uI < uEdgeIndice; uI++) + { + uTemp = pFaceTessData->m_puiSizesWires[uI]; + if(uTemp & kA3DTessFaceDataWireIsNotDrawn) + uTemp = uTemp & (~kA3DTessFaceDataWireIsNotDrawn); + if(uTemp & kA3DTessFaceDataWireIsClosing) + uTemp = uTemp & (~kA3DTessFaceDataWireIsClosing); + uStartIndex += uTemp; + + } + + A3DUns32* puiStartWireIndexes = m_pTessConnector->GetTess3DData()->m_puiWireIndexes + uStartIndex; + A3DUns32* puiCurrentWireIndexes = puiStartWireIndexes; + auEdgeIndice.resize(uNbVertices);// +(bClosed ? 1 : 0)); + + for(uI = 0; uI < uNbVertices; uI++) + { + auEdgeIndice[uI] = (*puiCurrentWireIndexes); + puiCurrentWireIndexes++; + } + + //if(bClosed) + // auEdgeIndice[uI] = (*puiStartWireIndexes); + return A3D_SUCCESS; +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +//A3DWireTessDataConnector +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +A3DWireTessDataConnector::A3DWireTessDataConnector(const A3DTess3DWire* psTessWire) +{ + A3D_INITIALIZE_DATA(A3DTess3DWireData, m_sWire3DTessData); + A3DTess3DWireGet(psTessWire, &m_sWire3DTessData); + A3D_INITIALIZE_DATA(A3DTessBaseData, m_sBaseTessData); + A3DTessBaseGet((const A3DTessBase*)psTessWire, &m_sBaseTessData); +} + + +A3DWireTessDataConnector::~A3DWireTessDataConnector() +{ + A3DTess3DWireGet(NULL, &m_sWire3DTessData); + A3DTessBaseGet(NULL, &m_sBaseTessData); +} + + +A3DStatus A3DWireTessDataConnector::Points(double*& pPoint, unsigned int& uSize) const +{ + pPoint = m_sBaseTessData.m_pdCoords; + uSize = m_sBaseTessData.m_uiCoordSize; + return A3D_SUCCESS; +} + +A3DStatus A3DWireTessDataConnector::Indices(std::vector& auPolylineIndices) const +{ + if(!m_sWire3DTessData.m_uiSizesWiresSize) + { + if(m_sBaseTessData.m_uiCoordSize) + { + auPolylineIndices.push_back(0); + auPolylineIndices.push_back(m_sBaseTessData.m_uiCoordSize / 3); + } + return A3D_SUCCESS; + } + + unsigned int uTemp; + auPolylineIndices.push_back(0); + for(unsigned uI = 0; uI < m_sWire3DTessData.m_uiSizesWiresSize; uI++) + { + uTemp = m_sWire3DTessData.m_puiSizesWires[uI]; + auPolylineIndices.push_back(uTemp); + uI += uTemp; + } + return A3D_SUCCESS; +} + +A3DStatus A3DWireTessDataConnector::Traverse(A3DVisitorContainer* psVisitor) +{ + + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + CHECK_RET(psVisitor->visitLeave(*this)); + + return A3D_SUCCESS; + +} diff --git a/exchange/exchangesource/Collision/visitor/TessConnector.h b/exchange/exchangesource/Collision/visitor/TessConnector.h new file mode 100644 index 0000000..7c0c6b7 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/TessConnector.h @@ -0,0 +1,147 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_TESS_CONNECTOR +#define A3D_TESS_CONNECTOR + +#include +#include "Connector.h" + +class A3DVisitorContainer; +class A3DTessDataConnector : public A3DConnector +{ + A3DTess3DData m_sTessData; + A3DTessBaseData m_sBaseTessData; + +public : + + A3DTessDataConnector(const A3DTess3D* pTess3D); + ~A3DTessDataConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor); + + unsigned FacesSize() const + { + return m_sTessData.m_uiFaceTessSize; + } + + A3DStatus Points(double*& pPoint, unsigned int& uSize) const; + + A3DStatus Normals(double*& pNormal, unsigned int& uSize) const; + + A3DStatus UV(double*& pUV, unsigned int& uSize) const; + + A3DTessBaseData const* GetBaseTessData() const { return &m_sBaseTessData; } + A3DTess3DData const* GetTess3DData() const { return &m_sTessData; } + + A3DStatus IndicesAsTriangle( + std::vector& auTriangleWithPoint_Normals_Indices, //normal, point,normal, point,..., point + std::vector& auTriangleWithPoint_Normals_UV_Indices //normal, point, UV, normal, point,UV, ..., normal,point, UV + ) const; + + A3DStatus IndicesPerFaceAsTriangle( + const unsigned& uFaceIndice, + std::vector& auTriangleWithPoint_Normals_Indices, + std::vector& auTriangleWithPoint_Normals_UV_Indices) const; + + A3DStatus Indices( + std::vector& auTrianglesOneNormal, //(normal, point, point,..., point) + std::vector& auFanOneNormal, + std::vector& auStripeOneNormal, + std::vector& auTrianglesWithNormals, //normal, point, ... , normal, point + std::vector& auFanWithNormals, + std::vector& auStripeWithNormal, + std::vector& auTrianglesOneNormalTexture, //normal,{texture...},point,{texture...},point,{texture...},point + std::vector& auFanOneNormalTextured, + std::vector& auStripeOneNormalTextured, + std::vector& auTrianglesWithNormalsTextured, //normal,{texture...},point,...,normal,{texture...},point + std::vector& auFanWithNormalsTextured, + std::vector& auStripeWithNormalsTextured) const; + + A3DStatus IndicesPerFace( + const unsigned& uFaceIndice, + std::vector& auTrianglesOneNormal, //(normal, point, point,..., point) + std::vector& auFanOneNormal, + std::vector& auStripeOneNormal, + std::vector& auTrianglesWithNormals, //normal, point, ... , normal, point + std::vector& auFanWithNormals, + std::vector& auStripeWithNormal, + std::vector& auTrianglesOneNormalTexture, //normal,{texture...},point,{texture...},point,{texture...},point + std::vector& auFanOneNormalTextured, + std::vector& auStripeOneNormalTextured, + std::vector& auTrianglesWithNormalsTextured,//normal,{texture...},point,...,normal,{texture...},point + std::vector& auFanWithNormalsTextured, + std::vector& auStripeWithNormalsTextured) const; +}; + + +class A3DFaceTessDataConnector : public A3DConnector +{ + const A3DTessDataConnector* m_pTessConnector; + unsigned m_uCurrentFaceIndex; + +public : + + A3DFaceTessDataConnector(const A3DTessFaceData* pFaceTess3D, unsigned uCurrentFaceIndex, const A3DTessDataConnector* pTessConnector); + ~A3DFaceTessDataConnector(); + + const A3DTessDataConnector* GetTessDataConnector() const { return m_pTessConnector; } + unsigned GetFaceIndex() const { return m_uCurrentFaceIndex; } + unsigned GetFaceNumber() const { return m_pTessConnector != NULL ? m_pTessConnector->FacesSize() : 0; } + + + A3DStatus Traverse(A3DVisitorContainer* psVisitor); + + A3DStatus IndicesAsTriangle( + std::vector& auTriangleWithPoint_Normals_Indices, //normal, point,normal, point,..., point + std::vector& auTriangleWithPoint_Normals_UV_Indices //normal, point, UV, normal, point,UV, ..., normal,point, UV + ) const; + + A3DStatus ColorsAsTriangle(std::vector& auTriangleWithPoint_Colors, bool &bIsRGBA) const; + + A3DStatus Indices( + std::vector& auTrianglesOneNormal, //(normal, point, point,..., point) + std::vector& auFanOneNormal, + std::vector& auStripeOneNormal, + std::vector& auTrianglesWithNormals, //normal, point, ... , normal, point + std::vector& auFanWithNormals, + std::vector& auStripeWithNormal, + std::vector& auTrianglesOneNormalTexture, //normal,{texture...},point,{texture...},point,{texture...},point + std::vector& auFanOneNormalTextured, + std::vector& auStripeOneNormalTextured, + std::vector& auTrianglesWithNormalsTextured, //normal,{texture...},point,...,normal,{texture...},point + std::vector& auFanWithNormalsTextured, + std::vector& auStripeWithNormalsTextured) const; + + unsigned GetWireNumber() const; + A3DStatus GetEdgeIndices(unsigned uEdgeIndice, std::vector& auEdgeIndice) const; +}; + + +class A3DWireTessDataConnector : public A3DConnector +{ + + A3DTess3DWireData m_sWire3DTessData; + A3DTessBaseData m_sBaseTessData; + +public: + + A3DWireTessDataConnector(const A3DTess3DWire* psTessWire); + ~A3DWireTessDataConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor); + + A3DStatus Points(double*& pPoint, unsigned int& uSize) const; + A3DStatus Indices(std::vector& auPolylineIndices) const; +}; + +#endif + diff --git a/exchange/exchangesource/Collision/visitor/TransfoConnector.cpp b/exchange/exchangesource/Collision/visitor/TransfoConnector.cpp new file mode 100644 index 0000000..b53b6aa --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/TransfoConnector.cpp @@ -0,0 +1,117 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "TransfoConnector.h" +#include "TreeTraverse.h" +#include "Matrix.h" + +static void stInitMatrixFromMiscTransformation(A3DMiscTransformation const * pMiscTransformation, A3DMatrix4x4 &sMatrix) +{ + if (pMiscTransformation) + { + A3DStatus iRet = A3D_SUCCESS; + A3DEEntityType eType = kA3DTypeUnknown; + A3DEntityGetType (pMiscTransformation, &eType); + + switch (eType) + { + case kA3DTypeMiscCartesianTransformation: + { + A3DMiscCartesianTransformationData sData; + A3D_INITIALIZE_DATA(A3DMiscCartesianTransformationData, sData); + + iRet = A3DMiscCartesianTransformationGet (pMiscTransformation, &sData); + + double dMirror = (sData.m_ucBehaviour & kA3DTransformationMirror) ? -1. : 1.; + + A3DVector3dData sZVector; + memset(sMatrix.m_adM, 0, 16 * sizeof(double)); + sZVector = CrossProduct(&(sData.m_sXVector), &(sData.m_sYVector)); + + sMatrix.m_adM[12] = sData.m_sOrigin.m_dX; + sMatrix.m_adM[13] = sData.m_sOrigin.m_dY; + sMatrix.m_adM[14] = sData.m_sOrigin.m_dZ; + + sMatrix.m_adM[0] = sData.m_sXVector.m_dX*sData.m_sScale.m_dX; + sMatrix.m_adM[1] = sData.m_sXVector.m_dY*sData.m_sScale.m_dX; + sMatrix.m_adM[2] = sData.m_sXVector.m_dZ*sData.m_sScale.m_dX; + + sMatrix.m_adM[4] = sData.m_sYVector.m_dX*sData.m_sScale.m_dY; + sMatrix.m_adM[5] = sData.m_sYVector.m_dY*sData.m_sScale.m_dY; + sMatrix.m_adM[6] = sData.m_sYVector.m_dZ*sData.m_sScale.m_dY; + + sMatrix.m_adM[8] = dMirror*sZVector.m_dX*sData.m_sScale.m_dZ; + sMatrix.m_adM[9] = dMirror*sZVector.m_dY*sData.m_sScale.m_dZ; + sMatrix.m_adM[10] = dMirror*sZVector.m_dZ*sData.m_sScale.m_dZ; + + sMatrix.m_adM[15] = 1.; + + iRet = A3DMiscCartesianTransformationGet (NULL, &sData); + } + break; + + case kA3DTypeMiscGeneralTransformation: + { + A3DMiscGeneralTransformationData sData; + A3D_INITIALIZE_DATA(A3DMiscGeneralTransformationData, sData); + + iRet = A3DMiscGeneralTransformationGet (pMiscTransformation, &sData); + + memcpy(&(sMatrix.m_adM[0]), sData.m_adCoeff, 16 * sizeof(double)); + + iRet = A3DMiscGeneralTransformationGet (NULL, &sData); + } + break; + + default: + break; + } + } +} + +A3DTransfoConnector::A3DTransfoConnector(const A3DMiscTransformation* pMiscTransformation) +: A3DConnector(pMiscTransformation) +{ + if (pMiscTransformation) + { + stInitMatrixFromMiscTransformation(pMiscTransformation, m_sLocalMatrix); + } + else + m_sLocalMatrix = stIdentity; +} + +void A3DTransfoConnector::ComputeGlobalMatrix(A3DMatrix4x4 const& rFatherWorldMatrix) +{ + m_sWorldMatrix = rFatherWorldMatrix * m_sLocalMatrix; +} + +void A3DTransfoConnector::SetGlobalMatrix(A3DMatrix4x4 const& rWorldMatrix) +{ + m_sWorldMatrix = rWorldMatrix; +} + +void A3DTransfoConnector::SetGlobalMatrix(A3DMiscTransformation const * pMiscTransformation) +{ + stInitMatrixFromMiscTransformation(pMiscTransformation, m_sWorldMatrix); +} + +A3DStatus A3DTransfoConnector::GetLocalMatrix( A3DMatrix4x4& rsMatrix ) +{ + rsMatrix = m_sLocalMatrix; + return A3D_SUCCESS; +} + +A3DStatus A3DTransfoConnector::GetGlobalTransfo(A3DMatrix4x4& rsMatrix) +{ + rsMatrix = m_sWorldMatrix; + return A3D_SUCCESS; +} + diff --git a/exchange/exchangesource/Collision/visitor/TransfoConnector.h b/exchange/exchangesource/Collision/visitor/TransfoConnector.h new file mode 100644 index 0000000..0b2ceea --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/TransfoConnector.h @@ -0,0 +1,44 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_TRANSFO_CONNECTOR +#define A3D_TRANSFO_CONNECTOR + +#include +#include "Connector.h" +#include "Matrix.h" + +class A3DVisitor; + + +class A3DTransfoConnector : public A3DConnector +{ + friend class A3DVisitorTransfo; + A3DMatrix4x4 m_sWorldMatrix; + A3DMatrix4x4 m_sLocalMatrix; + + void SetGlobalMatrix(A3DMiscTransformation const * pMiscTransformation); + void SetGlobalMatrix(A3DMatrix4x4 const& rWorldMatrix); + void ComputeGlobalMatrix(A3DMatrix4x4 const& rFatherWorldMatrix); + + A3DTransfoConnector(const A3DMiscTransformation* pMiscTransformation); + +public : + + ~A3DTransfoConnector() {} + + A3DStatus GetLocalMatrix(A3DMatrix4x4& rsMatrix); + + A3DStatus GetGlobalTransfo(A3DMatrix4x4& rsMatrix); + +}; + +#endif \ No newline at end of file diff --git a/exchange/exchangesource/Collision/visitor/TreeTraverse.cpp b/exchange/exchangesource/Collision/visitor/TreeTraverse.cpp new file mode 100644 index 0000000..347db50 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/TreeTraverse.cpp @@ -0,0 +1,701 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file TreeConnector.cpp + +This file contains fuctionalities to traverse a Prc Model Tree + +***********************************************************************************************************************/ + +#include + +#include "TreeTraverse.h" +#include "VisitorContainer.h" +#include "MarkupTraverse.h" +#include "ViewTraverse.h" + + +/************************************************************************************ + +Traverse Model File + +*************************************************************************************/ + +// Traverse all the model tree +A3DStatus A3DModelFileConnector::Traverse(A3DVisitorContainer* psVisitor, bool bVisitPrototype) +{ + unsigned int uI; + psVisitor->visitEnter(*this); + + for (uI = 0; uI < m_sModelFileData.m_uiPOccurrencesSize; uI++) + { + psVisitor->SetCurrentPoFather(NULL); + A3DProductOccurrenceConnector sTreeConnector(m_sModelFileData.m_ppPOccurrences[uI]); + if(sTreeConnector.TraversePO(m_sModelFileData.m_ppPOccurrences[uI], psVisitor, bVisitPrototype)!= A3D_SUCCESS) + return A3D_ERROR; + } + psVisitor->visitLeave(*this); + return A3D_SUCCESS; +} + + +/************************************************************************************ + +Traversing the assembly Structure + +*************************************************************************************/ + +A3DProductOccurrenceConnector::A3DProductOccurrenceConnector(const A3DAsmProductOccurrence* pProductOccurrence) + : A3DConnector(pProductOccurrence), + m_pProductOccurrenceDataSLW(NULL), + m_pProductOccurrenceDataCat(NULL), + m_pProductOccurrenceDataCV5(NULL), + m_pProductOccurrenceDataUg(NULL), + m_pProductOccurrenceDataProe(NULL), + m_pProductOccurrenceDataInv(NULL), + m_pProductOccurrenceDataJT(NULL) +{ + m_pFather = NULL; + m_bIsInstanciated = false; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, m_sProductOccurrenceData); + A3DAsmProductOccurrenceGet (pProductOccurrence, &m_sProductOccurrenceData); + + switch (m_sProductOccurrenceData.m_eModellerType) + { + case kA3DModellerSlw: + { + m_pProductOccurrenceDataSLW = (A3DAsmProductOccurrenceDataSLW*)malloc(sizeof(A3DAsmProductOccurrenceDataSLW)); + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceDataSLW, *m_pProductOccurrenceDataSLW); + A3DAsmProductOccurrenceGetSLW (pProductOccurrence, m_pProductOccurrenceDataSLW); + break; + } + + case kA3DModellerCatia: + { + m_pProductOccurrenceDataCat = (A3DAsmProductOccurrenceDataCat*)malloc(sizeof(A3DAsmProductOccurrenceDataCat)); + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceDataCat, *m_pProductOccurrenceDataCat); + A3DAsmProductOccurrenceGetCat (pProductOccurrence, m_pProductOccurrenceDataCat); + break; + } + + case kA3DModellerCatiaV5: + { + m_pProductOccurrenceDataCV5 = (A3DAsmProductOccurrenceDataCV5*)malloc(sizeof(A3DAsmProductOccurrenceDataCV5)); + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceDataCV5, *m_pProductOccurrenceDataCV5); + A3DAsmProductOccurrenceGetCV5 (pProductOccurrence, m_pProductOccurrenceDataCV5); + break; + } + + case kA3DModellerUnigraphics: + { + m_pProductOccurrenceDataUg = (A3DAsmProductOccurrenceDataUg*)malloc(sizeof(A3DAsmProductOccurrenceDataUg)); + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceDataUg, *m_pProductOccurrenceDataUg); + A3DAsmProductOccurrenceGetUg (pProductOccurrence, m_pProductOccurrenceDataUg); + break; + } + + case kA3DModellerProE: + { + m_pProductOccurrenceDataProe = (A3DAsmProductOccurrenceDataProe*)malloc(sizeof(A3DAsmProductOccurrenceDataProe)); + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceDataProe, *m_pProductOccurrenceDataProe); + A3DAsmProductOccurrenceGetProe (pProductOccurrence, m_pProductOccurrenceDataProe); + break; + } + + case kA3DModellerInventor: + { + m_pProductOccurrenceDataInv = (A3DAsmProductOccurrenceDataInv*)malloc(sizeof(A3DAsmProductOccurrenceDataInv)); + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceDataInv, *m_pProductOccurrenceDataInv); + A3DAsmProductOccurrenceGetInv (pProductOccurrence, m_pProductOccurrenceDataInv); + break; + } + + case kA3DModellerJt: + { + m_pProductOccurrenceDataJT = (A3DAsmProductOccurrenceDataJT*)malloc(sizeof(A3DAsmProductOccurrenceDataJT)); + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceDataJT, *m_pProductOccurrenceDataJT); + A3DAsmProductOccurrenceGetJT (pProductOccurrence, m_pProductOccurrenceDataJT); + break; + } + default: + break; + } + + m_bIsPrototype = false; + m_bIsExternal = false; +} + +A3DProductOccurrenceConnector::~A3DProductOccurrenceConnector() +{ + A3DAsmProductOccurrenceGet (NULL, &m_sProductOccurrenceData); + if (m_pProductOccurrenceDataSLW) + { + A3DAsmProductOccurrenceGetSLW (NULL, m_pProductOccurrenceDataSLW); + free(m_pProductOccurrenceDataSLW); + } + + if (m_pProductOccurrenceDataCat) + { + A3DAsmProductOccurrenceGetCat (NULL, m_pProductOccurrenceDataCat); + free(m_pProductOccurrenceDataCat); + } + + if (m_pProductOccurrenceDataCV5) + { + A3DAsmProductOccurrenceGetCV5 (NULL, m_pProductOccurrenceDataCV5); + free(m_pProductOccurrenceDataCV5); + } + + if (m_pProductOccurrenceDataUg) + { + A3DAsmProductOccurrenceGetUg (NULL, m_pProductOccurrenceDataUg); + free(m_pProductOccurrenceDataUg); + } + + if (m_pProductOccurrenceDataProe) + { + A3DAsmProductOccurrenceGetProe (NULL, m_pProductOccurrenceDataProe); + free(m_pProductOccurrenceDataProe); + } + + if (m_pProductOccurrenceDataInv) + { + A3DAsmProductOccurrenceGetInv (NULL, m_pProductOccurrenceDataInv); + free(m_pProductOccurrenceDataInv); + } + + if (m_pProductOccurrenceDataJT) + { + A3DAsmProductOccurrenceGetJT (NULL, m_pProductOccurrenceDataJT); + free(m_pProductOccurrenceDataJT); + } +} + +// Traversing the assembly Structure +A3DStatus A3DProductOccurrenceConnector::TraversePO(const A3DAsmProductOccurrence* pOccurrence, + A3DVisitorContainer* psVisitor, + bool bVisitPrototype) +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + //Traverse AnnotationEntity + A3DUns32 uI; +#ifdef CONNECT_PMI + if (psVisitor->GetFlagElementToConnect() & CONNECT_PMI) + { + A3DUns32 uNbAnnotationEntity = m_sProductOccurrenceData.m_uiAnnotationsSize; + for (uI = 0; uI < uNbAnnotationEntity; uI++) + { + A3DMkpAnnotationEntityConnector sAnnotationEntityConnector(m_sProductOccurrenceData.m_ppAnnotations[uI]); + sAnnotationEntityConnector.TraverseAnnotationEntity(psVisitor); + } + if (!uNbAnnotationEntity && m_sProductOccurrenceData.m_pPrototype != NULL) + { + A3DAsmProductOccurrence* pProductPrototype = m_sProductOccurrenceData.m_pPrototype; + while (pProductPrototype) + { + A3DAsmProductOccurrenceData sProductPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductPrototypeData); + CHECK_RET(A3DAsmProductOccurrenceGet (pProductPrototype, &sProductPrototypeData)); + uNbAnnotationEntity = sProductPrototypeData.m_uiAnnotationsSize; + for (uI = 0; uI < uNbAnnotationEntity; uI++) + { + A3DMkpAnnotationEntityConnector sAnnotationEntityConnector(sProductPrototypeData.m_ppAnnotations[uI]); + sAnnotationEntityConnector.TraverseAnnotationEntity(psVisitor); + } + + pProductPrototype = sProductPrototypeData.m_pPrototype; + CHECK_RET(A3DAsmProductOccurrenceGet (NULL, &sProductPrototypeData)); + } + } + } +#endif + +#ifdef CONNECT_VIEWS + if (psVisitor->GetFlagElementToConnect() & CONNECT_VIEWS) + { + A3DUns32 uNbView = m_sProductOccurrenceData.m_uiViewsSize; + if (!uNbView && m_sProductOccurrenceData.m_pPrototype != NULL) + { + A3DAsmProductOccurrence* pProductPrototype = m_sProductOccurrenceData.m_pPrototype; + while (pProductPrototype) + { + A3DAsmProductOccurrenceData sProductPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductPrototypeData); + CHECK_RET(A3DAsmProductOccurrenceGet (pProductPrototype, &sProductPrototypeData)); + uNbView = sProductPrototypeData.m_uiViewsSize; + for (uI = 0; uI < uNbView; uI++) + { + A3DMkpViewConnector sMkpViewConnector(sProductPrototypeData.m_ppViews[uI]); + sMkpViewConnector.TraverseView(psVisitor); + } + pProductPrototype = sProductPrototypeData.m_pPrototype; + CHECK_RET(A3DAsmProductOccurrenceGet (NULL, &sProductPrototypeData)); + } + } + else if (uNbView) + { + for (uI = 0; uI < uNbView; uI++) + { + A3DMkpViewConnector sMkpViewConnector(m_sProductOccurrenceData.m_ppViews[uI]); + sMkpViewConnector.TraverseView(psVisitor); + } + } + } + +#endif + +#ifdef CONNECT_FEATURE + if (psVisitor->GetFlagElementToConnect() & CONNECT_FEATURE) + { + A3DUns32 uNbFeatureBasedEntity = m_sProductOccurrenceData.m_uiFeatureBasedEntitiesSize; + if (!uNbFeatureBasedEntity && m_sProductOccurrenceData.m_pPrototype != NULL) + { + A3DAsmProductOccurrence* pProductPrototype = m_sProductOccurrenceData.m_pPrototype; + while (pProductPrototype) + { + A3DAsmProductOccurrenceData sProductPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductPrototypeData); + CHECK_RET(A3DAsmProductOccurrenceGet(pProductPrototype, &sProductPrototypeData)); + uNbFeatureBasedEntity = sProductPrototypeData.m_uiFeatureBasedEntitiesSize; + for (uI = 0; uI < uNbFeatureBasedEntity; uI++) + { + A3DFRMFeatureTreeConnector sConnector(sProductPrototypeData.m_ppFeatureBasedEntities[uI]); + sConnector.TraverseFeatureTree(psVisitor); + } + pProductPrototype = sProductPrototypeData.m_pPrototype; + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sProductPrototypeData)); + } + } + else if (uNbFeatureBasedEntity) + { + for (uI = 0; uI < uNbFeatureBasedEntity; uI++) + { + A3DFRMFeatureTreeConnector sConnector(m_sProductOccurrenceData.m_ppFeatureBasedEntities[uI]); + sConnector.TraverseFeatureTree(psVisitor); + } + } + } +#endif + A3DAsmPartDefinition* pPart = NULL; + if(!bVisitPrototype) + { + CHECK_RET(GetPart(pPart)); + } + else + { + pPart= m_sProductOccurrenceData.m_pPart; + } + if(pPart) + { + void * pEntityInMap = psVisitor->FindInMap(pPart); + psVisitor->SetInMap( pPart, pPart); + A3DPartConnector sPartConnector(pPart); + psVisitor->SetCurrentPoFather(pOccurrence); + sPartConnector.SetProductOccurrenceFather(pOccurrence); + + // if we haven't found the part in the map or if we traverse the instance + if(pEntityInMap==NULL || psVisitor->TraverseInstances()) + { + CHECK_RET(sPartConnector.TraversePart(psVisitor)); + } + psVisitor->SetCurrentPoFather(NULL); + } + std::vector apSons; + if(!bVisitPrototype) + { + CollectSons(apSons); + } + else + { + if(m_sProductOccurrenceData.m_pPrototype) + { + if(psVisitor->FindInMap(m_sProductOccurrenceData.m_pPrototype) == NULL) + { + psVisitor->SetInMap(m_sProductOccurrenceData.m_pPrototype, m_sProductOccurrenceData.m_pPrototype); + A3DProductOccurrenceConnector sPrototypeConnector(m_sProductOccurrenceData.m_pPrototype); + sPrototypeConnector.SetPrototypeType(true); + sPrototypeConnector.TraversePO(m_sProductOccurrenceData.m_pPrototype, psVisitor, bVisitPrototype); + } + } + if(m_sProductOccurrenceData.m_pExternalData) + { + if(psVisitor->FindInMap(m_sProductOccurrenceData.m_pExternalData) == NULL) + { + psVisitor->SetInMap(m_sProductOccurrenceData.m_pExternalData, m_sProductOccurrenceData.m_pExternalData); + A3DProductOccurrenceConnector sExternalConnector(m_sProductOccurrenceData.m_pExternalData); + sExternalConnector.SetExternalType(true); + sExternalConnector.TraversePO(m_sProductOccurrenceData.m_pExternalData, psVisitor, bVisitPrototype); + } + } + + + unsigned int uSize = m_sProductOccurrenceData.m_uiPOccurrencesSize; + + for( uI = 0; uI < uSize; uI++) + { + apSons.push_back(m_sProductOccurrenceData.m_ppPOccurrences[uI]); + } + } + + for (uI = 0; uI < apSons.size(); uI++) + { + A3DProductOccurrenceConnector sPoConnector(apSons[uI]); + sPoConnector.SetProductOccurrenceFather(this->GetA3DEntity()); + psVisitor->SetCurrentPoFather(pOccurrence); + CHECK_RET(sPoConnector.TraversePO(apSons[uI], psVisitor, bVisitPrototype)); + psVisitor->SetCurrentPoFather(NULL); + } + CHECK_RET(psVisitor->visitLeave(*this)); + + return A3D_SUCCESS; +} + +A3DStatus A3DProductOccurrenceConnector::CollectSons( + std::vector& apSons) const +{ + //Get Children or children on Prototype's ....Prototype's + A3DAsmProductOccurrence* pPrototype = m_sProductOccurrenceData.m_pPrototype; + A3DAsmProductOccurrence** ppPo = m_sProductOccurrenceData.m_ppPOccurrences; + unsigned int uSize = m_sProductOccurrenceData.m_uiPOccurrencesSize; + A3DStatus iRet = A3D_SUCCESS; + + while(uSize == 0 && pPrototype) + { + A3DAsmProductOccurrenceData sPrototypeData; + A3D_INITIALIZE_DATA( A3DAsmProductOccurrenceData, sPrototypeData); + CHECK_RET(A3DAsmProductOccurrenceGet(pPrototype, &sPrototypeData)); + pPrototype =sPrototypeData.m_pPrototype; + + uSize = sPrototypeData.m_uiPOccurrencesSize; + ppPo = sPrototypeData.m_ppPOccurrences; + + //TODO : Management of prototype with external assembly + //Not sur this can append. we don't have test files for validation. + /*if (pPrototype==NULL && sPrototypeData.m_pExternalData) + { + pPrototype=sPrototypeData.m_pExternalData; + }*/ + + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sPrototypeData)); + } + + unsigned uI; + for( uI = 0; uI < uSize; uI++) + apSons.push_back(ppPo[uI]); + + //Get Children on Externals + if(m_sProductOccurrenceData.m_pExternalData) + { + if(apSons.size() == 0) + { + A3DProductOccurrenceConnector sExternalConnector(m_sProductOccurrenceData.m_pExternalData); + CHECK_RET(sExternalConnector.CollectSons(apSons)); + } + else + apSons.push_back(m_sProductOccurrenceData.m_pExternalData); + } + + return A3D_SUCCESS; +} + +A3DStatus A3DProductOccurrenceConnector::GetPart( + A3DAsmPartDefinition*& pPart) const +{ + pPart = NULL; + A3DStatus iRet = A3D_SUCCESS;; + if(m_sProductOccurrenceData.m_pPart) + { + pPart = m_sProductOccurrenceData.m_pPart; + return A3D_SUCCESS; + } + + // Search for first Part found, recursively + A3DAsmProductOccurrence* pProductPrototype = m_sProductOccurrenceData.m_pPrototype; + while(pProductPrototype) + { + A3DAsmProductOccurrenceData sProductPrototypeData; + A3D_INITIALIZE_DATA( A3DAsmProductOccurrenceData, sProductPrototypeData); + CHECK_RET(A3DAsmProductOccurrenceGet(pProductPrototype, &sProductPrototypeData)); + if(sProductPrototypeData.m_pPart) + { + // take current part and return it + pPart = sProductPrototypeData.m_pPart; + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sProductPrototypeData)); + return A3D_SUCCESS; + } + else if (sProductPrototypeData.m_pPrototype) + { + // recurse in prototype if exist + pProductPrototype = sProductPrototypeData.m_pPrototype; + } + else if (sProductPrototypeData.m_pExternalData) + { + // recurse in external if exist + pProductPrototype = sProductPrototypeData.m_pExternalData; + } + else + { + // end recursion + pProductPrototype = NULL; + } + + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sProductPrototypeData)); + } + + if(m_sProductOccurrenceData.m_uiPOccurrencesSize == 0) + { + if(m_sProductOccurrenceData.m_pExternalData) + { + A3DProductOccurrenceConnector sExternalconnector(m_sProductOccurrenceData.m_pExternalData); + CHECK_RET(sExternalconnector.GetPart(pPart)); + } + } + return A3D_SUCCESS; +} + +A3DStatus A3DPartConnector::TraversePart(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + + CHECK_RET(psVisitor->visitEnter(*this)); + + //Traverse AnnotationEntity + A3DUns32 uI; +#ifdef CONNECT_PMI + if (psVisitor->GetFlagElementToConnect() & CONNECT_PMI) + { + A3DUns32 uNbAnnotationEntity = m_sPartData.m_uiAnnotationsSize; + for (uI = 0; uI < uNbAnnotationEntity; uI++) + { + A3DMkpAnnotationEntityConnector sAnnotationEntityConnector(m_sPartData.m_ppAnnotations[uI]); + sAnnotationEntityConnector.TraverseAnnotationEntity(psVisitor); + } + } +#endif + +#ifdef CONNECT_VIEWS + if (psVisitor->GetFlagElementToConnect() & CONNECT_VIEWS) + { + A3DUns32 uNbView = m_sPartData.m_uiViewsSize; + for (uI = 0; uI < uNbView; uI++) + { + A3DMkpViewConnector sMkpViewConnector(m_sPartData.m_ppViews[uI]); + sMkpViewConnector.TraverseView(psVisitor); + } + } +#endif + + //Traverse RI + for(uI = 0; uI < m_sPartData.m_uiRepItemsSize; uI++) + { + A3DRiConnector sRiConnector(m_sPartData.m_ppRepItems[uI]); + sRiConnector.TraverseRi(psVisitor); + } + + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +A3DStatus A3DRiConnector::TraverseRi(A3DVisitorContainer* psVisitor) +{ + A3DStatus iRet = A3D_SUCCESS; + psVisitor->visitEnter(*this); + + const A3DEntity* pRi = GetA3DEntity(); + A3DEEntityType eType=kA3DTypeUnknown; + A3DEntityGetType(pRi,&eType); + + if (iRet==A3D_SUCCESS) + { + switch(eType) + { + case kA3DTypeRiBrepModel: + { + A3DRiBrepModelConnector sConnector( static_cast(pRi)); + CHECK_RET(sConnector.TraverseRiBrepModel(psVisitor)); + break; + } + case kA3DTypeRiSet: + { + + A3DRiSetConnector sConnector(static_cast(pRi)); + CHECK_RET(sConnector.TraverseRiSet(psVisitor)); + break; + } + case kA3DTypeRiPointSet: + case kA3DTypeRiDirection: + case kA3DTypeRiCurve: + case kA3DTypeRiCoordinateSystem: + case kA3DTypeRiPlane: + break; + case kA3DTypeRiPolyBrepModel: + { + A3DPolyRiBrepModelConnector sConnector(static_cast(pRi)); + CHECK_RET(sConnector.TraverseRiPolyBrepModel(psVisitor)); + break; + } + default: + iRet=A3D_NOT_IMPLEMENTED; + break; + } + } + psVisitor->visitLeave(*this); + + return A3D_SUCCESS; +} + +// RiBrepModel +A3DStatus A3DRiBrepModelConnector::TraverseRiBrepModel(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + //Traverse Mesh +#ifdef CONNECT_MESH + if (psVisitor->GetFlagElementToConnect() & CONNECT_MESH) + { + A3DRiRepresentationItemData sRidata; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, sRidata); + CHECK_RET(A3DRiRepresentationItemGet (this->GetA3DEntity(), &sRidata)); + A3DTessDataConnector sTessConnector(static_cast(sRidata.m_pTessBase)); + CHECK_RET(sTessConnector.Traverse(psVisitor)); + CHECK_RET(A3DRiRepresentationItemGet (NULL, &sRidata)); + } +#endif + + //Traverse Brep Data +#ifdef CONNECT_BREP + if (psVisitor->GetFlagElementToConnect() & CONNECT_BREP) + { + A3DBrepDataConnector sTopoConnector(m_sRiBrepModelData.m_pBrepData); + CHECK_RET(sTopoConnector.Traverse(psVisitor)); + } + +#endif + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} + +// RiSet +A3DStatus A3DRiSetConnector::TraverseRiSet(A3DVisitorContainer* psVisitor) +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned uI; + for(uI = 0; uI < m_sRiSetData.m_uiRepItemsSize; uI++) + { + A3DRiConnector sRiConnector(m_sRiSetData.m_ppRepItems[uI]); + sRiConnector.TraverseRi(psVisitor); + } + + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} + +// RiPolyBrepModel +A3DStatus A3DPolyRiBrepModelConnector::TraverseRiPolyBrepModel( A3DVisitorContainer* psVisitor ) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + A3DRiRepresentationItemData sRiData; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, sRiData); + CHECK_RET(A3DRiRepresentationItemGet(this->GetA3DEntity(), &sRiData)); + A3DTessDataConnector sTessConnector(static_cast(sRiData.m_pTessBase)); + CHECK_RET(sTessConnector.Traverse(psVisitor)); + CHECK_RET(A3DRiRepresentationItemGet(NULL, &sRiData)); + + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} + +// A3DFRMParameter +A3DStatus A3DFRMFeatureConnector::TraverseFeature( A3DVisitorContainer* psVisitor ) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned uI; + + for (uI = 0; uI < m_sData.m_uiConnectionSize; uI++) + { + A3DFRMFeatureLinkedItemConnector sFeatureLinkedItemConnector(m_sData.m_ppConnections[uI]); + sFeatureLinkedItemConnector.TraverseConnection(psVisitor); + } + + + for (uI = 0; uI < m_sData.m_uiParametersSize; uI++) + { + A3DFRMParameterConnector sParameterConnector(m_sData.m_ppParameters[uI]); + sParameterConnector.TraverseParameter(psVisitor); + } + + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} + +// A3DFRMParameter +A3DStatus A3DFRMFeatureLinkedItemConnector::TraverseConnection( A3DVisitorContainer* psVisitor ) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + CHECK_RET(psVisitor->visitLeave(*this)); + return iRet; +} + +// A3DFRMParameter +A3DStatus A3DFRMParameterConnector::TraverseParameter( A3DVisitorContainer* psVisitor ) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned uI; + + for (uI = 0; uI < m_sData.m_uiFeatureSize; uI++) + { + A3DFRMFeatureConnector sFeatureConnector(m_sData.m_ppFeatures[uI]); + sFeatureConnector.TraverseFeature(psVisitor); + } + + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} + + +// FeatureTree +A3DStatus A3DFRMFeatureTreeConnector::TraverseFeatureTree( A3DVisitorContainer* psVisitor ) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned uI; + + for (uI = 0; uI < m_sTreeData.m_uiIntermediateGeometriesSize; uI++) + { + A3DRiConnector sRiConnector( m_sTreeData.m_ppIntermediateGeometries[uI]); + sRiConnector.TraverseRi(psVisitor); + } + + for (uI = 0; uI < m_sTreeData.m_uiParametersSize; uI++) + { + A3DFRMParameterConnector sParameterConnector( m_sTreeData.m_ppsParameters[uI]); + sParameterConnector.TraverseParameter(psVisitor); + } + + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} diff --git a/exchange/exchangesource/Collision/visitor/TreeTraverse.h b/exchange/exchangesource/Collision/visitor/TreeTraverse.h new file mode 100644 index 0000000..b03fd31 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/TreeTraverse.h @@ -0,0 +1,318 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_TREE_CONNECTOR +#define A3D_TREE_CONNECTOR + +#include +#include "Connector.h" +#include + + + +class A3DVisitorContainer; + class A3DModelFileConnector : public A3DConnector +{ +public : + + A3DModelFileConnector(const A3DAsmModelFile* pModelFile) : A3DConnector(pModelFile) + { + A3D_INITIALIZE_DATA( A3DAsmModelFileData, m_sModelFileData); + A3DAsmModelFileGet(pModelFile, &m_sModelFileData); + } + + ~A3DModelFileConnector() { A3DAsmModelFileGet(NULL, &m_sModelFileData); } + + A3DStatus Traverse(A3DVisitorContainer* psVisitor, bool bVisitPrototype = false); + +public : + + A3DAsmModelFileData m_sModelFileData; +}; + + +class A3DProductOccurrenceConnector : public A3DConnector +{ + friend class A3DModelFileConnector; + const A3DAsmProductOccurrence* m_pFather; + bool m_bIsInstanciated; + bool m_bIsPrototype; + bool m_bIsExternal; + +private : + + A3DProductOccurrenceConnector(const A3DAsmProductOccurrence* pProductOccurrence); + ~A3DProductOccurrenceConnector(); + + A3DStatus TraversePO(const A3DAsmProductOccurrence* pOccurrence, A3DVisitorContainer* psVisitor, bool bVisitPrototype = false); + + void SetProductOccurrenceFather(const A3DAsmProductOccurrence* pFather) { m_pFather = pFather; } + +public : + A3DStatus GetPart(A3DAsmPartDefinition*& pPart) const; + A3DStatus CollectSons(std::vector& apSons) const; + + A3DAsmProductOccurrenceData m_sProductOccurrenceData; + A3DAsmProductOccurrenceDataSLW *m_pProductOccurrenceDataSLW; + A3DAsmProductOccurrenceDataCat *m_pProductOccurrenceDataCat; + A3DAsmProductOccurrenceDataCV5 *m_pProductOccurrenceDataCV5; + A3DAsmProductOccurrenceDataUg *m_pProductOccurrenceDataUg; + A3DAsmProductOccurrenceDataProe *m_pProductOccurrenceDataProe; + A3DAsmProductOccurrenceDataInv *m_pProductOccurrenceDataInv; + A3DAsmProductOccurrenceDataJT *m_pProductOccurrenceDataJT; + + const A3DAsmProductOccurrence* GetProductOccurrenceFather() const { return m_pFather; } + void SetIsInstanciated(bool bIsInstanciated) { m_bIsInstanciated = bIsInstanciated; } + bool IsInstanciated() const { return m_bIsInstanciated; } + void SetPrototypeType(bool bIsPrototype) { m_bIsPrototype = bIsPrototype; } + bool IsProtoType() const { return m_bIsPrototype; } + void SetExternalType(bool bIsExternal) { m_bIsExternal = bIsExternal; } + bool IsExternal() const { return m_bIsExternal; } + +}; + + +class A3DPartConnector : public A3DConnector +{ + friend class A3DProductOccurrenceConnector; + const A3DAsmProductOccurrence* m_pFather; + bool m_bIsInstanciated; + + +private: + + A3DPartConnector(const A3DAsmPartDefinition *pPart) : A3DConnector(pPart) + { + m_pFather = NULL; + m_bIsInstanciated = false; + A3D_INITIALIZE_DATA(A3DAsmPartDefinitionData, m_sPartData); + A3DAsmPartDefinitionGet(pPart, &m_sPartData); + } + + ~A3DPartConnector() + { + A3DAsmPartDefinitionGet(NULL, &m_sPartData); + } + + + void SetProductOccurrenceFather(const A3DAsmProductOccurrence* pFather) { m_pFather = pFather; } + +public : + A3DStatus TraversePart(A3DVisitorContainer* psVisitor) const; + A3DAsmPartDefinitionData m_sPartData; + const A3DAsmProductOccurrence* GetProductOccurrenceFather() const { return m_pFather; } + void SetIsInstanciated(bool bIsInstanciated) { m_bIsInstanciated = bIsInstanciated; } + bool IsInstanciated() { return m_bIsInstanciated; } + +}; + +class A3DRiConnector : public A3DConnector +{ + friend class A3DPartConnector; + friend class A3DRiSetConnector; + friend class A3DFRMFeatureTreeConnector; + bool m_bIsInstanciated; +private: + + A3DRiConnector(const A3DRiRepresentationItem *pRi) : A3DConnector(pRi) + { + m_bIsInstanciated = false; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, m_sRiData); + A3DRiRepresentationItemGet(pRi, &m_sRiData); + } + + ~A3DRiConnector() + { + A3DRiRepresentationItemGet(NULL, &m_sRiData); + } + + A3DStatus TraverseRi(A3DVisitorContainer* psVisitor); + +public : + + A3DRiRepresentationItemData m_sRiData; + void SetIsInstanciated(bool bIsInstanciated) { m_bIsInstanciated = bIsInstanciated; } + bool IsInstanciated() { return m_bIsInstanciated; } +}; + + +class A3DRiBrepModelConnector : public A3DConnector +{ + friend class A3DRiConnector; +public : + + A3DRiBrepModelConnector(const A3DRiBrepModel *pRi) : m_pRiBrepModel(pRi), A3DConnector(pRi) + { + A3D_INITIALIZE_DATA(A3DRiBrepModelData, m_sRiBrepModelData); + A3DRiBrepModelGet(m_pRiBrepModel, &m_sRiBrepModelData); + } + + ~A3DRiBrepModelConnector() + { + A3DRiBrepModelGet(NULL, &m_sRiBrepModelData); + } + + A3DStatus TraverseRiBrepModel(A3DVisitorContainer* psVisitor) const; + +public : + A3DRiBrepModel const* m_pRiBrepModel; + A3DRiBrepModelData m_sRiBrepModelData; +}; + + + +class A3DRiSetConnector : public A3DConnector +{ + friend class A3DRiConnector; +private: + + A3DRiSetConnector(const A3DRiSet *pRi) : A3DConnector(pRi) + { + A3D_INITIALIZE_DATA(A3DRiSetData, m_sRiSetData); + A3DRiSetGet(pRi, &m_sRiSetData); + } + + ~A3DRiSetConnector() + { + A3DRiSetGet(NULL, &m_sRiSetData); + } + + A3DStatus TraverseRiSet(A3DVisitorContainer* psVisitor); + +public : + + A3DRiSetData m_sRiSetData; +}; + +class A3DPolyRiBrepModelConnector : public A3DConnector +{ + friend class A3DRiConnector; +private: + + A3DPolyRiBrepModelConnector(const A3DRiPolyBrepModel* pRi) : A3DConnector(pRi) + { + A3D_INITIALIZE_DATA(A3DRiPolyBrepModelData, m_sRiPolyBrepModelData); + A3DRiPolyBrepModelGet(pRi, &m_sRiPolyBrepModelData); + } + + ~A3DPolyRiBrepModelConnector() + { + A3DRiPolyBrepModelGet(NULL, &m_sRiPolyBrepModelData); + } + + + +public: + A3DStatus TraverseRiPolyBrepModel(A3DVisitorContainer* psVisitor) const; + A3DRiPolyBrepModelData m_sRiPolyBrepModelData; +}; + + +class A3DFRMParameterConnector : public A3DConnector +{ + friend class A3DFRMFeatureTreeConnector; + friend class A3DFRMFeatureConnector; +private: + + A3DFRMParameterConnector(const A3DFRMParameter *pParameter) : A3DConnector(pParameter) + { + A3D_INITIALIZE_DATA(A3DFRMParameterData, m_sData); + A3DFRMParameterGet (pParameter, &m_sData); + } + + ~A3DFRMParameterConnector() + { + A3DFRMParameterGet (NULL, &m_sData); + } + + +public: + + A3DFRMParameterData m_sData; + + A3DStatus TraverseParameter(A3DVisitorContainer* psVisitor) const; +}; + + +class A3DFRMFeatureLinkedItemConnector : public A3DConnector +{ + friend class A3DFRMFeatureConnector; +private: + + A3DFRMFeatureLinkedItemConnector(const A3DFRMLinkedItem *pLinkedItem) : A3DConnector(pLinkedItem) + { + A3D_INITIALIZE_DATA(A3DFRMLinkedItemData, m_sData); + A3DFRMLinkedItemGet (pLinkedItem, &m_sData); + } + + ~A3DFRMFeatureLinkedItemConnector() + { + A3DFRMLinkedItemGet (NULL, &m_sData); + } + + +public: + + A3DFRMLinkedItemData m_sData; + + A3DStatus TraverseConnection(A3DVisitorContainer* psVisitor) const; +}; + + + +class A3DFRMFeatureConnector : public A3DConnector +{ + friend class A3DFRMParameterConnector; +private: + + A3DFRMFeatureConnector(const A3DFRMFeature *pFeature) : A3DConnector(pFeature) + { + A3D_INITIALIZE_DATA(A3DFRMFeatureData, m_sData); + A3DFRMFeatureGet (pFeature, &m_sData); + } + + ~A3DFRMFeatureConnector() + { + A3DFRMFeatureGet (NULL, &m_sData); + } + + +public: + + A3DFRMFeatureData m_sData; + A3DStatus TraverseFeature(A3DVisitorContainer* psVisitor) const; + + +}; + +class A3DFRMFeatureTreeConnector : public A3DConnector +{ + friend class A3DProductOccurrenceConnector; +protected: + + A3DFRMFeatureTreeConnector(const A3DFRMTree *pTree) : A3DConnector(pTree) + { + A3D_INITIALIZE_DATA(A3DFRMTreeData, m_sTreeData); + A3DFRMTreeGet (pTree, &m_sTreeData); + } + + ~A3DFRMFeatureTreeConnector() + { + A3DFRMTreeGet (NULL, &m_sTreeData); + } + + A3DStatus TraverseFeatureTree(A3DVisitorContainer* psVisitor) const; + +public: + + A3DFRMTreeData m_sTreeData; +}; +#endif diff --git a/exchange/exchangesource/Collision/visitor/ViewTraverse.cpp b/exchange/exchangesource/Collision/visitor/ViewTraverse.cpp new file mode 100644 index 0000000..8e2a5bd --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/ViewTraverse.cpp @@ -0,0 +1,38 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file ViewTraverse.cpp + +This file contains functionalities to traverse a PRC View + +***********************************************************************************************************************/ + +#include "VisitorContainer.h" +#include "ViewTraverse.h" + +class A3DVisitorContainer; + +A3DStatus A3DMkpViewConnector::TraverseView(A3DVisitorContainer* pVisitor) +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(pVisitor->visitEnter(*this)); + + A3DUns32 uiI; + for (uiI = 0; uiIvisitLeave(*this)); + + return A3D_SUCCESS; +} diff --git a/exchange/exchangesource/Collision/visitor/ViewTraverse.h b/exchange/exchangesource/Collision/visitor/ViewTraverse.h new file mode 100644 index 0000000..ccf14de --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/ViewTraverse.h @@ -0,0 +1,45 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_VIEW_TRAVERSE +#define A3D_VIEW_TRAVERSE + +#include +#include "Connector.h" + + +class A3DVisitorContainer; + +class A3DMkpViewConnector : public A3DConnector +{ +public: + A3DMkpViewConnector(const A3DMkpView *pView) : A3DConnector(pView) + { + A3D_INITIALIZE_DATA( A3DMkpViewData, m_sViewData); + m_pView = pView; + A3DMkpViewGet(pView,&m_sViewData); + } + + ~A3DMkpViewConnector() + { + A3DMkpViewGet(NULL, &m_sViewData); + } + + A3DStatus TraverseView(A3DVisitorContainer* pVisitor); + + A3DMkpViewData const& GetViewData() const { return m_sViewData; } + A3DMkpView const* GetView() const { return m_pView; } + +private: + A3DMkpViewData m_sViewData; + A3DMkpView const* m_pView; +}; +#endif // A3D_VIEW_TRAVERSE \ No newline at end of file diff --git a/exchange/exchangesource/Collision/visitor/VisitorBrep.h b/exchange/exchangesource/Collision/visitor/VisitorBrep.h new file mode 100644 index 0000000..0bebb5e --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/VisitorBrep.h @@ -0,0 +1,65 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef VISIT_BREP +#define VISIT_BREP +#include "Visitors.h" +#include "BrepTraverse.h" +#include + +class A3DVisitorBrep : public A3DVisitor +{ +private: + std::map m_MapEdgeCoEdge; + double m_dScale; + +public: + + A3DVisitorBrep(A3DVisitorContainer* psContainer = NULL) : A3DVisitor("Brep", psContainer) { m_dScale = 1.0;} + + virtual A3DStatus visitEnter(const A3DRiConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DRiConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DBrepDataConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DBrepDataConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DConnexConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DConnexConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DShellConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DShellConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DFaceConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DFaceConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DLoopConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DLoopConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DCoEdgeConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DCoEdgeConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DEdgeConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DEdgeConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DUniqueVertexConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DUniqueVertexConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMultipleVertexConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMultipleVertexConnector&) { return A3D_SUCCESS; } + + double GetScale() const { return m_dScale;} + + std::map & GetMapEdgeCoEdge() { return m_MapEdgeCoEdge;} + +}; + + +#endif //VISIT_TOPO \ No newline at end of file diff --git a/exchange/exchangesource/Collision/visitor/VisitorCascadedAttribute.cpp b/exchange/exchangesource/Collision/visitor/VisitorCascadedAttribute.cpp new file mode 100644 index 0000000..077537b --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/VisitorCascadedAttribute.cpp @@ -0,0 +1,286 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "VisitorCascadedAttribute.h" +#include "CascadedAttributeConnector.h" +#include "VisitorTree.h" + +A3DVisitorColorMaterials::A3DVisitorColorMaterials(A3DVisitorContainer* psContainer) +: A3DVisitor("CascadedAttribute", psContainer), + m_pCurrentRi(NULL) +{ +} + +A3DVisitorColorMaterials::~A3DVisitorColorMaterials() +{ + std::vector::iterator itCur = m_apsCascadedAttribute.begin(); + std::vector::iterator itEnd = m_apsCascadedAttribute.end(); + for(; itCur < itEnd; ++itCur) + { + A3DMiscCascadedAttributesDelete(*itCur); + } +} + +A3DStatus A3DVisitorColorMaterials::pushCascadedAttribute(const A3DConnector& sEntity) +{ + unsigned int uSize = (unsigned int)m_apsCascadedAttribute.size(); + A3DInt32 iRet = A3D_SUCCESS; + if(!uSize) + { + A3DMiscCascadedAttributes* pAttr; + iRet = A3DMiscCascadedAttributesCreate(&pAttr); + m_apsCascadedAttribute.push_back(pAttr); + uSize++; + } + + A3DMiscCascadedAttributes* pAttr; + iRet = A3DMiscCascadedAttributesCreate(&pAttr); + iRet = A3DMiscCascadedAttributesPush(pAttr, sEntity.GetA3DEntity(), m_apsCascadedAttribute[uSize-1]); + m_apsCascadedAttribute.push_back(pAttr); + + return A3D_SUCCESS; +} + + +A3DStatus A3DVisitorColorMaterials::popCascadedAttribute(/*const A3DConnector& sEntity*/) +{ + if(m_apsCascadedAttribute.size() > 0) + { + A3DMiscCascadedAttributesDelete(m_apsCascadedAttribute[m_apsCascadedAttribute.size() - 1]); + m_apsCascadedAttribute.pop_back(); + } + + return A3D_SUCCESS; +} + +// Visit Product Occurrence +A3DStatus A3DVisitorColorMaterials::visitEnter(const A3DProductOccurrenceConnector& sEntity) +{ + pushCascadedAttribute( (const A3DConnector&) sEntity); + + /* A3DEEntityType eType; + A3DEntityGetType( sEntity.m_sProductOccurrenceData.m_ppEntityReferences[uI], &eType); + if(eType == kA3DTypeMiscEntityReference) + { + A3DMiscReferenceOnTopologyData sTopoRefData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnTopologyData,sTopoRefData); + A3DMiscReferenceOnTopologyGet(sEntity.m_sProductOccurrenceData.m_ppEntityReferences[uI], + &sTopoRefData); + // Get Entity Target: sTopoRefData.m_pBrepData, Edge, Face, Vertex + //Add also systematically the 3DTessData or Face Tess Data + //add in the Visitor container Map + + + // kA3DTypeTopoMultipleVertex + // kA3DTypeTopoUniqueVertex + // kA3DTypeTopoWireEdge + // kA3DTypeTopoEdge + // kA3DTypeTopoLoop + // kA3DTypeTopoFace + // kA3DTypeTopoShell + // kA3DTypeTopoConnex + + A3DMiscReferenceOnTopologyGet(NUL, + &sTopoRefData)); + + + A3DTopoBrepData* pBrepData = sTopoRefData.m_pBrepData; + A3DTopoBrepDataData sTopoBrepDataData; + A3D_INITIALIZE_DATA( A3DTopoBrepDataData,sTopoBrepDataData); + A3DTopoBrepDataGet(pBrepData,&sTopoBrepDataData); + unsigned int unbconnex = sTopoBrepDataData.m_uiConnexSize; + } + }*/ + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorColorMaterials::visitLeave(const A3DProductOccurrenceConnector& /*sEntity*/) +{ + popCascadedAttribute(); + return A3D_SUCCESS; +} + +// Visit PartDefintion +A3DStatus A3DVisitorColorMaterials::visitEnter(const A3DPartConnector& sEntity) +{ + pushCascadedAttribute((const A3DConnector& ) sEntity); + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorColorMaterials::visitLeave(const A3DPartConnector& /*sEntity*/) +{ + popCascadedAttribute(); + return A3D_SUCCESS; +} + +// Visit Representation Item +A3DStatus A3DVisitorColorMaterials::visitEnter(const A3DRiConnector& sRi) +{ + A3DStatus iRet = A3D_SUCCESS; + m_pCurrentRi = (A3DRiRepresentationItem*)sRi.GetA3DEntity(); + CHECK_RET(pushCascadedAttribute((const A3DConnector&) sRi)); + CHECK_RET(SetGlobalAttributeOnLeaf(m_apsCascadedAttribute[ m_apsCascadedAttribute.size() - 1])); + return iRet; +} + +A3DStatus A3DVisitorColorMaterials::visitLeave(const A3DRiConnector& /*sRi*/) +{ + A3DStatus iRet = A3D_SUCCESS; + m_pCurrentRi = NULL; + CHECK_RET(popCascadedAttribute()); + return A3D_SUCCESS; +} + +// Visit Face Tess Data +A3DStatus A3DVisitorColorMaterials::visitEnter(const A3DFaceTessDataConnector& sFaceTess) +{ + A3DStatus iRet = A3D_SUCCESS; + A3DTessFaceData* pFaceTessData = (A3DTessFaceData*)sFaceTess.GetA3DEntity(); + + if(m_pCurrentRi && !pFaceTessData->m_bIsRGBA && pFaceTessData->m_uiStyleIndexesSize == 1) + { + //CHECK_RET(pushCascadedAttribute((const A3DConnector&) sRi)); + //home made push for tess face + A3DMiscCascadedAttributes* pAttr; + iRet = A3DMiscCascadedAttributesCreate(&pAttr); + iRet = A3DMiscCascadedAttributesPushTessFace(pAttr, + m_pCurrentRi, + (A3DTess3D*)sFaceTess.GetTessDataConnector()->GetA3DEntity(), + (A3DTessFaceData*)sFaceTess.GetA3DEntity(), + sFaceTess.GetFaceIndex(), + m_apsCascadedAttribute[m_apsCascadedAttribute.size()-1]); + m_apsCascadedAttribute.push_back(pAttr); + + CHECK_RET(SetGlobalAttributeOnLeaf(m_apsCascadedAttribute[ m_apsCascadedAttribute.size() - 1])); + } + return iRet; +} + +A3DStatus A3DVisitorColorMaterials::visitLeave(const A3DFaceTessDataConnector& sFaceTess) +{ + A3DStatus iRet = A3D_SUCCESS; + A3DTessFaceData* pFaceTessData = (A3DTessFaceData*)sFaceTess.GetA3DEntity(); + if(!pFaceTessData->m_bIsRGBA && pFaceTessData->m_uiStyleIndexesSize == 1) + { + CHECK_RET(popCascadedAttribute()); + } + return A3D_SUCCESS; +} + +A3DMiscCascadedAttributes* A3DVisitorColorMaterials::GetLastCascadedAttributes() const +{ + size_t iSize = m_apsCascadedAttribute.size(); + if(iSize == 0) + return NULL; + return m_apsCascadedAttribute[iSize-1]; +} + +A3DStatus A3DVisitorColorMaterials::GetColorMaterialConnector( ColorMaterialsConnector& rsColorConnector, + bool bUseInstances /*= false*/ ) +{ + A3DStatus iErr = A3D_SUCCESS; + size_t iSize = m_apsCascadedAttribute.size(); + if(iSize == 0) + return A3D_ERROR; + A3DMiscCascadedAttributes* pCurrent = m_apsCascadedAttribute[iSize-1]; + + if(!bUseInstances) + { + A3DMiscEntityReference* pMER = NULL; + A3DStepEntityRefManager const * pSERM = m_psContainer->GetActiveStepEntityRefManager(NULL); + if (pSERM) + { + pMER = pSERM->m_pStepEntityRef; + } + + A3DViewLinkedItemManager const* pVLIM = m_psContainer->GetActiveViewLinkedItemManager(NULL); + if (pVLIM) + { + pMER = pVLIM->m_pMarkupLinkedItem; + } + + if (pMER) + { + A3DMiscEntityReferenceData sSERData; + A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sSERData); + iErr = A3DMiscEntityReferenceGet(pMER, &sSERData); + if(iErr == A3D_SUCCESS) + { + A3DEEntityType eType; + A3DEntityGetType( pMER, &eType); + if(eType == kA3DTypeMiscEntityReference || eType==kA3DTypeMiscMarkupLinkedItem) + { + A3DMiscReferenceOnTopologyData sTopoRefData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnTopologyData,sTopoRefData); + iErr = A3DMiscReferenceOnTopologyGet(pMER, &sTopoRefData); + if(iErr == A3D_SUCCESS) // topo + { + switch(sTopoRefData.m_eTopoItemType) + { + case kA3DTypeTopoMultipleVertex: + case kA3DTypeTopoUniqueVertex: + case kA3DTypeTopoWireEdge: + case kA3DTypeTopoEdge: + case kA3DTypeTopoLoop: + break; + case kA3DTypeTopoFace: + { + A3DTopoBrepData* pBrepData = sTopoRefData.m_pBrepData; + A3DTopoBrepDataData sTopoBrepDataData; + A3D_INITIALIZE_DATA( A3DTopoBrepDataData,sTopoBrepDataData); + A3DTopoBrepDataGet(pBrepData,&sTopoBrepDataData); + + A3DTopoBrepDataGet(NULL,&sTopoBrepDataData); + + break; + } + case kA3DTypeTopoShell: + { + break; + } + case kA3DTypeTopoConnex: + { + break; + } + default: + { + break; + } + } + } + else // no topo -> global PO/Part/RI/RIBrepModel + { + A3DEEntityType eLType; + A3DEntityGetType( sSERData.m_pEntity, &eLType); + + //A3DGraphStyleData + A3DMiscCascadedAttributes* pAttr = NULL; + A3DMiscCascadedAttributesCreate(&pAttr); + iErr = A3DMiscCascadedAttributesPush(pAttr, pMER, pCurrent); + A3DMiscCascadedAttributesData sCAData; + A3D_INITIALIZE_DATA(A3DMiscCascadedAttributesData, sCAData); + iErr = A3DMiscCascadedAttributesGet(pAttr, &sCAData); + rsColorConnector = ColorMaterialsConnector(pAttr); + A3DMiscCascadedAttributesDelete (pAttr); + } + + A3DMiscReferenceOnTopologyGet(NULL,&sTopoRefData); + } + A3DMiscEntityReferenceGet( NULL, &sSERData); + } + } + else + rsColorConnector = ColorMaterialsConnector(pCurrent); + } + + return A3D_SUCCESS; +} diff --git a/exchange/exchangesource/Collision/visitor/VisitorCascadedAttribute.h b/exchange/exchangesource/Collision/visitor/VisitorCascadedAttribute.h new file mode 100644 index 0000000..e00a552 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/VisitorCascadedAttribute.h @@ -0,0 +1,76 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef VISITOR_CASCADED_ATTRIBUTE +#define VISITOR_CASCADED_ATTRIBUTE +#include "Visitors.h" +#include + +class A3DCascadedAttribute; +class ColorMaterialsConnector; + +class A3DVisitorColorMaterials : public A3DVisitor +{ +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) // Suppress the warning C4251 because it leads to have that kind of warning : "warning + // C4251: 'A3DVisitorColorMaterials::m_apsCascadedAttribute' : class 'std::vector<_Ty>' needs to have dll-interface to + // be used by clients of class 'A3DVisitorColorMaterials" + // This is because of the "dllexport" on the visitor classes, as they use stl members and it seems that stl causes + // warning with dllexport with microsoft compiler +#endif // _MSC_VER + + //friend class A3DVisitorContainer; + std::vector m_apsCascadedAttribute; + A3DRiRepresentationItem* m_pCurrentRi; //needed for FaceTessDataConnector + +#ifdef _MSC_VER +#pragma warning(pop) +#endif // _MSC_VER + +public: + + A3DVisitorColorMaterials(A3DVisitorContainer* psContainer = NULL); + + virtual ~A3DVisitorColorMaterials(); + + virtual A3DStatus pushCascadedAttribute(const A3DConnector& sEntity); + virtual A3DStatus visitEnter(const A3DProductOccurrenceConnector& sEntity); + virtual A3DStatus visitEnter(const A3DPartConnector& sEntity); + virtual A3DStatus visitEnter(const A3DRiConnector& sEntity); + virtual A3DStatus visitEnter(const A3DFaceTessDataConnector& sEntity); + + virtual A3DStatus popCascadedAttribute(/*const A3DConnector& sEntity*/); + virtual A3DStatus visitLeave(const A3DProductOccurrenceConnector& sEntity); + virtual A3DStatus visitLeave(const A3DPartConnector& sEntity); + virtual A3DStatus visitLeave(const A3DRiConnector& sEntity); + virtual A3DStatus visitLeave(const A3DFaceTessDataConnector& sEntity); + + std::vector _Get() const { return m_apsCascadedAttribute; } + void _Set(std::vector const & val) { m_apsCascadedAttribute = val; } + void _SetCurrentRi(A3DRiRepresentationItem* const val) { m_pCurrentRi = val; } + +public: + + /////////////////////////////////////////////////////////////////// + // Please, redefined this function in a inherited class to connect + // the meshes provide by 3DX in your application + ////////////////////////////////////////////////////////////////// + + virtual A3DStatus SetGlobalAttributeOnLeaf(const A3DMiscCascadedAttributes* /*psCascadedAttribute*/) { return A3D_SUCCESS; } + + A3DStatus GetColorMaterialConnector(ColorMaterialsConnector& rsColorConnector, bool bUseInstances = false); + + A3DMiscCascadedAttributes* GetLastCascadedAttributes() const; + +}; + +#endif diff --git a/exchange/exchangesource/Collision/visitor/VisitorContainer.cpp b/exchange/exchangesource/Collision/visitor/VisitorContainer.cpp new file mode 100644 index 0000000..2eeb666 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/VisitorContainer.cpp @@ -0,0 +1,631 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "VisitorContainer.h" +#include "Visitors.h" + +#ifdef CONNECT_BREP +#include "VisitorBrep.h" +#endif +#ifdef CONNECT_TRANSFO +#include "VisitorTransfo.h" +#endif +#ifdef CONNECT_COLORS +#include "VisitorCascadedAttribute.h" +#endif +#ifdef CONNECT_ASSEMBLY_TREE +#include "VisitorTree.h" +#endif +#ifdef CONNECT_MESH +#include "VisitorTessellation.h" +#endif +#ifdef CONNECT_PMI +//#include +#endif +#ifdef CONNECT_PMI +#include "ViewTraverse.h" +#endif + +#include +#include +#include + +using namespace std; + +#define VISITENTER \ +{\ + ActivateEntityReference(sConnector.GetA3DEntity()); \ + for(unsigned uI = 0; uI < m_apVisitor.size(); uI++)\ + m_apVisitor[uI]->visitEnter(sConnector);\ + return A3D_SUCCESS;\ +} + +#define VISITLEAVE \ +{\ + DeactivateEntityReference(sConnector.GetA3DEntity()); \ + for(unsigned uI = 0; uI < m_apVisitor.size(); uI++)\ + m_apVisitor[uI]->visitLeave(sConnector);\ + return A3D_SUCCESS;\ +} + +//Tree +#ifdef CONNECT_ASSEMBLY_TREE + +// static A3DStatus stCreateAndPushCascadedAttributes( const A3DRootBaseWithGraphics* pBase, +// const A3DMiscCascadedAttributes* pFatherAttr, +// A3DMiscCascadedAttributes** ppAttr, +// A3DMiscCascadedAttributesData* psAttrData) +// { +// A3DStatus iRet = A3D_SUCCESS; +// +// CHECK_RET(A3DMiscCascadedAttributesCreate(ppAttr)); +// CHECK_RET(A3DMiscCascadedAttributesPush(*ppAttr, pBase, pFatherAttr)); +// +// A3D_INITIALIZE_DATA(A3DMiscCascadedAttributesData, (*psAttrData)); +// CHECK_RET(A3DMiscCascadedAttributesGet(*ppAttr, psAttrData)); +// +// return iRet; +// } + +A3DStatus A3DVisitorContainer::visitEnter(const A3DModelFileConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitEnter(const A3DProductOccurrenceConnector& sConnector) +{ + m_uiCurrentLevel++; + + // Entity Reference + unsigned int uI, uNbRefEntity = sConnector.m_sProductOccurrenceData.m_uiEntityReferenceSize; + for(uI = 0; uI < uNbRefEntity; uI++) + { + A3DMiscEntityReferenceData sMiscRefData; + A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sMiscRefData); + A3DMiscEntityReference* pEntityRef = sConnector.m_sProductOccurrenceData.m_ppEntityReferences[uI]; + A3DMiscEntityReferenceGet (pEntityRef, &sMiscRefData); + A3DStepEntityRefManager sEntityManager; + sEntityManager.m_pStepEntityRef = pEntityRef; + sEntityManager.m_uiPOLevel = m_uiCurrentLevel; + + A3DEEntityType sType; + A3DEntityGetType (sMiscRefData.m_pEntity, &sType); + if(sType == kA3DTypeMiscReferenceOnTopology) + { + A3DMiscReferenceOnTopologyData sTopoRefData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnTopologyData,sTopoRefData); + A3DMiscReferenceOnTopologyGet (pEntityRef, &sTopoRefData); + sEntityManager.m_pA3DEntityRef = sTopoRefData.m_pBrepData; + sEntityManager.m_bRefOnTopoItem = true; + A3DMiscReferenceOnTopologyGet (NULL, &sTopoRefData); + } + else if(sType == kA3DTypeMiscReferenceOnCsysItem) + { + A3DMiscReferenceOnCsysItemData sA3DMiscReferenceOnCSYSITemData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnCsysItemData, sA3DMiscReferenceOnCSYSITemData); + A3DMiscReferenceOnCsysItemGet (pEntityRef, &sA3DMiscReferenceOnCSYSITemData); + sEntityManager.m_pA3DEntityRef = sA3DMiscReferenceOnCSYSITemData.m_pCoordinateSystem; + A3DMiscReferenceOnCsysItemGet (NULL, &sA3DMiscReferenceOnCSYSITemData); + } + else + sEntityManager.m_pA3DEntityRef = sMiscRefData.m_pEntity; + + A3DMiscEntityReferenceGet (NULL, &sMiscRefData); + + m_asStepEntityRefManager.push_back(sEntityManager); + } + + A3DStatus iRet = A3D_SUCCESS; + + // Active View ... + if (m_psActivatedView) + { + A3DUns32 uNbView = sConnector.m_sProductOccurrenceData.m_uiViewsSize; + for (uI = 0; uI < uNbView; uI++) + { + if (sConnector.m_sProductOccurrenceData.m_ppViews[uI] != m_psActivatedView) + continue; + + A3DMkpViewConnector sMkpViewConnector(sConnector.m_sProductOccurrenceData.m_ppViews[uI]); + sMkpViewConnector.TraverseView(this); + } + } + + ActivateEntityReference(sConnector.GetA3DEntity()); + for( uI = 0; uI < m_apVisitor.size(); uI++) + { + m_apVisitor[uI]->visitEnter(sConnector); + } + + return iRet; +} + +A3DStatus A3DVisitorContainer::visitEnter(const A3DPartConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DRiConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DRiBrepModelConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DRiSetConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DPolyRiBrepModelConnector& sConnector) +VISITENTER + + +A3DStatus A3DVisitorContainer::visitLeave(const A3DModelFileConnector& sConnector) +VISITLEAVE + +A3DStatus A3DVisitorContainer::visitLeave(const A3DProductOccurrenceConnector& sConnector) +{ + for(unsigned uI = 0; uI < m_apVisitor.size(); uI++) + { + m_apVisitor[uI]->visitLeave(sConnector); + } + + unsigned int uI, uNbRefEntity = sConnector.m_sProductOccurrenceData.m_uiEntityReferenceSize; + for (uI = 0; uI < uNbRefEntity; uI++) + { + m_asStepEntityRefManager.pop_back(); + } + + if (m_psActivatedView != NULL) + { + A3DUns32 uNbView = sConnector.m_sProductOccurrenceData.m_uiViewsSize; + for (uI = 0; uI < uNbView; uI++) + { + if (sConnector.m_sProductOccurrenceData.m_ppViews[uI]!=m_psActivatedView) + continue; + + A3DMkpViewConnector sViewConnector(m_psActivatedView); + unsigned int uJ; + uNbRefEntity = sViewConnector.GetViewData().m_uiLinkedItemsSize; + for (uJ = 0; uJ < uNbRefEntity; uJ++) + { + m_asViewLinkedItemManager.pop_back(); + } + } + } + + DeactivateEntityReference(sConnector.GetA3DEntity()); + + m_uiCurrentLevel--; + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorContainer::visitLeave(const A3DPartConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DRiConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DRiBrepModelConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DRiSetConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DPolyRiBrepModelConnector& sConnector) +VISITLEAVE +#endif + +//Markup +#ifdef CONNECT_PMI +A3DStatus A3DVisitorContainer::visitEnter(const A3DMkpAnnotationEntityConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMkpAnnotationSetConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMkpAnnotationItemConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMarkupConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMarkupDimensionConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMarkupGDTConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMarkupDatumConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitLeave(const A3DMkpAnnotationEntityConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMkpAnnotationSetConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMkpAnnotationItemConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMarkupDimensionConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMarkupConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMarkupGDTConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMarkupDatumConnector& sConnector) +VISITLEAVE +#endif + +//Brep +#ifdef CONNECT_BREP +A3DStatus A3DVisitorContainer::visitEnter(const A3DBrepDataConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DConnexConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DShellConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DFaceConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DLoopConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DCoEdgeConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DEdgeConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DUniqueVertexConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMultipleVertexConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitLeave(const A3DBrepDataConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DConnexConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DShellConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DFaceConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DLoopConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DCoEdgeConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DEdgeConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DUniqueVertexConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMultipleVertexConnector& sConnector) +VISITLEAVE +#endif + +//Mesh +#ifdef CONNECT_MESH +A3DStatus A3DVisitorContainer::visitEnter(const A3DTessDataConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitLeave(const A3DTessDataConnector& sConnector) +VISITLEAVE + +A3DStatus A3DVisitorContainer::visitEnter(const A3DFaceTessDataConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitLeave(const A3DFaceTessDataConnector& sConnector) +VISITLEAVE + +//VISIT(const A3DTessDataConnector&) +#endif + +A3DVisitorContainer::A3DVisitorContainer(unsigned int uFlagElementToconnect) +: A3DVisitor("Container"), + m_pTreeVisitor(NULL), + m_pCurrentPOFather(NULL), + m_psActivatedView(NULL), + m_bTraverseActivatedViewOnly(true), + m_uiCurrentLevel(0), + m_uFlagElementToConnect(uFlagElementToconnect), + m_bTraverseInstance(false) +{ +#ifdef CONNECT_TRANSFO + if(uFlagElementToconnect&CONNECT_TRANSFO) + { + A3DVisitorTransfo* psVisistorTransfo = new A3DVisitorTransfo(this); + this->push( psVisistorTransfo); + } +#endif +#ifdef CONNECT_COLORS + if(uFlagElementToconnect&CONNECT_COLORS) + { + A3DVisitorColorMaterials* psVisitorcascadedAttribute = new A3DVisitorColorMaterials(this); + this->push( psVisitorcascadedAttribute); + } +#endif +#ifdef CONNECT_MESH + if(uFlagElementToconnect&CONNECT_MESH) + { + A3DVisitorTessellation* psVisitorTessellation = new A3DVisitorTessellation(this); + this->push( psVisitorTessellation); + } +#endif +#ifdef CONNECT_BREP + if(uFlagElementToconnect&CONNECT_BREP) + { + A3DVisitorBrep* psVisitorBrep = new A3DVisitorBrep(this); + this->push( psVisitorBrep); + } +#endif +#ifdef CONNECT_ASSEMBLY_TREE + if(uFlagElementToconnect&CONNECT_ASSEMBLY_TREE) + { + A3DTreeVisitor* psVisitorTree= new A3DTreeVisitor(this); + this->push( psVisitorTree); + } +#endif +#ifdef CONNECT_PMI + if(uFlagElementToconnect&CONNECT_PMI) + { + //A3DVisitorPMI* psVisitorPMI = new A3DVisitorPMI(this); + //this->push( psVisitorPMI ); + } +#endif +#ifdef CONNECT_VIEWS + if(uFlagElementToconnect&CONNECT_VIEWS) + { + // Not yet Implemented + // A3DVisitorview* psVisitorViews = new A3DVisitorview(this); + // this->push( psVisitorViews); + } +#endif +} + +#ifdef CONNECT_VIEWS + +A3DStatus A3DVisitorContainer::visitEnter(const A3DMkpViewConnector& sConnector) +{ + if ((m_psActivatedView == NULL) || (m_psActivatedView != sConnector.GetA3DEntity())) + { + if (!m_bTraverseActivatedViewOnly) + { + VISITENTER; + } + + return A3D_SUCCESS; + } + + // VISITENTER + ActivateEntityReference(sConnector.GetA3DEntity()); + for (unsigned uI = 0; uI < m_apVisitor.size(); uI++) + { + m_apVisitor[uI]->visitEnter(sConnector); + } + + unsigned int uI, uNbRefEntity = sConnector.GetViewData().m_uiLinkedItemsSize; + for (uI = 0; uI < uNbRefEntity; uI++) + { + A3DMiscMarkupLinkedItemData sMkpLinkedItemData; + A3D_INITIALIZE_DATA(A3DMiscMarkupLinkedItemData, sMkpLinkedItemData); + A3DMiscMarkupLinkedItem* pMkpLinkedItemEntityRef = sConnector.GetViewData().m_ppLinkedItems[uI]; + A3DMiscMarkupLinkedItemGet (pMkpLinkedItemEntityRef, &sMkpLinkedItemData); + A3DViewLinkedItemManager sViewLinkedItemManager; + + A3DMiscEntityReferenceData sMiscRefData; + A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sMiscRefData); + A3DMiscEntityReferenceGet (pMkpLinkedItemEntityRef, &sMiscRefData); + + sViewLinkedItemManager.m_pA3DEntityRef = sMiscRefData.m_pEntity; + sViewLinkedItemManager.m_POOwner = sMkpLinkedItemData.m_pTargetProductOccurrence; + sViewLinkedItemManager.m_pMarkupLinkedItem = pMkpLinkedItemEntityRef; + sViewLinkedItemManager.m_uiPOLevel = m_uiCurrentLevel; + + A3DEEntityType sType; + A3DEntityGetType (sMiscRefData.m_pEntity, &sType); + if (sType == kA3DTypeMiscReferenceOnTopology) + { + A3DMiscReferenceOnTopologyData sTopoRefData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnTopologyData, sTopoRefData); + A3DMiscReferenceOnTopologyGet (sMiscRefData.m_pEntity, &sTopoRefData); + sViewLinkedItemManager.m_pA3DEntityRef = sTopoRefData.m_pBrepData; + sViewLinkedItemManager.m_bRefOnTopoItem = true; + A3DMiscReferenceOnTopologyGet (NULL, &sTopoRefData); + } + else if (sType == kA3DTypeMiscReferenceOnCsysItem) + { + A3DMiscReferenceOnCsysItemData sA3DMiscReferenceOnCSYSITemData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnCsysItemData, sA3DMiscReferenceOnCSYSITemData); + A3DMiscReferenceOnCsysItemGet (sMiscRefData.m_pEntity, &sA3DMiscReferenceOnCSYSITemData); + sViewLinkedItemManager.m_pA3DEntityRef = sA3DMiscReferenceOnCSYSITemData.m_pCoordinateSystem; + A3DMiscReferenceOnCsysItemGet (NULL, &sA3DMiscReferenceOnCSYSITemData); + } + else + sViewLinkedItemManager.m_pA3DEntityRef = sMiscRefData.m_pEntity; + + A3DMiscEntityReferenceGet (NULL, &sMiscRefData); + + m_asViewLinkedItemManager.push_back(sViewLinkedItemManager); + } + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorContainer::visitLeave(const A3DMkpViewConnector& sConnector) +{ + if ((m_psActivatedView == NULL) || (m_psActivatedView != sConnector.GetA3DEntity())) + { + if (!m_bTraverseActivatedViewOnly) + VISITLEAVE; + + return A3D_SUCCESS; + } + + VISITLEAVE; +} + +#endif + +void A3DVisitorContainer::push( A3DVisitor* psVisitor ) +{ +// vector::iterator iter = +// search(m_apVisitor.begin(), m_apVisitor.end(), &psVisitor, &psVisitor+1); +// if(iter == m_apVisitor.end()) +// { +// m_apVisitorExcludedForDelete.push_back(psVisitor); +// } + m_apVisitor.push_back(psVisitor); + if(!m_pTreeVisitor) + m_pTreeVisitor = (A3DVisitor*)dynamic_cast(psVisitor);//dynamic_cast return null if failed. +} + + +A3DVisitorContainer::~A3DVisitorContainer() +{ + size_t uI, uNbVisitor = m_apVisitor.size(); +// vector::iterator iter; + for(uI = 0; uI < uNbVisitor; uI++) +// { +// iter = search( m_apVisitorExcludedForDelete.begin(), +// m_apVisitorExcludedForDelete.end(), +// &m_apVisitor[uI], +// &m_apVisitor[uI]+1); +// if(iter == m_apVisitorExcludedForDelete.end()) + delete m_apVisitor[uI]; +// } +} + + +void* A3DVisitorContainer::FindInMap(const A3DEntity* pA3DEntity) +{ + map::iterator my_mapIter; + my_mapIter = m_apA3DEntityYourEntityMap.find(pA3DEntity); + if(my_mapIter == m_apA3DEntityYourEntityMap.end()) + return NULL; + return my_mapIter->second; +} + +void A3DVisitorContainer::SetInMap(const A3DEntity* pA3DEntity, void* pYourEntity) +{ + m_apA3DEntityYourEntityMap.insert(std::pair(pA3DEntity, pYourEntity)); +} + +void A3DVisitorContainer::RemoveFromMap(const A3DEntity* pA3DEntity) +{ + m_apA3DEntityYourEntityMap.erase(pA3DEntity); +} + +A3DVisitor* A3DVisitorContainer::GetVisitorByName( std::string strName ) +{ + for(auto visitor : m_apVisitor) + { + if(visitor->GetName() == strName) + { + return visitor; + } + } + return nullptr; +} + +A3DVisitor* A3DVisitorContainer::GetTreeVisitor() const +{ + return m_pTreeVisitor; +} + +void A3DVisitorContainer::ActivateEntityReference( A3DEntity const* pEntity ) +{ + // StepEntityReference + size_t uI, uNbPushStepEntityRef = m_asStepEntityRefManager.size(); + for(uI = 0; uI < uNbPushStepEntityRef; uI++) + { + if(m_asStepEntityRefManager[uI].m_pA3DEntityRef == pEntity) + { + m_asStepEntityRefManager[uI].m_uiPushLevel = m_uiCurrentLevel; + } + } + + // ViewLinkedItem + size_t uNbPushViewLMkpLinkedItem = m_asViewLinkedItemManager.size(); + for (uI = 0; uI < uNbPushViewLMkpLinkedItem; uI++) + { + A3DViewLinkedItemManager *pCurManager = &m_asViewLinkedItemManager[uI]; + if (pCurManager->m_pA3DEntityRef == pEntity && + ( pCurManager->m_POOwner == NULL || + pCurManager->m_POOwner == pEntity || + pCurManager->m_POOwner == m_pCurrentPOFather + ) + ) + { + pCurManager->m_uiPushLevel = m_uiCurrentLevel; + } + } +} + +void A3DVisitorContainer::DeactivateEntityReference( A3DEntity const* pEntity ) +{ + // StepEntityReference + size_t uI, uNbPushStepEntityRef = m_asStepEntityRefManager.size(); + for(uI = 0; uI < uNbPushStepEntityRef; uI++) + { + if(m_asStepEntityRefManager[uI].m_pA3DEntityRef == pEntity) + { + m_asStepEntityRefManager[uI].m_uiPushLevel = ~0U; + } + } + + // ViewLinkedItem + size_t uNbPushViewLMkpLinkedItem = m_asViewLinkedItemManager.size(); + for (uI = 0; uI < uNbPushViewLMkpLinkedItem; uI++) + { + A3DViewLinkedItemManager *pCurManager = &m_asViewLinkedItemManager[uI]; + if (pCurManager->m_pA3DEntityRef == pEntity && + ( pCurManager->m_POOwner == NULL || + pCurManager->m_POOwner == pEntity || + pCurManager->m_POOwner == m_pCurrentPOFather + ) + ) + { + pCurManager->m_uiPushLevel = ~0U; + } + } +} + +A3DStepEntityRefManager const* A3DVisitorContainer::GetActiveStepEntityRefManager(A3DEntity const * pEntity) const +{ + A3DStepEntityRefManager const * psActivated = NULL; + size_t uI, uNbPushStepEntityRef = m_asStepEntityRefManager.size(); + for(uI = 0; uI < uNbPushStepEntityRef; uI++) + { + A3DStepEntityRefManager const * psCurManager = &m_asStepEntityRefManager[uI]; + if (psCurManager->m_uiPushLevel!=~0U && (pEntity==NULL || psCurManager->m_pA3DEntityRef==pEntity)) + { + if (!psActivated) + psActivated = psCurManager; + else if (psCurManager->IsFirst(*psActivated)) + psActivated = psCurManager; + } + } + return psActivated; +} + +A3DViewLinkedItemManager const* A3DVisitorContainer::GetActiveViewLinkedItemManager(A3DEntity const * pEntity) const +{ + A3DViewLinkedItemManager const * psActivated = NULL; + + size_t uI, uNbPushViewMarkupLinkedItem = m_asViewLinkedItemManager.size(); + for (uI = 0; uI < uNbPushViewMarkupLinkedItem; uI++) + { + A3DViewLinkedItemManager const * psCurManager = &m_asViewLinkedItemManager[uI]; + if (psCurManager->m_uiPushLevel!=~0U && (pEntity==NULL || psCurManager->m_pA3DEntityRef==pEntity)) + { + if (!psActivated) + psActivated = psCurManager; + else if (psCurManager->IsFirst(*psActivated)) + psActivated = psCurManager; + } + } + + return psActivated; +} + +#ifdef CONNECT_FEATURE +A3DStatus A3DVisitorContainer::visitEnter(const A3DFRMFeatureConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitLeave(const A3DFRMFeatureConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitEnter(const A3DFRMParameterConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitLeave(const A3DFRMParameterConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitEnter(const A3DFRMFeatureTreeConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitLeave(const A3DFRMFeatureTreeConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitEnter(const A3DFRMFeatureLinkedItemConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitLeave(const A3DFRMFeatureLinkedItemConnector& sConnector) +VISITLEAVE + +#endif diff --git a/exchange/exchangesource/Collision/visitor/VisitorContainer.h b/exchange/exchangesource/Collision/visitor/VisitorContainer.h new file mode 100644 index 0000000..281ab7c --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/VisitorContainer.h @@ -0,0 +1,236 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3DVISITOR_CONTAINER +#define A3DVISITOR_CONTAINER +#include +#include "Visitors.h" + +//This class allow to use several vistor when traversing 3DX Tree. +//It allow also to exchange parameters between visitors + +#define NODE_INSTANCES 0x0001 + +class A3DStepEntityRefManager +{ +public: + unsigned int m_uiPOLevel; // Level of creation + unsigned int m_uiPushLevel; // if not ~0U , then is activated + bool m_bRefOnTopoItem;; + A3DMiscEntityReference* m_pStepEntityRef; + A3DEntity* m_pA3DEntityRef; + // std::vector m_apYourEntity; + + A3DStepEntityRefManager() : m_uiPOLevel(~0U), m_uiPushLevel(~0U), m_pStepEntityRef(NULL), m_bRefOnTopoItem(false), + m_pA3DEntityRef(NULL){} + void GetMatrix(); + + bool IsFirst( A3DStepEntityRefManager const & sOther) const { return (m_uiPOLevelsOther.m_uiPushLevel);} +}; + + + +class A3DViewLinkedItemManager + +{ +public: + unsigned int m_uiPOLevel; + unsigned int m_uiPushLevel; // if not ~0U , then is activated + bool m_bRefOnTopoItem; + A3DMiscMarkupLinkedItem * m_pMarkupLinkedItem; + A3DAsmProductOccurrence * m_POOwner; + A3DEntity * m_pA3DEntityRef; + // std::vector m_apYourEntity; + + A3DViewLinkedItemManager() : m_uiPOLevel(~0U), m_uiPushLevel(~0U), m_pMarkupLinkedItem(NULL),m_bRefOnTopoItem(false), + m_pA3DEntityRef(NULL){} + void GetMatrix(); + + bool IsFirst( A3DViewLinkedItemManager const & sOther) const { return (m_uiPOLevelsOther.m_uiPushLevel);} +}; + +class A3DVisitorContainer : public A3DVisitor +{ +#ifdef _MSC_VER + +#pragma warning(push) +#pragma warning(disable:4251) // Suppress the warning C4251 because it leads to have that kind of warning : "warning +// C4251: 'A3DVisitorColorMaterials::m_apsCascadedAttribute' : class 'std::vector<_Ty>' needs to have dll-interface to +// be used by clients of class 'A3DVisitorColorMaterials" +// This is because of the "dllexport" on the visitor classes, as they use stl members and it seems that stl causes +// warning with dllexport with microsoft compiler +#endif // _MSC_VER + + std::map m_apA3DEntityYourEntityMap; + std::vector m_apVisitor; + bool m_bTraverseInstance; + + A3DVisitor* m_pTreeVisitor; + A3DAsmProductOccurrence const * m_pCurrentPOFather; + A3DMkpView const * m_psActivatedView; + bool m_bTraverseActivatedViewOnly; + + std::vector m_asStepEntityRefManager; + std::vector m_asViewLinkedItemManager; + unsigned int m_uiCurrentLevel; + unsigned int m_uFlagElementToConnect; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif // _MSC_VER + +public: + A3DVisitorContainer(unsigned int uFlagElementToconnect = + CONNECT_TRANSFO | CONNECT_COLORS | CONNECT_MESH | CONNECT_ASSEMBLY_TREE | CONNECT_BREP | CONNECT_PMI | CONNECT_VIEWS| CONNECT_FEATURE); + + virtual ~A3DVisitorContainer(); + + void push( A3DVisitor* psVisitor); + + //A3DConnector + virtual A3DStatus visitEnter(const A3DConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DConnector& /*sConnector*/) { return A3D_SUCCESS; } + + //Assmebly Tree +#ifdef CONNECT_ASSEMBLY_TREE + virtual A3DStatus visitEnter(const A3DModelFileConnector& sConnector); + virtual A3DStatus visitLeave(const A3DModelFileConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DProductOccurrenceConnector& sConnector); + virtual A3DStatus visitLeave(const A3DProductOccurrenceConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DPartConnector& sConnector); + virtual A3DStatus visitLeave(const A3DPartConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DRiConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiConnector& sConnector); + + + virtual A3DStatus visitEnter(const A3DRiBrepModelConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiBrepModelConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DRiSetConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiSetConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DPolyRiBrepModelConnector& sConnector); + virtual A3DStatus visitLeave(const A3DPolyRiBrepModelConnector& sConnector); + +#endif +#ifdef CONNECT_PMI + //Markup Tree + virtual A3DStatus visitEnter(const A3DMkpAnnotationEntityConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMkpAnnotationEntityConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMkpAnnotationSetConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMkpAnnotationSetConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMkpAnnotationItemConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMkpAnnotationItemConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMarkupConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMarkupConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMarkupDimensionConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMarkupDimensionConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMarkupGDTConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMarkupGDTConnector& sConnector); +#endif + +#ifdef CONNECT_BREP + //Brep + virtual A3DStatus visitEnter(const A3DBrepDataConnector& sConnector); + virtual A3DStatus visitLeave(const A3DBrepDataConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DConnexConnector& sConnector); + virtual A3DStatus visitLeave(const A3DConnexConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DShellConnector& sConnector); + virtual A3DStatus visitLeave(const A3DShellConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DFaceConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFaceConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DLoopConnector& sConnector); + virtual A3DStatus visitLeave(const A3DLoopConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DCoEdgeConnector& sConnector); + virtual A3DStatus visitLeave(const A3DCoEdgeConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DEdgeConnector& sConnector); + virtual A3DStatus visitLeave(const A3DEdgeConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DUniqueVertexConnector& sConnector); + virtual A3DStatus visitLeave(const A3DUniqueVertexConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMultipleVertexConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMultipleVertexConnector& sConnector); +#endif +#ifdef CONNECT_MESH + //Mesh + virtual A3DStatus visitEnter(const A3DTessDataConnector& sConnector); + virtual A3DStatus visitLeave(const A3DTessDataConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DFaceTessDataConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFaceTessDataConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMarkupDatumConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMarkupDatumConnector& sConnector); +#endif + //Views +#ifdef CONNECT_VIEWS + virtual A3DStatus visitEnter(const A3DMkpViewConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMkpViewConnector& sConnector); +#endif +#ifdef CONNECT_FEATURE + virtual A3DStatus visitEnter(const A3DFRMFeatureConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFRMFeatureConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DFRMParameterConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFRMParameterConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DFRMFeatureTreeConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFRMFeatureTreeConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DFRMFeatureLinkedItemConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFRMFeatureLinkedItemConnector& sConnector); +#endif + void* FindInMap(const A3DEntity* pA3DEntity); + void SetInMap(const A3DEntity* pA3DEntity, void* pYourEntity); + void RemoveFromMap(const A3DEntity* pA3DEntity); + + std::vector& GetVisitor() { return m_apVisitor; } + + + bool TraverseInstances() { return m_bTraverseInstance; } + void SetTraverseInstance(bool bTraverseInstance) { m_bTraverseInstance = bTraverseInstance; } + + A3DVisitor* GetVisitorByName(std::string strName); + A3DVisitor* GetTreeVisitor() const; + + void SetCurrentPoFather(A3DAsmProductOccurrence const * pCurrentPOFather) { m_pCurrentPOFather = pCurrentPOFather; } + A3DAsmProductOccurrence const * GetCurrentPoFather() { return m_pCurrentPOFather; } + + void SetActivateView(A3DMkpView const * psActivatedView) { m_psActivatedView = psActivatedView; } + A3DMkpView const * GetActivatedView() { return m_psActivatedView; } + + void SetTraverseActivatedViewOnly(bool bTraverseActivatedViewOnly) { m_bTraverseActivatedViewOnly = bTraverseActivatedViewOnly; } + + // StepEntityReference and ViewLinkedItem treatment + A3DStepEntityRefManager const* GetActiveStepEntityRefManager(A3DEntity const * pEntity) const; + A3DViewLinkedItemManager const* GetActiveViewLinkedItemManager(A3DEntity const * pEntity) const; + + void ActivateEntityReference( A3DEntity const* pEntity ); + void DeactivateEntityReference(A3DEntity const* pEntity); + + unsigned int GetFlagElementToConnect() const { return m_uFlagElementToConnect; } +}; +#endif diff --git a/exchange/exchangesource/Collision/visitor/VisitorTessellation.cpp b/exchange/exchangesource/Collision/visitor/VisitorTessellation.cpp new file mode 100644 index 0000000..91bc3c9 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/VisitorTessellation.cpp @@ -0,0 +1,90 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "VisitorTessellation.h" +#include "TessConnector.h" +#include "VisitorTessellation.h" +#include "TessConnector.h" + + +A3DStatus A3DVisitorTessellation::visitEnter(const A3DTessDataConnector& sTessConnector) +{ + m_uCurrentFaceIndice = 0; + //Get point Array + A3DStatus iRet = A3D_SUCCESS; + unsigned int uPointSize, uNormalSize, uUVSize, uFaceSize; + double* pdPoint, *pdNormal, *pdUV; + CHECK_RET(sTessConnector.Points(pdPoint, uPointSize)); + CHECK_RET(sTessConnector.Normals(pdNormal, uNormalSize)); + CHECK_RET(sTessConnector.UV(pdUV, uUVSize)); + uFaceSize = sTessConnector.FacesSize(); + unsigned int uIFaceCount; + for(uIFaceCount = 0; uIFaceCount auTriangleWithPointNormalInidces; + std::vector auTrinagleWithPointNromalUVindices; + CHECK_RET(sTessConnector.IndicesPerFaceAsTriangle(uIFaceCount, + auTriangleWithPointNormalInidces, + auTrinagleWithPointNromalUVindices)); + + /**************************************************************************** + Please create Your mesh here + *****************************************************************************/ + } + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTessellation::visitLeave(const A3DTessDataConnector& /*sTessConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTessellation::visitEnter(const A3DFaceTessDataConnector& /*sTessConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTessellation::visitLeave(const A3DFaceTessDataConnector& /*sTessConnector*/) +{ + m_uCurrentFaceIndice++; + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTessellation::visitEnter(const A3DRiConnector& /*sTessConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTessellation::visitLeave(const A3DRiConnector& /*sTessConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTessellation::visitEnter(const A3DMarkupTessConnector& /*sMarkupTessConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTessellation::visitLeave(const A3DMarkupTessConnector& /*sMarkupTessConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTessellation::visitEnter(const A3DWireTessDataConnector& /*sWireTessConnector*/) +{ + return A3D_SUCCESS; +} + + +A3DStatus A3DVisitorTessellation::visitLeave(const A3DWireTessDataConnector& /*sWireTessConnector*/) +{ + return A3D_SUCCESS; +} diff --git a/exchange/exchangesource/Collision/visitor/VisitorTessellation.h b/exchange/exchangesource/Collision/visitor/VisitorTessellation.h new file mode 100644 index 0000000..7ac6a07 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/VisitorTessellation.h @@ -0,0 +1,45 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_VISIST_TESSELLATION +#define A3D_VISIST_TESSELLATION + +#include "Visitors.h" +#include "TessConnector.h" + +class A3DVisitorTessellation : public A3DVisitor +{ + friend class A3DVisitorContainer; + +protected: + bool m_bShow; + unsigned int m_uCurrentFaceIndice; +public: + A3DVisitorTessellation(A3DVisitorContainer* psContainer = NULL) : A3DVisitor("Tessellation", psContainer) {}; + virtual ~A3DVisitorTessellation() {} + + virtual A3DStatus visitEnter(const A3DFaceTessDataConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFaceTessDataConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DTessDataConnector& sTessConnector); + virtual A3DStatus visitLeave(const A3DTessDataConnector& sTessConnector); + + virtual A3DStatus visitEnter(const A3DRiConnector& sTessConnector); + virtual A3DStatus visitLeave(const A3DRiConnector& sTessConnector); + + virtual A3DStatus visitEnter(const A3DMarkupTessConnector& sMarkupTessConnector); + virtual A3DStatus visitLeave(const A3DMarkupTessConnector& sMarkupTessConnector); + + virtual A3DStatus visitEnter(const A3DWireTessDataConnector& sTessConnector); + virtual A3DStatus visitLeave(const A3DWireTessDataConnector& sTessConnector); +}; +#endif + diff --git a/exchange/exchangesource/Collision/visitor/VisitorTransfo.cpp b/exchange/exchangesource/Collision/visitor/VisitorTransfo.cpp new file mode 100644 index 0000000..8faaf4e --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/VisitorTransfo.cpp @@ -0,0 +1,324 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "TransfoConnector.h" +#include "VisitorTransfo.h" +#include "TreeTraverse.h" +#include "Matrix.h" +#include "VisitorTree.h" + +A3DVisitorTransfo::A3DVisitorTransfo( bool bModelFileUnitFormCAD, + double dUnitModelFile, + A3DVisitorContainer* psContainer /*= NULL*/ ) +: A3DVisitor("Transformation", psContainer), + m_dUnit(dUnitModelFile), + m_bUnitFormCad(bModelFileUnitFormCAD) +{ +} + +A3DVisitorTransfo::A3DVisitorTransfo( A3DVisitorContainer* psContainer /*= NULL*/ ) +: A3DVisitor("Transformation", psContainer), + m_dUnit(1.), + m_bUnitFormCad(false) +{ +} + +A3DVisitorTransfo::~A3DVisitorTransfo() +{ +} + +A3DTransfoConnector* A3DVisitorTransfo::GetTransfoConnectorFromManager(A3DEntity const * pEntity) +{ + if(m_psContainer) + { + A3DViewLinkedItemManager const* pVLIM = m_psContainer->GetActiveViewLinkedItemManager(pEntity); + if (pVLIM) + { + A3DMiscEntityReferenceData sSERData; + A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sSERData); + A3DStatus iErr = A3DMiscEntityReferenceGet (pVLIM->m_pMarkupLinkedItem, &sSERData); + if (iErr == A3D_SUCCESS && sSERData.m_pCoordinateSystem) + { + A3DRiCoordinateSystemData sCSysData; + A3D_INITIALIZE_DATA(A3DRiCoordinateSystemData, sCSysData); + iErr = A3DRiCoordinateSystemGet (sSERData.m_pCoordinateSystem, &sCSysData); + A3DTransfoConnector* pConnector = new A3DTransfoConnector(NULL); + pConnector->SetGlobalMatrix(sCSysData.m_pTransformation); + return pConnector; + } + A3DMiscEntityReferenceGet (NULL, &sSERData); + } + + A3DStepEntityRefManager const* pSERM = m_psContainer->GetActiveStepEntityRefManager(pEntity); + if(pSERM) + { + A3DMiscEntityReferenceData sSERData; + A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sSERData); + A3DStatus iErr = A3DMiscEntityReferenceGet (pSERM->m_pStepEntityRef, &sSERData); + if(iErr == A3D_SUCCESS && sSERData.m_pCoordinateSystem) + { + A3DRiCoordinateSystemData sCSysData; + A3D_INITIALIZE_DATA(A3DRiCoordinateSystemData, sCSysData); + A3DRiCoordinateSystemGet (sSERData.m_pCoordinateSystem, &sCSysData); + A3DTransfoConnector* pConnector = new A3DTransfoConnector(NULL); + + pConnector->SetGlobalMatrix(sCSysData.m_pTransformation); + return pConnector; + } + A3DMiscEntityReferenceGet (NULL, &sSERData); + } + } + + return NULL; +} + +A3DStatus A3DVisitorTransfo::visitEnter(const A3DRiConnector& sConnector) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DMatrix4x4 sTransfo; + size_t uSize = m_adPushTransfo.size(); + + // Use ItemReference transformation instead of local transformation + A3DTransfoConnector *pConnectorFromRef = this->GetTransfoConnectorFromManager(sConnector.GetA3DEntity()); + if (pConnectorFromRef) + { + pConnectorFromRef->GetGlobalTransfo(sTransfo); + m_adPushTransfo.push_back(sTransfo); + delete pConnectorFromRef; + + } + else if(sConnector.m_sRiData.m_pCoordinateSystem) + { + A3DRiCoordinateSystemData sA3DRiCoordinateSystemData; + A3D_INITIALIZE_DATA(A3DRiCoordinateSystemData, sA3DRiCoordinateSystemData); + A3DRiCoordinateSystemGet(sConnector.m_sRiData.m_pCoordinateSystem,&sA3DRiCoordinateSystemData); + + A3DTransfoConnector sTransfoConnector(sA3DRiCoordinateSystemData.m_pTransformation); + sTransfoConnector.ComputeGlobalMatrix(uSize!= 0 ? m_adPushTransfo[uSize-1] : stIdentity); + //Local Matrix + A3DMatrix4x4 sThisMatrix; + CHECK_RET(sTransfoConnector.GetLocalMatrix(sThisMatrix)); + CHECK_RET(SetLocalTransfo(sThisMatrix)); + //GlobalMatrix + sTransfoConnector.GetGlobalTransfo(sTransfo); + m_adPushTransfo.push_back(sTransfo); + A3DRiCoordinateSystemGet(NULL, &sA3DRiCoordinateSystemData); + } + else + { + m_adPushTransfo.push_back(uSize!= 0 ? m_adPushTransfo[uSize-1] : stIdentity); + CHECK_RET(SetLocalTransfo(stIdentity)); + } + + CHECK_RET(SetGlobalTransfo(m_adPushTransfo[m_adPushTransfo.size() - 1])); + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTransfo::visitLeave(const A3DRiConnector& /*sConnector*/) +{ + // End drawing the Representation Items + m_adPushTransfo.pop_back(); + + return A3D_SUCCESS; +} + +//XXX Is There a way to integrate this function in TreeTravrse? +static A3DStatus stProductOccurrenceGetLocation( const A3DAsmProductOccurrenceData* psPOccData, + A3DMiscCartesianTransformation** ppLocation) +{ + if (psPOccData == NULL) + return A3D_ERROR; + + A3DStatus iRet = A3D_SUCCESS; + A3DAsmProductOccurrence* pExternal = psPOccData->m_pExternalData; + + if (pExternal != NULL) + { + A3DAsmProductOccurrenceData sExternalDataData; + A3D_INITIALIZE_DATA( A3DAsmProductOccurrenceData, sExternalDataData); + A3DAsmProductOccurrenceGet(pExternal, &sExternalDataData); + + CHECK_RET(stProductOccurrenceGetLocation( &sExternalDataData , ppLocation)); + A3DAsmProductOccurrenceGet(NULL, &sExternalDataData); + if(*ppLocation) + return A3D_SUCCESS; + } + + if (psPOccData->m_pLocation == NULL && psPOccData->m_pPrototype != NULL) + { + A3DAsmProductOccurrenceData sPrototypeData; + A3D_INITIALIZE_DATA( A3DAsmProductOccurrenceData, sPrototypeData); + A3DAsmProductOccurrenceGet(psPOccData->m_pPrototype, &sPrototypeData); + + CHECK_RET(stProductOccurrenceGetLocation(&sPrototypeData, ppLocation)); + A3DAsmProductOccurrenceGet(NULL, &sPrototypeData); + return A3D_SUCCESS; + } + + *ppLocation = psPOccData->m_pLocation; + + return iRet; +} + +A3DStatus A3DVisitorTransfo::visitEnter(const A3DProductOccurrenceConnector& sConnector) +{ + A3DStatus iRet = A3D_SUCCESS; + + if(sConnector.m_sProductOccurrenceData.m_bUnitFromCAD && !m_bUnitFormCad) + { + m_bUnitFormCad = true; + m_dUnit = sConnector.m_sProductOccurrenceData.m_dUnit; + } + + // Use ItemReference transformation instead of local transformation + A3DTransfoConnector *pConnectorFromRef = this->GetTransfoConnectorFromManager(sConnector.GetA3DEntity()); + if (pConnectorFromRef) + { + A3DMatrix4x4 sTransfo; + pConnectorFromRef->GetGlobalTransfo(sTransfo); + m_adPushTransfo.push_back(sTransfo); + delete pConnectorFromRef; + } + else + { + A3DMiscCartesianTransformation* pLocation = NULL; + stProductOccurrenceGetLocation(&(sConnector.m_sProductOccurrenceData), &pLocation); + + A3DMatrix4x4 sTransfo; + size_t uSize = m_adPushTransfo.size(); + + if(pLocation) + { + A3DTransfoConnector sTransfoConnector(pLocation); + + //Local Transfo + A3DMatrix4x4 sThisMatrix; + CHECK_RET(sTransfoConnector.GetLocalMatrix(sThisMatrix)); + CHECK_RET(SetLocalTransfo(sThisMatrix)); + + //Global Transfo + sTransfoConnector.ComputeGlobalMatrix( uSize != 0 ? m_adPushTransfo[uSize - 1]: stIdentity); + sTransfoConnector.GetGlobalTransfo(sTransfo); + m_adPushTransfo.push_back(sTransfo); + } + else + { + m_adPushTransfo.push_back(uSize != 0 ? m_adPushTransfo[uSize - 1] : stIdentity); + CHECK_RET(SetLocalTransfo(stIdentity)); + } + } + + CHECK_RET(SetGlobalTransfo(m_adPushTransfo[m_adPushTransfo.size() - 1])); + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTransfo::visitLeave(const A3DProductOccurrenceConnector& /*sConnector*/) +{ + // End drawing the Product Occurrences + m_adPushTransfo.pop_back(); + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTransfo::visitEnter(const A3DModelFileConnector& sConnector) +{ + if(sConnector.m_sModelFileData.m_bUnitFromCAD && !m_bUnitFormCad) + { + m_bUnitFormCad = true; + m_dUnit = sConnector.m_sModelFileData.m_dUnit; + } + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTransfo::visitLeave(const A3DModelFileConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DTransfoConnector* A3DVisitorTransfo::GetTransfoConnector(bool bUseInstance /*= false*/ ) +{ + if(bUseInstance) + { + size_t iSize = m_adPushTransfo.size(); + A3DMatrix4x4 rLastMatrix = iSize != 0 ? m_adPushTransfo[iSize-1] : stIdentity; + A3DMiscCartesianTransformation* pTransfo = CreateTransfo(m_adLocalMatrix); + A3DTransfoConnector* pConnector = new A3DTransfoConnector(pTransfo); + pConnector->SetGlobalMatrix(rLastMatrix); + A3DEntityDelete (pTransfo); + return pConnector; + } + else + { + //if(m_psContainer) + //{ + // A3DTreeVisitor* pTreeVisitor = (A3DTreeVisitor*)m_psContainer->GetTreeVisitor(); + // if(pTreeVisitor) + // { + // A3DStepEntityRefManager const* pSERM = pTreeVisitor->GetFirstActiveStepEntityRefManager(); + // if(pSERM) + // { + // A3DMiscEntityReferenceData sSERData; + // A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sSERData); + // A3DStatus iErr = A3DMiscEntityReferenceGet(pSERM->m_pStepEntityRef, &sSERData); + // if(iErr == A3D_SUCCESS && sSERData.m_pCoordinateSystem) + // { + // A3DRiCoordinateSystemData sCSysData; + // A3D_INITIALIZE_DATA(A3DRiCoordinateSystemData, sCSysData); + // iErr = A3DRiCoordinateSystemGet(sSERData.m_pCoordinateSystem, &sCSysData); + // A3DTransfoConnector* pConnector = new A3DTransfoConnector(NULL); + // pConnector->SetGlobalMatrix(sCSysData.m_pTransformation); + // return pConnector; + // } + // A3DMiscEntityReferenceGet(NULL, &sSERData); + // } + // + // A3DViewLinkedItemManager const* pVLIM = pTreeVisitor->GetFirstActiveViewLinkedItemManager(); + // if (pVLIM) + // { + // A3DMiscEntityReferenceData sSERData; + // A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sSERData); + // A3DStatus iErr = A3DMiscEntityReferenceGet (pVLIM->m_pMarkupLinkedItem, &sSERData); + // if (iErr == A3D_SUCCESS && sSERData.m_pCoordinateSystem) + // { + // A3DRiCoordinateSystemData sCSysData; + // A3D_INITIALIZE_DATA(A3DRiCoordinateSystemData, sCSysData); + // iErr = A3DRiCoordinateSystemGet (sSERData.m_pCoordinateSystem, &sCSysData); + // A3DTransfoConnector* pConnector = new A3DTransfoConnector(NULL); + // pConnector->SetGlobalMatrix(sCSysData.m_pTransformation); + // return pConnector; + // } + // A3DMiscEntityReferenceGet (NULL, &sSERData); + // } + // } + //} + size_t iSize = m_adPushTransfo.size(); + A3DMatrix4x4 rLastMatrix = iSize != 0 ? m_adPushTransfo[iSize-1] : stIdentity; + A3DMiscCartesianTransformation* pTransfo = CreateTransfo(m_adLocalMatrix); + A3DTransfoConnector* pConnector = new A3DTransfoConnector(pTransfo); + pConnector->SetGlobalMatrix(rLastMatrix); + A3DEntityDelete (pTransfo); + return pConnector; + } +} + +A3DMiscTransformation* A3DVisitorTransfo::CreateTransfo( A3DMatrix4x4 const & rMatrix ) +{ + + A3DMiscGeneralTransformationData sData; + A3D_INITIALIZE_DATA( A3DMiscGeneralTransformationData, sData); + memcpy( sData.m_adCoeff ,rMatrix.m_adM, 16*sizeof(double)); + A3DMiscGeneralTransformation* pTransfo = NULL; + A3DMiscGeneralTransformationCreate (&sData, &pTransfo); + return (A3DMiscTransformation*)pTransfo; +} diff --git a/exchange/exchangesource/Collision/visitor/VisitorTransfo.h b/exchange/exchangesource/Collision/visitor/VisitorTransfo.h new file mode 100644 index 0000000..eb4ca84 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/VisitorTransfo.h @@ -0,0 +1,83 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef VISIT_TRANSFO +#define VISIT_TRANSFO +#include "Visitors.h" +#include +#include "Matrix.h" + + +class A3DTransfoConnector; + + +//Visitor used to Get transfo on each ProductOccurrences and Representation Item Nodes +class A3DVisitorTransfo : public A3DVisitor +{ + //friend class A3DVisitorContainer; + +protected: + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) // Suppress the warning C4251 because it leads to have that kind of warning : "warning + // C4251: 'A3DVisitorColorMaterials::m_apsCascadedAttribute' : class 'std::vector<_Ty>' needs to have dll-interface to + // be used by clients of class 'A3DVisitorColorMaterials" + // This is because of the "dllexport" on the visitor classes, as they use stl members and it seems that stl causes + // warning with dllexport with microsoft compiler +#endif // _MSC_VER + + std::vector m_adPushTransfo; + A3DMatrix4x4 m_adLocalMatrix; + bool m_bUnitFormCad; + double m_dUnit; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif // _MSC_VER + + A3DMiscTransformation* CreateTransfo(A3DMatrix4x4 const & rMatrix); + +public: + + A3DVisitorTransfo(bool bModelFileUnitFormCAD, + double dUnitModelFile, + A3DVisitorContainer* psContainer = NULL); + + A3DVisitorTransfo(A3DVisitorContainer* psContainer = NULL); + + virtual ~A3DVisitorTransfo(); + + virtual A3DStatus visitEnter(const A3DRiConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiConnector& sConnector); + virtual A3DStatus visitEnter(const A3DProductOccurrenceConnector& sConnector); + virtual A3DStatus visitLeave(const A3DProductOccurrenceConnector& sConnector); + virtual A3DStatus visitEnter(const A3DModelFileConnector& sConnector); + virtual A3DStatus visitLeave(const A3DModelFileConnector& sConnector); + + virtual A3DStatus SetLocalTransfo(A3DMatrix4x4 const& rdLocalTransfo) { m_adLocalMatrix = rdLocalTransfo; return A3D_SUCCESS; } + virtual A3DStatus SetGlobalTransfo(A3DMatrix4x4 const& /*rdLocalTransfo*/) { return A3D_SUCCESS; } + + bool UnitFromCad() const + { + return m_bUnitFormCad; + } + + double Unit() const + { + return m_dUnit; + } + + A3DTransfoConnector* GetTransfoConnector(bool bUseInstance = false); + + A3DTransfoConnector* GetTransfoConnectorFromManager(A3DEntity const * pEntity); +}; +#endif diff --git a/exchange/exchangesource/Collision/visitor/VisitorTree.cpp b/exchange/exchangesource/Collision/visitor/VisitorTree.cpp new file mode 100644 index 0000000..a0f3e7f --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/VisitorTree.cpp @@ -0,0 +1,97 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "VisitorTree.h" + +A3DStatus A3DTreeVisitor::visitEnter(const A3DRiBrepModelConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DRiBrepModelConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitEnter(const A3DRiSetConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DRiSetConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitEnter(const A3DRiConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DRiConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitEnter(const A3DPartConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DPartConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitEnter(const A3DProductOccurrenceConnector& sConnector) +{ + if(m_uOption&NODE_INSTANCES) + { + m_pYourEntity = m_psContainer->FindInMap(sConnector.GetA3DEntity()); + if(m_pYourEntity) + { + ((A3DProductOccurrenceConnector*) &sConnector)->SetIsInstanciated(true); + } + } + + m_psContainer->SetInMap(sConnector.GetA3DEntity(),(void*) sConnector.GetA3DEntity() ); + + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DProductOccurrenceConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitEnter(const A3DMkpViewConnector& sConnector) +{ + m_psContainer->SetInMap(sConnector.GetA3DEntity(), (void*)sConnector.GetA3DEntity());//m_pYourEntity); + + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DMkpViewConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +void A3DTreeVisitor::SetYourEntity(void* /*pYourEnity*/) +{ + //std::vector::iterator sIter; + //for(sIter = m_asStepEntityRefManager.begin(); sIter != m_asStepEntityRefManager.end(); ++sIter) + //{ + // if(sIter->m_bPushChildren == true) + // sIter->m_apYourEntity.push_back(pYourEnity); + //} + // + //return; +} diff --git a/exchange/exchangesource/Collision/visitor/VisitorTree.h b/exchange/exchangesource/Collision/visitor/VisitorTree.h new file mode 100644 index 0000000..9c9af6f --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/VisitorTree.h @@ -0,0 +1,73 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef VISIT_TREE +#define VISIT_TREE +#include "Visitors.h" +#include "VisitorContainer.h" + + +class A3DConnector; +class A3DVisitorContainer; + +class A3DTreeVisitor : public A3DVisitor +{ + friend class A3DVisitorContainer; +protected: + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) // Suppress the warning C4251 because it leads to have that kind of warning : "warning + // C4251: 'A3DVisitorColorMaterials::m_apsCascadedAttribute' : class 'std::vector<_Ty>' needs to have dll-interface to + // be used by clients of class 'A3DVisitorColorMaterials" + // This is because of the "dllexport" on the visitor classes, as they use stl members and it seems that stl causes + // warning with dllexport with microsoft compiler +#endif // _MSC_VER + + unsigned m_uOption; + void* m_pYourEntity; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif // _MSC_VER + +public: + + A3DTreeVisitor(A3DVisitorContainer* psContainer = NULL) : A3DVisitor("Tree", psContainer) + { + m_uOption = 0; + m_pYourEntity = NULL; + } + + virtual ~A3DTreeVisitor() {}; + + virtual A3DStatus visitEnter(const A3DRiBrepModelConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiBrepModelConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DRiSetConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiSetConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DRiConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DPartConnector& sConnector ); + virtual A3DStatus visitLeave(const A3DPartConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DProductOccurrenceConnector& sConnector); + virtual A3DStatus visitLeave(const A3DProductOccurrenceConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMkpViewConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMkpViewConnector& sConnector); + + void SetYourEntity(void* pYourEnity); + +}; +#endif \ No newline at end of file diff --git a/exchange/exchangesource/Collision/visitor/Visitors.h b/exchange/exchangesource/Collision/visitor/Visitors.h new file mode 100644 index 0000000..54fa9a5 --- /dev/null +++ b/exchange/exchangesource/Collision/visitor/Visitors.h @@ -0,0 +1,183 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_VISITOR +#define A3D_VISITOR + +#define CONNECT_TRANSFO 0x0001 +#define CONNECT_COLORS 0x0002 +#define CONNECT_MESH 0x0004 +#define CONNECT_ASSEMBLY_TREE 0x008 +#define CONNECT_BREP 0x0010 +#define CONNECT_PMI 0x00020 +#define CONNECT_VIEWS 0x00040 +#define CONNECT_FEATURE 0x00080 + + +#include "TreeTraverse.h" +#ifdef CONNECT_PMI +#include "MarkupTraverse.h" +#endif +#ifdef CONNECT_BREP +#include "BrepTraverse.h" +#endif +#ifdef CONNECT_PMI +#include "MarkupTraverse.h" +#endif +#ifdef CONNECT_MESH +#include "TessConnector.h" +#endif +#ifdef CONNECT_VIEWS +#include "ViewTraverse.h" +#endif + +#include + +#ifndef CHECK_RET +#define CHECK_RET(function) { if ((iRet = function)!=A3D_SUCCESS) { /*__debugbreak();*/ return iRet; }} +#endif + + +class A3DConnector; +class A3DVisitorContainer; +class A3DVisitor +{ +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) // Suppress the warning C4251 because it leads to have that kind of warning : "warning + // C4251: 'A3DVisitorColorMaterials::m_apsCascadedAttribute' : class 'std::vector<_Ty>' needs to have dll-interface to + // be used by clients of class 'A3DVisitorColorMaterials" + // This is because of the "dllexport" on the visitor classes, as they use stl members and it seems that stl causes + // warning with dllexport with microsoft compiler +#endif // _MSC_VER + +protected: + A3DVisitorContainer* m_psContainer; + std::string m_strName; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif // _MSC_VER + +public : + A3DVisitor(std::string strName, A3DVisitorContainer* psContainer = NULL) + : m_strName(strName), m_psContainer(psContainer){} + + virtual ~A3DVisitor() {} + + virtual std::string GetName() const { return m_strName; } + + //Assembly +#ifdef CONNECT_ASSEMBLY_TREE + virtual A3DStatus visitEnter(const A3DModelFileConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DModelFileConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DProductOccurrenceConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DProductOccurrenceConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DPartConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DPartConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DRiConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DRiConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DRiBrepModelConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DRiBrepModelConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DRiSetConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DRiSetConnector& /*sConnector*/) { return A3D_SUCCESS;} + + virtual A3DStatus visitEnter(const A3DPolyRiBrepModelConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DPolyRiBrepModelConnector& /*sConnector*/) { return A3D_SUCCESS; } + +#endif + //Markup +#ifdef CONNECT_PMI + virtual A3DStatus visitEnter(const A3DMkpAnnotationEntityConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMkpAnnotationEntityConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMkpAnnotationSetConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMkpAnnotationSetConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMkpAnnotationItemConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMkpAnnotationItemConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMarkupConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMarkupConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMarkupDimensionConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMarkupDimensionConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMarkupGDTConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMarkupGDTConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMarkupDatumConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMarkupDatumConnector& /*sConnector*/) { return A3D_SUCCESS; } +#endif + //Brep +#ifdef CONNECT_BREP + virtual A3DStatus visitEnter(const A3DBrepDataConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DBrepDataConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DConnexConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DConnexConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DShellConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DShellConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DFaceConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DFaceConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DLoopConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DLoopConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DCoEdgeConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DCoEdgeConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DEdgeConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DEdgeConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DUniqueVertexConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DUniqueVertexConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMultipleVertexConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMultipleVertexConnector&) { return A3D_SUCCESS; } +#endif + //Mesh +#ifdef CONNECT_MESH + virtual A3DStatus visitEnter(const A3DTessDataConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DTessDataConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DFaceTessDataConnector&) {return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DFaceTessDataConnector&) {return A3D_SUCCESS; } +#endif + //Views +#ifdef CONNECT_VIEWS + virtual A3DStatus visitEnter(const A3DMkpViewConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMkpViewConnector&) { return A3D_SUCCESS; } +#endif +#ifdef CONNECT_FEATURE + virtual A3DStatus visitEnter(const A3DFRMFeatureConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DFRMFeatureConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DFRMParameterConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DFRMParameterConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DFRMFeatureTreeConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DFRMFeatureTreeConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DFRMFeatureLinkedItemConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DFRMFeatureLinkedItemConnector& /*sConnector*/) { return A3D_SUCCESS; } +#endif +}; + + +#endif diff --git a/exchange/exchangesource/CreatePRCBrepWithGeometry/CreatePRCBrepWithGeometry.cpp b/exchange/exchangesource/CreatePRCBrepWithGeometry/CreatePRCBrepWithGeometry.cpp new file mode 100644 index 0000000..cc1f98f --- /dev/null +++ b/exchange/exchangesource/CreatePRCBrepWithGeometry/CreatePRCBrepWithGeometry.cpp @@ -0,0 +1,478 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file CreatePRCBrepWithGeometry.cpp + +This file demonstrates how to programmatically create a PRC file using HOOPS Exchange. +The only input is the file path where the program will write the output PRC file. +The program generates a PRC file which contains a warped circle with a thick edge. + +***********************************************************************************************************************/ + +#define _CRT_SECURE_NO_DEPRECATE 1 +#define _USE_MATH_DEFINES +#include +#include + +#define INITIALIZE_A3D_API +#include + +#include "../common.hpp" + +//###################################################################################################################### +/*! Creates a surface based on the parameters supplied to m_sUVDomain + */ +A3DSurfCylinder* stCreateSurface() +{ + A3DSurfCylinderData sData; + A3D_INITIALIZE_DATA(A3DSurfCylinderData, sData); + + sData.m_dRadius = 10.0; + // A 40 mm high closed cylinder (360°) + // Make the cylinder parameterized between -1 and +1 in both directions ((0, 0) is the center) + // The sUVDomain indicates the domain you want to use + // Coefficients have to be set so that computed parameters are defined + // inside classical parameterization for cylinders [0.0, 360.0] + sData.m_sParam.m_sUVDomain.m_sMin.m_dX = -1.0; + sData.m_sParam.m_sUVDomain.m_sMin.m_dY = -1.0; + sData.m_sParam.m_sUVDomain.m_sMax.m_dX = 1.0; + sData.m_sParam.m_sUVDomain.m_sMax.m_dY = 1.0; + A3DDouble dX = sData.m_sParam.m_sUVDomain.m_sMax.m_dX - sData.m_sParam.m_sUVDomain.m_sMin.m_dX; + sData.m_sParam.m_dUCoeffA = 2*M_PI/dX; + sData.m_sParam.m_dUCoeffB = 0; + sData.m_sParam.m_dVCoeffA = 20; + sData.m_sParam.m_dVCoeffB = 0; + sData.m_sParam.m_bSwapUV = false; + sData.m_sTrsf.m_ucBehaviour = kA3DTransformationIdentity; + + A3DSurfCylinder* pp = NULL; + A3DSurfCylinderCreate(&sData, &pp); + return pp; +} + +//###################################################################################################################### +/*! Creates a NURBS circle. + */ +A3DCrvNurbs* stCreateCircle(A3DDouble radius) +{ + A3DCrvNurbsData sData; + A3D_INITIALIZE_DATA(A3DCrvNurbsData, sData); + double dSqrt2_2 = sqrt(2.0) / 2.0; + + /**************************************************************************** + Definition of a NURBS representing a circle in the parametric space: + Radius must be comprised between 0 and 1 + Degree = 2, Dimension = 2 + 9 control points (first and last are identical) + 9 weights + 12 knots + + 3 |2 1 + +--------+--------+ + | | | + | | | + 4| | |0 + --+--------+--------+-- + | | |8 + | | | + | | | + +--------+--------+ + 5 6 7 + + ****************************************************************************/ + double adCtrlPoints[18] = + { + 1.0, 0.0, // 0 + 1.0, 1.0, // 1 + 0.0, 1.0, // 2 + -1.0, 1.0, // 3 + -1.0, 0.0, // 4 + -1.0, -1.0, // 5 + 0.0, -1.0, // 6 + 1.0, -1.0, // 7 + 1.0, 0.0 // 8 + }; + double adWeights[9] = + { + 1.0, // 0 + dSqrt2_2, // 1 + 1.0, // 2 + dSqrt2_2, // 3 + 1.0, // 4 + dSqrt2_2, // 5 + 1.0, // 6 + dSqrt2_2, // 7 + 1.0 // 8 + }; + double adKnots[12] = + { + 0.0, 0.0, 0.0, + 0.25, 0.25, + 0.50, 0.50, + 0.75, 0.75, + 1.00, 1.00, 1.00 + }; + + A3DVector3dData asControlPoints[9]; + A3DInt32 i; + for(i = 0; i < 9; ++i) + A3D_INITIALIZE_DATA(A3DVector3dData, asControlPoints[i]); + + for(i = 0; i < 9; ++i) + { + asControlPoints[i].m_dX = adCtrlPoints[i * 2] * radius; + asControlPoints[i].m_dY = adCtrlPoints[i * 2 + 1] * radius; + asControlPoints[i].m_dZ = 0; + } + + sData.m_bIs2D = 2; + sData.m_bRational = true; + sData.m_uiDegree = 2; + sData.m_uiCtrlSize = 9; + sData.m_pCtrlPts = asControlPoints; + sData.m_uiWeightSize = 9; + sData.m_pdWeights = adWeights; + sData.m_uiKnotSize = 12; + sData.m_pdKnots = adKnots; + sData.m_eCurveForm = kA3DBSplineCurveFormCircularArc; + sData.m_eKnotType = kA3DKnotTypeUnspecified; + + A3DCrvNurbs* pp = NULL; + A3DCrvNurbsCreate(&sData, &pp); + return pp; +} + +//###################################################################################################################### +/*! Creates an A3DTopoEdge based on topo edges created from A3DTopoEdgeCreate. + */ +A3DTopoEdge* stCreateTopoEdge() +{ + A3DTopoEdgeData sData; + A3D_INITIALIZE_DATA(A3DTopoEdgeData, sData); + A3DTopoEdge* pp = NULL; + A3DTopoEdgeCreate(&sData, &pp); + return pp; +} + +//###################################################################################################################### +/*! Creates an A3DTopoCoEdge based on data returned from stCreateTopoEdge(). + */ +A3DTopoCoEdge* stCreateTopoCoEdge(A3DCrvBase* p) +{ + A3DTopoCoEdge* pp = NULL; + A3DTopoCoEdge* q = stCreateTopoEdge(); + if(p != NULL && q != NULL) + { + A3DTopoCoEdgeData sData; + A3D_INITIALIZE_DATA(A3DTopoCoEdgeData, sData); + sData.m_pUVCurve = p; + sData.m_pEdge = q; + sData.m_ucOrientationWithLoop = 1; + sData.m_ucOrientationUVWithLoop = 1; + A3DTopoCoEdgeCreate(&sData, &pp); + } + return pp; +} + +//###################################################################################################################### +/*! Creates an A3DTopoLoop based on data returned from stCreateCircle() and stCreateTopoCoEdge(). + */ +A3DTopoLoop* stCreateTopoLoop(A3DDouble radius) +{ + A3DTopoLoopData sData; + A3D_INITIALIZE_DATA(A3DTopoLoopData, sData); + + A3DCrvBase* p = stCreateCircle(radius); + A3DTopoCoEdge* q = stCreateTopoCoEdge(p); + + sData.m_ppCoEdges = &q; + sData.m_uiCoEdgeSize = 1; + sData.m_ucOrientationWithSurface = 1; + + A3DTopoLoop* pp = NULL; + A3DTopoLoopCreate(&sData, &pp); + return pp; +} + +//###################################################################################################################### +/*! Creates an A3DTopoFace and creates a surface from stCreateSurface(). + */ +A3DTopoFace* stCreateTopoFace() +{ + A3DDouble outerradius = 0.5; + A3DDouble innerradius = 0.4; + A3DTopoLoop* loops[2]; + loops[0] = stCreateTopoLoop(outerradius); + loops[1] = stCreateTopoLoop(innerradius); + + A3DTopoFaceData sData; + A3D_INITIALIZE_DATA(A3DTopoFaceData, sData); + + sData.m_pSurface = stCreateSurface(); + sData.m_ppLoops = loops; + sData.m_uiLoopSize = 2; + sData.m_uiOuterLoopIndex = 0; + + A3DTopoFace* pp = NULL; + A3DTopoFaceCreate(&sData, &pp); + return pp; +} + +//###################################################################################################################### +/*! Creates an A3DTopoShell and populates it with an A3DTopoFace from stCreateTopoFace(). + */ +A3DTopoShell* stCreateTopoShell() +{ + A3DTopoShell* pp = NULL; + A3DTopoFace* p = stCreateTopoFace(); + if(p != NULL) + { + A3DTopoShellData sData; + A3D_INITIALIZE_DATA(A3DTopoShellData, sData); + + A3DUns8 orient = 1; + sData.m_bClosed = false; + sData.m_ppFaces = &p; + sData.m_uiFaceSize = 1; + sData.m_pucOrientationWithShell = &orient; + + A3DTopoShellCreate(&sData, &pp); + } + return pp; +} + +//###################################################################################################################### +/*! Creates an A3DTopoConnex and populates it with an A3DTopoShell from A3DTopoConnexCreate(). + */ +A3DTopoConnex* stCreateTopoConnex() +{ + A3DTopoConnex* pp = NULL; + A3DTopoShell* p = stCreateTopoShell(); + if(p != NULL) + { + A3DTopoConnexData sData; + A3D_INITIALIZE_DATA(A3DTopoConnexData, sData); + + sData.m_ppShells = &p; + sData.m_uiShellSize = 1; + + A3DTopoConnexCreate(&sData, &pp); + } + return pp; +} + +//###################################################################################################################### +/*! Creates an A3DTopoBrepData and populates it with an A3DTopoConnex from stCreateTopoConnex(). + */ +A3DTopoBrepData* stCreateTopoBrep() +{ + A3DTopoBrepData* pp = NULL; + A3DTopoConnex* p = stCreateTopoConnex(); + if(p != NULL) + { + A3DTopoBrepDataData sData; + A3D_INITIALIZE_DATA(A3DTopoBrepDataData, sData); + + sData.m_ppConnexes = &p; + sData.m_uiConnexSize = 1; + + A3DTopoBrepDataCreate(&sData, &pp); + } + return pp; +} + +//###################################################################################################################### +/*! Creates a representation item and populates it with an A3DTopoBrepData from stCreateTopoBrep(). + */ +A3DRiRepresentationItem* stCreateRIBrep() +{ + A3DRiBrepModel* pp = NULL; + A3DTopoBrepData* p = stCreateTopoBrep(); + if(p != NULL) + { + A3DRiBrepModelData sData; + A3D_INITIALIZE_DATA(A3DRiBrepModelData, sData); + + sData.m_pBrepData = p; + sData.m_bSolid = false; + + A3DRiBrepModelCreate(&sData, &pp); + } + return pp; +} + +//###################################################################################################################### +/*! Creates a part definition and populates it with a representation item from stCreateRIBrep(). + */ +A3DAsmPartDefinition* stCreatePart() +{ + A3DAsmPartDefinition* pp = NULL; + A3DRiRepresentationItem* p = stCreateRIBrep(); + if(p != NULL) + { + A3DAsmPartDefinitionData sData; + A3D_INITIALIZE_DATA(A3DAsmPartDefinitionData, sData); + + sData.m_uiRepItemsSize = 1; + sData.m_ppRepItems = &p; + + A3DAsmPartDefinitionCreate(&sData, &pp); + } + return pp; +} + +//###################################################################################################################### +/*! Creates attributes for the entity parameter p, then assigns the attributes to p. + */ +A3DVoid stSetAttributes(A3DEntity* p) +{ + A3DMiscAttribute* pAttr[3]; + + A3DMiscSingleAttributeData Single; + A3D_INITIALIZE_DATA(A3DMiscSingleAttributeData, Single); + + Single.m_eType = kA3DModellerAttributeTypeString; + Single.m_pcTitle = (char*) "Title"; + Single.m_pcData = (char*) "Simple B-rep building demonstration"; + + A3DMiscAttributeData sAttribs; + A3D_INITIALIZE_DATA(A3DMiscAttributeData, sAttribs); + + sAttribs.m_pcTitle = Single.m_pcTitle; + sAttribs.m_asSingleAttributesData = &Single; + sAttribs.m_uiSize = 1; + A3DMiscAttributeCreate(&sAttribs, &pAttr[0]); + + Single.m_pcTitle = (char*) "Author"; + Single.m_pcData = (char*) "HOOPS Exchange"; + sAttribs.m_pcTitle = Single.m_pcTitle; + A3DMiscAttributeCreate(&sAttribs, &pAttr[1]); + + Single.m_pcTitle = (char*) "Company"; + Single.m_pcData = (char*) "Tech Soft 3D"; + sAttribs.m_pcTitle = Single.m_pcTitle; + A3DMiscAttributeCreate(&sAttribs, &pAttr[2]); + + A3DRootBaseData sRootData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sRootData); + + sRootData.m_pcName = (char*) "Trimmed surface"; + sRootData.m_ppAttributes = pAttr; + sRootData.m_uiSize = 3; + A3DRootBaseSet(p, &sRootData); + + // cleaning up the allocated attributes + for(A3DUns32 i = 0; i < sRootData.m_uiSize; ++i) + A3DEntityDelete(sRootData.m_ppAttributes[i]); +} + +//###################################################################################################################### +/*! Creates the product occurrence and populates it with the part definition created by stCreatePart. + */ +A3DAsmProductOccurrence* stCreateOccurrence() +{ + A3DAsmProductOccurrence* pp = NULL; + A3DAsmPartDefinition* p = stCreatePart(); + if(p != NULL) + { + A3DAsmProductOccurrenceData sData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sData); + + sData.m_pPart = p; + + A3DInt32 iRet = A3DAsmProductOccurrenceCreate(&sData, &pp); + if(iRet == A3D_SUCCESS) + stSetAttributes(pp); + } + return pp; +} + +//###################################################################################################################### +/*! Create model file structure, build the model, and return the model file + */ +A3DAsmModelFile* stCreateModel() +{ + // Create the product occurrence + A3DAsmModelFile* pp = NULL; + A3DAsmProductOccurrence* p = stCreateOccurrence(); + if(p != NULL) + { + A3DAsmModelFileData sData; + A3D_INITIALIZE_DATA(A3DAsmModelFileData, sData); + + // In this model there will be only one product occurrence + sData.m_uiPOccurrencesSize = 1; + sData.m_dUnit = 1.0; + sData.m_ppPOccurrences = &p; + + A3DAsmModelFileCreate(&sData, &pp); + } + return pp; +} + +static MY_CHAR acDstFileName[_MAX_PATH * 2]; +static MY_CHAR acLogFileName[_MAX_PATH * 2]; + +//###################################################################################################################### +// Main function +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + // + // ### COMMAND LINE ARGUMENTS + // + + if (iArgc > 3 || iArgc < 2) + { + MY_PRINTF2("Usage:\n %s [output PRC file] [output LOG file]\n", ppcArgv[0]); + MY_PRINTF(" Default output LOG file is [output PRC file]_Log.txt\n\n"); + return A3D_ERROR; + } + + MY_STRCPY(acDstFileName, ppcArgv[1]); + + if (iArgc > 2) MY_STRCPY(acLogFileName, ppcArgv[2]); + else MY_SPRINTF(acLogFileName, "%s_Log.txt", acDstFileName); + GetLogFile(acLogFileName); // Initialize log file + + // + // ### INITIALIZE HOOPS EXCHANGE + // + + A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); + CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus); + + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + // + // ### PROCESS SAMPLE CODE + // + + // Model file is created programmatically + sHoopsExchangeLoader.m_psModelFile = stCreateModel(); + + // The command line argument ppcArgv[1] is the file name for the exported file + A3DExport sExport(acDstFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + + // Export the model + CHECK_RET(sHoopsExchangeLoader.Export(sExport)); + + // + // ### TERMINATE HOOPS EXCHANGE + // + + // Check memory allocations + return (int)ListLeaks(); +} diff --git a/exchange/exchangesource/CreatePRCBrepWithGeometry/CreatePRCBrepWithGeometry.vcxproj b/exchange/exchangesource/CreatePRCBrepWithGeometry/CreatePRCBrepWithGeometry.vcxproj new file mode 100644 index 0000000..5c1bfaa --- /dev/null +++ b/exchange/exchangesource/CreatePRCBrepWithGeometry/CreatePRCBrepWithGeometry.vcxproj @@ -0,0 +1,180 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {B0AA5CD9-263E-45CE-AE76-C53AA7307249} + CreatePRCBrepWithGeometry + Win32Proj + 10.0 + + + + Application + v145 + true + + + Application + v145 + false + + + Application + v145 + true + + + Application + v145 + false + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + LinkVerboseLib + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + false + + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + LinkVerboseLib + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + false + + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + Use + Level4 + ProgramDatabase + false + + + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + true + true + false + + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + Use + Level4 + ProgramDatabase + false + + + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + true + true + false + + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/CreatePRCBrepWithGeometry/CreatePRCBrepWithGeometry.vcxproj.filters b/exchange/exchangesource/CreatePRCBrepWithGeometry/CreatePRCBrepWithGeometry.vcxproj.filters new file mode 100644 index 0000000..17b7794 --- /dev/null +++ b/exchange/exchangesource/CreatePRCBrepWithGeometry/CreatePRCBrepWithGeometry.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + Source Files + + + \ No newline at end of file diff --git a/exchange/exchangesource/CreatePRCCubes/CreateModelFile.cpp b/exchange/exchangesource/CreatePRCCubes/CreateModelFile.cpp new file mode 100644 index 0000000..acb751f --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/CreateModelFile.cpp @@ -0,0 +1,651 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreateModelFile.cpp +* This file is containing the data and function used to create PRC Model file. +* +***********************************************************************************************************************/ +#include "CreateModelFile.h" + +#include "CreateTessellatedCubes.h" + +#include "modules/CreateMarkups.h" +#include "modules/CreateTextures.h" +#include "modules/CreateViews.h" + + +#include +#include +#include + + +//###################################################################################################################### +A3DStatus createCubeTessellation(A3DTess3D** ppTess3D, A3DUns32* puiStyleIndex) +{ + A3DStatus iRet = A3D_SUCCESS; + + // create a cube tessellation + A3DTess3DData sTess3DData; + fillCubeTessData(sTess3DData, puiStyleIndex); + CHECK_RET(A3DTess3DCreate(&sTess3DData, ppTess3D)); + freeTess3DData(sTess3DData); + + A3DTessBaseData sTessBaseData; + fillCubeTessBaseData(sTessBaseData, CUBE_WIDTH, CUBE_HEIGHT, CUBE_LENGTH); + CHECK_RET(A3DTessBaseSet(*ppTess3D, &sTessBaseData)); + freeTessBaseData(sTessBaseData); + + return iRet; +} + + +//###################################################################################################################### +A3DStatus createPolyBREPModel(A3DRiPolyBrepModel** ppPolyBREP, A3DTess3D* pTess3D) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DRiPolyBrepModelData sPolyBrepModelData; + A3D_INITIALIZE_DATA(A3DRiPolyBrepModelData, sPolyBrepModelData); + sPolyBrepModelData.m_bIsClosed = TRUE; + CHECK_RET(A3DRiPolyBrepModelCreate(&sPolyBrepModelData, ppPolyBREP)); + + // assign the cube tessellation to the PolyBrepModel + A3DRiRepresentationItemData sRiData; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, sRiData); + sRiData.m_pTessBase = pTess3D; + sRiData.m_pCoordinateSystem = NULL; + CHECK_RET(A3DRiRepresentationItemSet(*ppPolyBREP, &sRiData)); + + return iRet; +} + +A3DStatus createPart(A3DAsmPartDefinition** ppPartDef, A3DRiRepresentationItem** ppRIs, A3DUns32 uiRepItemsSize) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DAsmPartDefinitionData sPartDefinitionData; + A3D_INITIALIZE_DATA(A3DAsmPartDefinitionData, sPartDefinitionData); + sPartDefinitionData.m_uiRepItemsSize = uiRepItemsSize; + sPartDefinitionData.m_ppRepItems = ppRIs; + sPartDefinitionData.m_uiAnnotationsSize = 0; + CHECK_RET(A3DAsmPartDefinitionCreate(&sPartDefinitionData, ppPartDef)); + + return iRet; +} + +//###################################################################################################################### +// Create uiPrototypesSize prototypes of the instance PO pInstance. +A3DStatus createAssemblyTree(A3DAsmProductOccurrence* pInstance, A3DUns32 uiPrototypesSize, A3DAsmProductOccurrence*** pppPrototypes) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DAsmProductOccurrence** ppPrototypes = new A3DAsmProductOccurrence*[uiPrototypesSize]; + *pppPrototypes = ppPrototypes; + + setEntityName(pInstance, "Instance"); + A3DMiscAttribute* pAttribute = 0; + A3DMiscAttributeData sAttributeData; + A3D_INITIALIZE_DATA(A3DMiscAttributeData, sAttributeData); + sAttributeData.m_pcTitle = (A3DUTF8Char *)"Instance PO, holding data."; + CHECK_RET(A3DMiscAttributeCreate(&sAttributeData, &pAttribute)); + addEntityAttributes(pInstance, 1, &pAttribute); + + A3DEntityDelete(pAttribute); + + // New PO with prototype + A3DAsmProductOccurrenceData sPrototypePOData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sPrototypePOData); + sPrototypePOData.m_pPrototype = pInstance; // populating the PO Data Structure with the prototype + + for (A3DUns32 i = 0; i < uiPrototypesSize; ++i) + { + if (i > 0) + { + // create new location (color can also be modify) + A3DMiscCartesianTransformation* newLocation = NULL; + A3DMiscCartesianTransformationData newLocationData; + A3D_INITIALIZE_DATA(A3DMiscCartesianTransformationData, newLocationData); + newLocationData.m_sOrigin.m_dX = i * CUBE_SPACING; + newLocationData.m_sOrigin.m_dY = i * CUBE_SPACING; + newLocationData.m_sOrigin.m_dZ = i * CUBE_SPACING; + + newLocationData.m_sScale.m_dX = 1; + newLocationData.m_sScale.m_dY = 1; + newLocationData.m_sScale.m_dZ = 1; + + newLocationData.m_sXVector.m_dX = 1.0; + newLocationData.m_sXVector.m_dY = 0.0; + newLocationData.m_sXVector.m_dZ = 0.0; + + newLocationData.m_sYVector.m_dX = 0.0; + newLocationData.m_sYVector.m_dY = 1.0; + newLocationData.m_sYVector.m_dZ = 0.0; + newLocationData.m_ucBehaviour = kA3DTransformationTranslate | kA3DTransformationRotate; + + A3DMiscCartesianTransformationCreate(&newLocationData, &newLocation); + + // populating the PO Data Structure with the location + sPrototypePOData.m_pLocation = newLocation; + } + // create PO from PO Data structure + A3DAsmProductOccurrenceCreate(&sPrototypePOData, &ppPrototypes[i]); + + // add Base Info to enable graphics behaviors. + A3DRootBaseData sBaseData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sBaseData); + CHECK_RET(A3DRootBaseSet(ppPrototypes[i], &sBaseData)); + + // sample name + CHECK_RET(setEntityName(ppPrototypes[i], "Prototype")); + + // sample attribute + A3DMiscAttribute* pProtoAttribute=nullptr; + A3DMiscAttributeData sProtoAttributeData; + A3D_INITIALIZE_DATA(A3DMiscAttributeData, sProtoAttributeData); + sProtoAttributeData.m_pcTitle = (A3DUTF8Char *)"Prototype PO to an instance PO."; + CHECK_RET(A3DMiscAttributeCreate(&sProtoAttributeData, &pProtoAttribute)); + + CHECK_RET(addEntityAttributes(ppPrototypes[i], 1, &pProtoAttribute)); + A3DEntityDelete(pProtoAttribute); + } + + // we set the last cube blue, redefining the texture graphics + setEntityColor(ppPrototypes[uiPrototypesSize - 1], BLUE, 0.5); + + return iRet; +} + + +//###################################################################################################################### +A3DStatus createFileMarkups(A3DMkpAnnotationItem** ppOutAnnotationsSet, + A3DUns32 uiPrototypesSize, A3DAsmProductOccurrence** ppPrototypes, + A3DRiPolyBrepModel* pRiPolyBrepModel) +{ + A3DStatus iRet = A3D_SUCCESS; + + std::vector vpAnnotations; + + A3DMkpAnnotationItem* pNewAnnotation = 0; + + A3DAsmProductOccurrence* pCurrentPO = 0; + A3DUns32 uiPOCurrentIndex = 0; + + // ------------------------------------------------------------------ + // initialize markups position. + A3DVector3dData sAnnotationLeaderPos; + A3D_INITIALIZE_DATA(A3DVector3dData, sAnnotationLeaderPos); + A3DVector3dData sAnnotationLeaderPosOffset; + A3D_INITIALIZE_DATA(A3DVector3dData, sAnnotationLeaderPosOffset); + sAnnotationLeaderPosOffset.m_dX = 0; + sAnnotationLeaderPosOffset.m_dY = 0; + sAnnotationLeaderPosOffset.m_dZ = CUBE_HEIGHT; + + A3DVector3dData sAnnotationFramePos; + A3D_INITIALIZE_DATA(A3DVector3dData, sAnnotationFramePos); + A3DVector3dData sAnnotationFramePosOffset; + A3D_INITIALIZE_DATA(A3DVector3dData, sAnnotationFramePosOffset); + sAnnotationFramePosOffset.m_dX = 1 * CUBE_WIDTH; + sAnnotationFramePosOffset.m_dY = 1 * CUBE_LENGTH; + sAnnotationFramePosOffset.m_dZ = 2 * CUBE_HEIGHT; + + + // ------------------------------------------------------------------ + // simple markup + A3DUTF8Char *pcTextSimpleMarkup = (A3DUTF8Char *)"Simple"; + + pCurrentPO = ppPrototypes[uiPOCurrentIndex]; + ++uiPOCurrentIndex; + + CHECK_RET(getPOLocationOrigin(pCurrentPO, &sAnnotationLeaderPos)); + sAnnotationLeaderPos.m_dX += sAnnotationLeaderPosOffset.m_dX; + sAnnotationLeaderPos.m_dY += sAnnotationLeaderPosOffset.m_dY; + sAnnotationLeaderPos.m_dZ += sAnnotationLeaderPosOffset.m_dZ; + + CHECK_RET(getPOLocationOrigin(pCurrentPO, &sAnnotationFramePos)); + sAnnotationFramePos.m_dX += sAnnotationFramePosOffset.m_dX; + sAnnotationFramePos.m_dY += sAnnotationFramePosOffset.m_dY; + sAnnotationFramePos.m_dZ += sAnnotationFramePosOffset.m_dZ; + + CHECK_RET(createMarkup(&pNewAnnotation, + pcTextSimpleMarkup, + 1, + &pRiPolyBrepModel, + &pCurrentPO, + &sAnnotationFramePos, + &sAnnotationLeaderPos)); + + vpAnnotations.push_back(pNewAnnotation); + + // ------------------------------------------------------------------ + // Markup on a face + A3DUTF8Char *pcTextOnFace = (A3DUTF8Char *)"Face"; + + pCurrentPO = ppPrototypes[uiPOCurrentIndex]; + ++uiPOCurrentIndex; + + CHECK_RET(getPOLocationOrigin(pCurrentPO, &sAnnotationLeaderPos)); + sAnnotationLeaderPos.m_dX += sAnnotationLeaderPosOffset.m_dX; + sAnnotationLeaderPos.m_dY += sAnnotationLeaderPosOffset.m_dY; + sAnnotationLeaderPos.m_dZ += sAnnotationLeaderPosOffset.m_dZ; + + CHECK_RET(getPOLocationOrigin(pCurrentPO, &sAnnotationFramePos)); + sAnnotationFramePos.m_dX += sAnnotationFramePosOffset.m_dX; + sAnnotationFramePos.m_dY += sAnnotationFramePosOffset.m_dY; + sAnnotationFramePos.m_dZ += sAnnotationFramePosOffset.m_dZ; + + A3DUns32 uiFaceIndex = 0; + CHECK_RET(createMarkupOnFace(&pNewAnnotation, + pcTextOnFace, + 1, + &pRiPolyBrepModel, + &pCurrentPO, + &uiFaceIndex, + &sAnnotationFramePos, + &sAnnotationLeaderPos)); + + vpAnnotations.push_back(pNewAnnotation); + + // ------------------------------------------------------------------ + // Markup parrallel to screen + A3DUTF8Char *pcTextParallel = (A3DUTF8Char *)"Parallel"; + + pCurrentPO = ppPrototypes[uiPOCurrentIndex]; + ++uiPOCurrentIndex; + + CHECK_RET(getPOLocationOrigin(pCurrentPO, &sAnnotationFramePos)); + sAnnotationFramePos.m_dX += sAnnotationFramePosOffset.m_dX; + sAnnotationFramePos.m_dY += sAnnotationFramePosOffset.m_dY; + sAnnotationFramePos.m_dZ += sAnnotationFramePosOffset.m_dZ; + + CHECK_RET(createMarkupFaceToScreen(&pNewAnnotation, + pcTextParallel, + 1, + &pRiPolyBrepModel, + &pCurrentPO, + &sAnnotationFramePos)); + + vpAnnotations.push_back(pNewAnnotation); + + // ------------------------------------------------------------------ + // Markup non Zoomable + A3DUTF8Char *pcTextZoomable = (A3DUTF8Char *)"Non zoomable"; + + pCurrentPO = ppPrototypes[uiPOCurrentIndex]; + ++uiPOCurrentIndex; + + CHECK_RET(getPOLocationOrigin(pCurrentPO, &sAnnotationFramePos)); + sAnnotationFramePos.m_dX += sAnnotationFramePosOffset.m_dX; + sAnnotationFramePos.m_dY += sAnnotationFramePosOffset.m_dY; + sAnnotationFramePos.m_dZ += sAnnotationFramePosOffset.m_dZ; + + CHECK_RET(createMarkupFaceToScreen(&pNewAnnotation, + pcTextZoomable, + 1, + &pRiPolyBrepModel, + &pCurrentPO, + &sAnnotationFramePos, + FlatToScreenNonZoomable)); + + vpAnnotations.push_back(pNewAnnotation); + + // ------------------------------------------------------------------ + // Markup non Zoomable + A3DUTF8Char *pcTextAttached = (A3DUTF8Char *)"OnTop"; + + pCurrentPO = ppPrototypes[uiPOCurrentIndex]; + ++uiPOCurrentIndex; + + CHECK_RET(getPOLocationOrigin(pCurrentPO, &sAnnotationFramePos)); + sAnnotationFramePos.m_dX += sAnnotationFramePosOffset.m_dX; + sAnnotationFramePos.m_dY += sAnnotationFramePosOffset.m_dY; + sAnnotationFramePos.m_dZ += sAnnotationFramePosOffset.m_dZ; + + CHECK_RET(createMarkupFaceToScreen(&pNewAnnotation, + pcTextAttached, + 1, + &pRiPolyBrepModel, + &pCurrentPO, + &sAnnotationFramePos, + FlatToScreenAlwaysOnTop)); + + vpAnnotations.push_back(pNewAnnotation); + + // ------------------------------------------------------------------ + // Highlight all prototypes passed + A3DUTF8Char *pcTextHighlightAll = (A3DUTF8Char *)"Highlight All"; + A3DVector3dData sHighlightAllPos; + A3D_INITIALIZE_DATA(A3DVector3dData, sHighlightAllPos); + sHighlightAllPos.m_dX = -4 * CUBE_WIDTH; + sHighlightAllPos.m_dY = -4 * CUBE_LENGTH; + sHighlightAllPos.m_dZ = -4 * CUBE_HEIGHT; + + std::vector vpLinkedEntity; + std::vector vpPOTarget; + for (A3DUns32 i = 0; i < uiPrototypesSize; ++i) + { + vpLinkedEntity.push_back(pRiPolyBrepModel); + vpPOTarget.push_back(ppPrototypes[i]); + } + + CHECK_RET(createMarkupFaceToScreen(&pNewAnnotation, + pcTextHighlightAll, + uiPrototypesSize, + &vpLinkedEntity[0], + &vpPOTarget[0], + &sHighlightAllPos)); + + vpAnnotations.push_back(pNewAnnotation); + vpLinkedEntity.clear(); + vpPOTarget.clear(); + + + // ------------------------------------------------------------------ + // Create a Markup Set and add markups in it + A3DMkpAnnotationSetData sAnnotationSetData; + A3D_INITIALIZE_DATA(A3DMkpAnnotationSetData, sAnnotationSetData); + sAnnotationSetData.m_uiAnnotationsSize = (A3DUns32)vpAnnotations.size(); + sAnnotationSetData.m_ppAnnotations = &(vpAnnotations[0]); + CHECK_RET(A3DMkpAnnotationSetCreate(&sAnnotationSetData, ppOutAnnotationsSet)); + vpAnnotations.clear(); + + return iRet; +} + +//###################################################################################################################### +A3DStatus createFileViews(A3DUns32* puiOutMkpViewSize, A3DMkpView*** pppOutMkpViews, + A3DUns32 uiPrototypesSize, A3DAsmProductOccurrence** ppPrototypes, + A3DUns32 uiAnnotationSize, A3DMkpAnnotationItem** ppMkpAnnotationItem, + A3DRiPolyBrepModel* pRiPolyBrepModel) +{ + A3DStatus iRet = A3D_SUCCESS; + + std::vector vpMkpViews; + *puiOutMkpViewSize = 0; + + A3DVector3dData sCameraPos; + A3DVector3dData sCameraLookAt; + + // ------------------------------------------------------------------ + // "A View With A Camera" + A3D_INITIALIZE_DATA(A3DVector3dData, sCameraPos); + sCameraPos.m_dX = stCameraPosDefault.m_dX; + sCameraPos.m_dY = stCameraPosDefault.m_dY; + sCameraPos.m_dZ = stCameraPosDefault.m_dZ; + + A3D_INITIALIZE_DATA(A3DVector3dData, sCameraLookAt); + sCameraLookAt.m_dX = stCameraLookAtDefault.m_dX; + sCameraLookAt.m_dY = stCameraLookAtDefault.m_dY; + sCameraLookAt.m_dZ = stCameraLookAtDefault.m_dZ; + + A3DMkpView* pMkpViewWithCamera = 0; + A3DMkpViewData sMkpViewWithCamera; + A3D_INITIALIZE_DATA(A3DMkpViewData, sMkpViewWithCamera); + CHECK_RET(setViewCameraPlacement(&sMkpViewWithCamera, &sCameraPos, &sCameraLookAt, -1, -1)); + + CHECK_RET(createView(&pMkpViewWithCamera, &sMkpViewWithCamera, "Define New Camera")); + + vpMkpViews.push_back(pMkpViewWithCamera); + + // ------------------------------------------------------------------ + // "A View That Hide Objects" + A3DAsmProductOccurrence* ppPOsToHide[3]; + ppPOsToHide[0] = ppPrototypes[0]; + ppPOsToHide[1] = ppPrototypes[2]; + ppPOsToHide[2] = ppPrototypes[4]; + + A3DRootBaseWithGraphicsData sRootBaseWithGraphicsHiddenData; + A3D_INITIALIZE_DATA(A3DRootBaseWithGraphicsData, sRootBaseWithGraphicsHiddenData); + CHECK_RET(setGraphicsHidden(&sRootBaseWithGraphicsHiddenData)); + + A3DMkpViewData sMkpViewHidingObjects; + A3D_INITIALIZE_DATA(A3DMkpViewData, sMkpViewHidingObjects); + CHECK_RET(setViewEntitiesGraphics(&sMkpViewHidingObjects, 3, ppPOsToHide, &sRootBaseWithGraphicsHiddenData)); + CHECK_RET(A3DGraphicsDelete(sRootBaseWithGraphicsHiddenData.m_pGraphics)); + + A3DMkpView* pMkpViewHidingObjects = 0; + CHECK_RET(createView(&pMkpViewHidingObjects, &sMkpViewHidingObjects, "Hide Objects")); + vpMkpViews.push_back(pMkpViewHidingObjects); + free(sMkpViewHidingObjects.m_ppLinkedItems); + + // ------------------------------------------------------------------ + // "A View That Change Objects Color" + + A3DAsmProductOccurrence* ppPOsToChangeColor[2]; + ppPOsToChangeColor[0] = ppPrototypes[1]; + ppPOsToChangeColor[1] = ppPrototypes[3]; + + A3DRootBaseWithGraphicsData sRootBaseWithGraphicsYellowColorData; + A3D_INITIALIZE_DATA(A3DRootBaseWithGraphicsData, sRootBaseWithGraphicsYellowColorData); + CHECK_RET(setGraphicsColor(&sRootBaseWithGraphicsYellowColorData, YELLOW, 1.0)); + + A3DMkpViewData sMkpViewChangingObjectColor; + A3D_INITIALIZE_DATA(A3DMkpViewData, sMkpViewChangingObjectColor); + CHECK_RET(setViewEntitiesGraphics(&sMkpViewChangingObjectColor, 2, ppPOsToChangeColor, &sRootBaseWithGraphicsYellowColorData)); + CHECK_RET(A3DGraphicsDelete(sRootBaseWithGraphicsYellowColorData.m_pGraphics)); + + A3DMkpView* pMkpViewChangingObjectColor = 0; + CHECK_RET(createView(&pMkpViewChangingObjectColor, &sMkpViewChangingObjectColor, "Change Objects Color")); + vpMkpViews.push_back(pMkpViewChangingObjectColor); + free(sMkpViewChangingObjectColor.m_ppLinkedItems); + + // ------------------------------------------------------------------ + // "A View That Change Face Color" + A3DMiscMarkupLinkedItem* pMarkupLinkedItem = NULL; + A3DUns32 faceindex[1]; + faceindex[0] = 0; + CHECK_RET(createMarkupLinkedItemOnTess(pRiPolyBrepModel, kA3DTypeTessFace, 1, faceindex, ppPrototypes[2], &pMarkupLinkedItem)); + + A3DMiscMarkupLinkedItem* ppLinkedItemsToChangeColorOnFace[1]; + ppLinkedItemsToChangeColorOnFace[0] = pMarkupLinkedItem; + + A3DRootBaseWithGraphicsData sRootBaseWithGraphicsGreenColorData; + A3D_INITIALIZE_DATA(A3DRootBaseWithGraphicsData, sRootBaseWithGraphicsGreenColorData); + CHECK_RET(setGraphicsColor(&sRootBaseWithGraphicsGreenColorData, GREEN, 1.0)); + CHECK_RET(A3DRootBaseWithGraphicsSet(ppLinkedItemsToChangeColorOnFace[0], &sRootBaseWithGraphicsGreenColorData)); + CHECK_RET(A3DGraphicsDelete(sRootBaseWithGraphicsGreenColorData.m_pGraphics)); + + A3DMkpViewData sMkpViewChangingFaceColor; + A3D_INITIALIZE_DATA(A3DMkpViewData, sMkpViewChangingFaceColor); + CHECK_RET(addViewLinkedItem(&sMkpViewChangingFaceColor, 1, ppLinkedItemsToChangeColorOnFace)); + + A3DMkpView* pMkpViewChangingFaceColor = 0; + CHECK_RET(createView(&pMkpViewChangingFaceColor, &sMkpViewChangingFaceColor, "Change Face Color")); + vpMkpViews.push_back(pMkpViewChangingFaceColor); + free(sMkpViewChangingFaceColor.m_ppLinkedItems); + + // ------------------------------------------------------------------ + // "A View With Visible Annotation" + A3DMkpAnnotationItem* ppAnnotations[2]; + ppAnnotations[0] = ppMkpAnnotationItem[1]; + ppAnnotations[1] = ppMkpAnnotationItem[2]; + + A3DMkpViewData sMkpViewWithAnnotation; + A3D_INITIALIZE_DATA(A3DMkpViewData, sMkpViewWithAnnotation); + CHECK_RET(setViewAnnotations(&sMkpViewWithAnnotation, 2, ppAnnotations)); + + A3DMkpView* pMkpViewWithAnnotation = 0; + CHECK_RET(createView(&pMkpViewWithAnnotation, &sMkpViewWithAnnotation, "Visible Annotation")); + vpMkpViews.push_back(pMkpViewWithAnnotation); + + // ------------------------------------------------------------------ + // "A View With That Change Object Position" + A3DMiscCartesianTransformation* ppTransformations[3]; + A3DMiscCartesianTransformationData sTransformationData; + A3D_INITIALIZE_DATA(A3DMiscCartesianTransformationData, sTransformationData); + sTransformationData.m_sOrigin.m_dX = CUBE_SPACING + CUBE_SPACING; + sTransformationData.m_sOrigin.m_dY = CUBE_SPACING; + sTransformationData.m_sOrigin.m_dZ = CUBE_SPACING; + sTransformationData.m_sXVector.m_dX = 1.; + sTransformationData.m_sXVector.m_dY = 0.; + sTransformationData.m_sXVector.m_dZ = 0.; + sTransformationData.m_sYVector.m_dX = 0.; + sTransformationData.m_sYVector.m_dY = 1.; + sTransformationData.m_sYVector.m_dZ = 0.; + sTransformationData.m_sScale.m_dX = 1.; + sTransformationData.m_sScale.m_dY = 1.; + sTransformationData.m_sScale.m_dZ = 1.; + CHECK_RET(A3DMiscCartesianTransformationCreate(&sTransformationData, &ppTransformations[0])); + CHECK_RET(A3DMiscCartesianTransformationCreate(&sTransformationData, &ppTransformations[1])); + CHECK_RET(A3DMiscCartesianTransformationCreate(&sTransformationData, &ppTransformations[2])); + + A3DAsmProductOccurrence* ppPOsToChangePos[3]; + ppPOsToChangePos[0] = ppPrototypes[0]; + ppPOsToChangePos[1] = ppPrototypes[1]; + ppPOsToChangePos[2] = ppPrototypes[2]; + + A3DMkpViewData sMkpViewChangeObjectPos; + A3D_INITIALIZE_DATA(A3DMkpViewData, sMkpViewChangeObjectPos); + CHECK_RET(setViewEntitiesOffsetPosition(&sMkpViewChangeObjectPos, 3, ppPOsToChangePos, ppTransformations)); + A3DEntityDelete(ppTransformations[0]); + A3DEntityDelete(ppTransformations[1]); + A3DEntityDelete(ppTransformations[2]); + + A3DMkpView* pMkpViewChangeObjectPos = 0; + CHECK_RET(createView(&pMkpViewChangeObjectPos, &sMkpViewChangeObjectPos, "Change Object Position")); + vpMkpViews.push_back(pMkpViewChangeObjectPos); + free(sMkpViewChangeObjectPos.m_ppLinkedItems); + + // ------------------------------------------------------------------ + // "Default View with Camera and all annotations" + A3D_INITIALIZE_DATA(A3DVector3dData, sCameraPos); + sCameraPos.m_dX = 0; + sCameraPos.m_dY = 0; + sCameraPos.m_dZ = uiPrototypesSize * (CUBE_LENGTH + CUBE_SPACING); + + A3D_INITIALIZE_DATA(A3DVector3dData, sCameraLookAt); + sCameraLookAt.m_dX = uiPrototypesSize * (CUBE_WIDTH + CUBE_SPACING) / 2.; + sCameraLookAt.m_dY = uiPrototypesSize * (CUBE_HEIGHT + CUBE_SPACING) / 2.; + sCameraLookAt.m_dZ = uiPrototypesSize * CUBE_LENGTH; + + A3DDouble dXFovy = (uiPrototypesSize +1) * (CUBE_WIDTH + CUBE_SPACING) / 2.; + A3DDouble dYFovy = (uiPrototypesSize +1) * (CUBE_HEIGHT + CUBE_SPACING) / 2.; + + A3DMkpViewData sMkpViewDefault; + A3D_INITIALIZE_DATA(A3DMkpViewData, sMkpViewDefault); + CHECK_RET(setViewCameraPlacement(&sMkpViewDefault, &sCameraPos, &sCameraLookAt, dXFovy, dYFovy)); + CHECK_RET(setViewAnnotations(&sMkpViewDefault, uiAnnotationSize, ppMkpAnnotationItem)); + + A3DMkpView* pMkpViewDefault = 0; + CHECK_RET(createView(&pMkpViewDefault, &sMkpViewDefault, "Default View")); + vpMkpViews.push_back(pMkpViewDefault); + + + // ------------------------------------------------------------------ + // copy view vector + *puiOutMkpViewSize = (A3DUns32)vpMkpViews.size(); + A3DMkpView** ppMkpViews = new A3DMkpView*[vpMkpViews.size()]; + for (A3DUns32 i = 0; i < (A3DUns32)vpMkpViews.size(); ++i) + { + ppMkpViews[i] = vpMkpViews[i]; + } + *pppOutMkpViews = ppMkpViews; + + + return iRet; +} + +//###################################################################################################################### +A3DStatus createPRCCubesFile(A3DAsmModelFile** ppModelFile, const A3DUTF8Char* pcTextureFilePath = NULL) +{ + A3DStatus iRet = A3D_SUCCESS; + + // ------------------------------------------------------------------ + // create Texture if needed + A3DUns32 uiStyleIndex = A3D_DEFAULT_STYLE_INDEX; // will become the texture index + + if (pcTextureFilePath != NULL) + { + // the picture width and height are read from the image (for supported image types), + // and since we don't know them, width and height can be 0 + iRet = createTexture(pcTextureFilePath, kA3DPictureJpg, 0, 0, uiStyleIndex); // JPG + //iRet = createTexture(pcTextureFilePath, kA3DPicturePng, 0, 0, uiStyleIndex); // PNG + } + + // ------------------------------------------------------------------ + // create a cube tessellation + A3DTess3D* pTess3D = NULL; + CHECK_RET(createCubeTessellation(&pTess3D, &uiStyleIndex)); + + // ------------------------------------------------------------------ + // create a PolyBrepModel representation item + A3DRiPolyBrepModel *pRiPolyBrepModel = NULL; + CHECK_RET(createPolyBREPModel(&pRiPolyBrepModel, pTess3D)); + + // ------------------------------------------------------------------ + // create a PartDefinition to hold the PolyBrepModel and markups + A3DAsmPartDefinition *pPartDefinition = NULL; + CHECK_RET(createPart(&pPartDefinition, &pRiPolyBrepModel, 1)); + + // ------------------------------------------------------------------ + // create a ProductOccurrence to stock the Part Definition + A3DAsmProductOccurrence* pPO = NULL; + A3DAsmProductOccurrenceData sPOData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sPOData); + sPOData.m_pPart = pPartDefinition; + CHECK_RET(A3DAsmProductOccurrenceCreate(&sPOData, &pPO)); + + // ------------------------------------------------------------------ + // Create Prototypes + // Create N PO using previous PO as prototype + A3DUns32 uiPOSize = 6; + A3DAsmProductOccurrence** ppPOs = 0; + + CHECK_RET(createAssemblyTree(pPO, uiPOSize, &ppPOs)); + + // ------------------------------------------------------------------ + // create Markups + A3DMkpAnnotationItem* pMkpAnnotationSet = 0; + CHECK_RET(createFileMarkups(&pMkpAnnotationSet, uiPOSize, ppPOs, pRiPolyBrepModel)); + + // ------------------------------------------------------------------ + // create Views + A3DUns32 uiMkpViewsSize = 0; + A3DMkpView** ppMkpViews = 0; + A3DMkpAnnotationSetData sAnnotationSetData; + A3D_INITIALIZE_DATA(A3DMkpAnnotationSetData, sAnnotationSetData); + CHECK_RET(A3DMkpAnnotationSetGet(pMkpAnnotationSet, &sAnnotationSetData)); + CHECK_RET(createFileViews(&uiMkpViewsSize, &ppMkpViews, + uiPOSize, ppPOs, + sAnnotationSetData.m_uiAnnotationsSize, sAnnotationSetData.m_ppAnnotations, + pRiPolyBrepModel)); + CHECK_RET(A3DMkpAnnotationSetGet(nullptr,&sAnnotationSetData)); + // ------------------------------------------------------------------ + // create the Root Product Occurrence. + A3DAsmProductOccurrence* pSubAsm = NULL; + A3DAsmProductOccurrenceData sSubAsmData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sSubAsmData); + sSubAsmData.m_uiPOccurrencesSize = uiPOSize; + sSubAsmData.m_ppPOccurrences = ppPOs; + if (pMkpAnnotationSet) + { + sSubAsmData.m_uiAnnotationsSize = 1; + sSubAsmData.m_ppAnnotations = &pMkpAnnotationSet; + } + sSubAsmData.m_uiViewsSize = uiMkpViewsSize; + sSubAsmData.m_ppViews = ppMkpViews; + CHECK_RET(A3DAsmProductOccurrenceCreate(&sSubAsmData, &pSubAsm)); + + // delete allocated datas + if (uiPOSize != 0) delete ppPOs; + if (uiMkpViewsSize != 0) delete ppMkpViews; + + // ------------------------------------------------------------------ + // Insertion of the whole product structure in the modelfile + A3DAsmModelFileData sData; + A3D_INITIALIZE_DATA(A3DAsmModelFileData, sData); + sData.m_uiPOccurrencesSize = 1; + sData.m_dUnit = 1.0; + sData.m_ppPOccurrences = &pSubAsm; + CHECK_RET(A3DAsmModelFileCreate(&sData, ppModelFile)); + + return iRet; +} diff --git a/exchange/exchangesource/CreatePRCCubes/CreateModelFile.h b/exchange/exchangesource/CreatePRCCubes/CreateModelFile.h new file mode 100644 index 0000000..485e2d4 --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/CreateModelFile.h @@ -0,0 +1,28 @@ +#pragma once +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreateTextures.cpp +* This file is containing the function allowing to create textures. +* +* Texture creation exemple +* Create the style corresponding to texture. +* +* +***********************************************************************************************************************/ +#pragma once + +#include "CreatePRCCubesDef.h" + +//###################################################################################################################### +// Create the style corresponding to texture. +A3DStatus createPRCCubesFile(A3DAsmModelFile** ppModelFile, const A3DUTF8Char* pcTextureFilePath); diff --git a/exchange/exchangesource/CreatePRCCubes/CreatePRCCubes.cpp b/exchange/exchangesource/CreatePRCCubes/CreatePRCCubes.cpp new file mode 100644 index 0000000..8cef3bf --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/CreatePRCCubes.cpp @@ -0,0 +1,126 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreatePRCCubes.cpp +* This file is containing the main trunc of the CreatePRCCubes sample. +* +* The purpose of this sample is to propose an embryo set of functionality allowing the creation of various PRC entities. +* It proposes and tackles different modules such as: +* - creation of markups: see CreateMarkups.cpp +* - creation of views: see CreateViews.cpp +* - creation of textures: see CreateTextures.cpp +* - creation of colors: see CreateGraphics.cpp +* - creation of links between entities: see CreateLinkedItem.cpp +* +* Inside this files is created either a PRC or a PDF file with a defined structures, +* a certain number of markups and a certain number of views. +* +* The function createAssemblyTree, createFileMarkups, createFileViews +* can be modified to create your own PRC or PDF file: +* modifying the structure can be done in createAssemblyTree. +* modifying the views can be done in createFileViews. +* modifying the markups can be done in createFileMarkups. +* +* It should be the reference sample for PRC entity creation but is also a great tool to understand how the PRC tree is working. +* +***********************************************************************************************************************/ + +#define INITIALIZE_A3D_API +#include "CreatePRCCubesDef.h" +#include "CreateModelFile.h" +#include + +static MY_CHAR acDstFileName[_MAX_PATH * 2]; +static MY_CHAR acJpgFileName[_MAX_PATH * 2]; +static MY_CHAR acLogFileName[_MAX_PATH * 2]; + + +//###################################################################################################################### + +/* +void debugCheckRet() +{ + printf("debug"); +} + +#define CHECK_RET(function_call) {\ + iRet = function_call; if(iRet != A3D_SUCCESS) { debugCheckRet(); std::cout << "Error number=" << iRet << std::endl; return iRet; }\ +} +*/ + + + +//###################################################################################################################### +// Main function +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + // + // ### COMMAND LINE ARGUMENTS + // + + if (iArgc > 4 || iArgc < 2) + { + MY_PRINTF2("Usage:\n %s [output PRC file] [existing JPG file] [output LOG file]\n", ppcArgv[0]); + MY_PRINTF(" Default existing JPG file is [output PRC file].jpg\n"); + MY_PRINTF(" Default output LOG file is [output PRC file]_Log.txt\n\n"); + return A3D_ERROR; + } + + MY_STRCPY(acDstFileName, ppcArgv[1]); + + if (iArgc > 2) MY_STRCPY(acJpgFileName, ppcArgv[2]); + else MY_SPRINTF(acJpgFileName, "%s.jpg", acDstFileName); + if (iArgc > 3) MY_STRCPY(acLogFileName, ppcArgv[3]); + else MY_SPRINTF(acLogFileName, "%s_Log.txt", acDstFileName); + GetLogFile(acLogFileName); // Initialize log file + + // + // ### INITIALIZE HOOPS EXCHANGE + // + + A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); + CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus); + + // Initialize callbacks + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + // + // ### PROCESS SAMPLE CODE + // + + A3DUTF8Char sJPGFileNameUTF8[_MAX_PATH]; +#ifdef _MSC_VER + A3DMiscUTF16ToUTF8(acJpgFileName, sJPGFileNameUTF8); +#else + MY_STRCPY(sJPGFileNameUTF8, acJpgFileName); +#endif + CHECK_RET(createPRCCubesFile(&sHoopsExchangeLoader.m_psModelFile, sJPGFileNameUTF8)); + + if (sHoopsExchangeLoader.m_psModelFile) + { + A3DExport sExport(acDstFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + CHECK_RET(sHoopsExchangeLoader.Export(sExport)); + } + + // + // ### TERMINATE HOOPS EXCHANGE + // + + // Check memory allocations + return (int)ListLeaks(); + +} diff --git a/exchange/exchangesource/CreatePRCCubes/CreatePRCCubes.vcxproj b/exchange/exchangesource/CreatePRCCubes/CreatePRCCubes.vcxproj new file mode 100644 index 0000000..124f2b7 --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/CreatePRCCubes.vcxproj @@ -0,0 +1,207 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {BC7D4477-04C9-426D-93A1-3401DFD12A0F} + CreatePRCCubes + Win32Proj + 10.0 + + + + Application + v145 + true + + + Application + v145 + false + + + Application + v145 + true + + + Application + v145 + false + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + NotUsing + Level4 + ProgramDatabase + false + + + + + LinkVerboseLib + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + false + + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + NotUsing + Level4 + ProgramDatabase + false + + + + + LinkVerboseLib + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + false + + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + NotUsing + Level4 + ProgramDatabase + false + + + + + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + true + true + false + + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + NotUsing + Level4 + ProgramDatabase + false + + + + + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + true + true + false + + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/CreatePRCCubes/CreatePRCCubes.vcxproj.filters b/exchange/exchangesource/CreatePRCCubes/CreatePRCCubes.vcxproj.filters new file mode 100644 index 0000000..2be458e --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/CreatePRCCubes.vcxproj.filters @@ -0,0 +1,98 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {23b8ef04-6569-4cf4-af31-43582f5c740c} + + + {7bcb00e4-9093-4036-aa36-52d8159d90b6} + + + {0cd497a1-32aa-47ca-9344-e9b84346f5c2} + + + {99e4792e-f4f5-43a5-8da0-c4b7fad52fd5} + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files\tessellation_wrapper + + + Source Files\tessellation_wrapper + + + Source Files\tessellation_wrapper + + + Source Files\modules + + + Source Files\modules + + + Source Files\modules + + + Source Files\modules + + + Source Files\modules + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files\tessellation_wrapper + + + Header Files\tessellation_wrapper + + + Header Files\tessellation_wrapper + + + Header Files\modules + + + Header Files\modules + + + Header Files\modules + + + Header Files\modules + + + Header Files\modules + + + \ No newline at end of file diff --git a/exchange/exchangesource/CreatePRCCubes/CreatePRCCubesDef.cpp b/exchange/exchangesource/CreatePRCCubes/CreatePRCCubesDef.cpp new file mode 100644 index 0000000..3fd136b --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/CreatePRCCubesDef.cpp @@ -0,0 +1,75 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreatePRCCubesDef.h +* +* Includes and defines variable used in the rest of the project. +* +***********************************************************************************************************************/ + + +#include "CreatePRCCubesDef.h" + +//###################################################################################################################### +A3DStatus setEntityName(A3DEntity* pEntity, const A3DUTF8Char* pName) +{ + A3DStatus iRet = A3D_SUCCESS; + if (pEntity != NULL) + { + A3DRootBaseData sBaseData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sBaseData); + CHECK_RET(A3DRootBaseGet(pEntity, &sBaseData)); + A3DUTF8Char* pTmpStr = sBaseData.m_pcName; + sBaseData.m_pcName = (A3DUTF8Char*) pName; + CHECK_RET(A3DRootBaseSet(pEntity, &sBaseData)); + sBaseData.m_pcName = pTmpStr; + CHECK_RET(A3DRootBaseGet(nullptr, &sBaseData)); + } + return iRet; +} + +//###################################################################################################################### +A3DStatus addEntityAttributes(A3DEntity* pEntity, A3DUns32 uiAttributeSize, A3DMiscAttribute** ppAttributes) +{ + A3DStatus iRet = A3D_SUCCESS; + + if (pEntity != NULL) + { + CHECK_RET(A3DRootBaseAttributeAppend(pEntity, uiAttributeSize, ppAttributes)); + } + + return iRet; +} + + +//###################################################################################################################### +A3DStatus getPOLocationOrigin(A3DAsmProductOccurrence* pPO, A3DVector3dData* pOutPos) +{ + A3DStatus iRet = A3D_SUCCESS; + if (pOutPos == 0) return A3D_ERROR; + + A3DAsmProductOccurrenceData sPOData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sPOData); + CHECK_RET(A3DAsmProductOccurrenceGet(pPO, &sPOData)); + + if (sPOData.m_pLocation) + { + A3DMiscCartesianTransformationData sTransforamationData; + A3D_INITIALIZE_DATA(A3DMiscCartesianTransformationData, sTransforamationData); + CHECK_RET(A3DMiscCartesianTransformationGet(sPOData.m_pLocation, &sTransforamationData)); + pOutPos->m_dX = sTransforamationData.m_sOrigin.m_dX; + pOutPos->m_dY = sTransforamationData.m_sOrigin.m_dY; + pOutPos->m_dZ = sTransforamationData.m_sOrigin.m_dZ; + } + + return iRet; +} diff --git a/exchange/exchangesource/CreatePRCCubes/CreatePRCCubesDef.h b/exchange/exchangesource/CreatePRCCubes/CreatePRCCubesDef.h new file mode 100644 index 0000000..89cf5a4 --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/CreatePRCCubesDef.h @@ -0,0 +1,43 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreatePRCCubesDef.h +* +* Includes, macros and tools used in the rest of the project. +* +* +***********************************************************************************************************************/ +#pragma once + +#include +#include + +#include "../common.hpp" + +//###################################################################################################################### +#define INFINITE_COORD 12345.0 +#define PI 3.14159265358979323846 + +#define CUBE_WIDTH 50 +#define CUBE_HEIGHT 50 +#define CUBE_LENGTH 50 +#define CUBE_SPACING 300 + + +//###################################################################################################################### +A3DStatus setEntityName(A3DEntity* pEntity, const A3DUTF8Char* pName); +A3DStatus addEntityAttributes(A3DEntity* pEntity, A3DUns32 uiAttributeSize, A3DMiscAttribute** ppAttributes); + +A3DStatus getPOLocationOrigin(A3DAsmProductOccurrence* pPO, A3DVector3dData* pOutPos); + + + diff --git a/exchange/exchangesource/CreatePRCCubes/CreateTessellatedCubes.cpp b/exchange/exchangesource/CreatePRCCubes/CreateTessellatedCubes.cpp new file mode 100644 index 0000000..3f44862 --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/CreateTessellatedCubes.cpp @@ -0,0 +1,188 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreateTessellatedCubes.cpp +* This file is containing the data and function used to create PRC Tessellation. +* +* fillCubeTessBaseData is filling the structure A3DTessBaseData +* A3DTessBaseData is the structure containing the coordinates of the tessellation. +* +* fillCubeTessData is filling the structure A3DTess3DData +* A3DTess3DData is the structure describing the coordinates from A3DTessBaseData +* It contains indexes of vertex coordinates, wire frames coordinates, normals and textures coordinates. +* +* +***********************************************************************************************************************/ + +#include "CreateTessellatedCubes.h" + + +//###################################################################################################################### +// Cube Tessellation structures completion +// filling A3DTessBaseData: containing the coordinates of the tessellation. +void fillCubeTessBaseData(A3DTessBaseData& sTessBaseData, A3DDouble cubeWidth, A3DDouble cubeHeight, A3DDouble cubeLength) +{ + A3D_INITIALIZE_DATA(A3DTessBaseData, sTessBaseData); + + sTessBaseData.m_bIsCalculated = false; + + // Point coordinates + sTessBaseData.m_uiCoordSize = 24; + sTessBaseData.m_pdCoords = (A3DDouble*) malloc((size_t) sTessBaseData.m_uiCoordSize * sizeof(A3DDouble)); + + A3DUns32 ui; + for (ui = 0; ui < sTessBaseData.m_uiCoordSize / 3; ++ui) + { + sTessBaseData.m_pdCoords[3 * ui] = stCubePoints[3 * ui] * cubeWidth; + sTessBaseData.m_pdCoords[3 * ui + 1] = stCubePoints[3 * ui + 1] * cubeHeight; + sTessBaseData.m_pdCoords[3 * ui + 2] = stCubePoints[3 * ui + 2] * cubeLength; + } +} + +void freeTessBaseData(A3DTessBaseData& sTessBaseData) +{ + free(sTessBaseData.m_pdCoords); +} + +//###################################################################################################################### +// Cube Tessellation structures completion +// filling A3DTess3DData:describing the coordinates from A3DTessBaseData +// indexes of vertex coordinates, wire frames coordinates, normals and textures coordinates. +void fillCubeTessData(A3DTess3DData& sTess3DData, A3DUns32* puiStyleIndex) +{ + A3D_INITIALIZE_DATA(A3DTess3DData, sTess3DData); + + A3DUns32 ui; + + // Normal coordinates + sTess3DData.m_uiNormalSize = 18; + sTess3DData.m_pdNormals = (A3DDouble*) malloc((size_t) sTess3DData.m_uiNormalSize * sizeof(A3DDouble)); + for (ui = 0; ui < sTess3DData.m_uiNormalSize; ++ui) + sTess3DData.m_pdNormals[ui] = stCubeNormals[ui]; + + if (puiStyleIndex != NULL) + { + // UV coordinates + sTess3DData.m_uiTextureCoordSize = 8; + sTess3DData.m_pdTextureCoords = + (A3DDouble*) malloc(sTess3DData.m_uiTextureCoordSize * A3DUns32(sizeof(A3DDouble))); + for (ui = 0; ui < sTess3DData.m_uiTextureCoordSize; ++ui) + { + sTess3DData.m_pdTextureCoords[ui] = stCubeUV[ui]; + } + } + + // Faces + sTess3DData.m_bHasFaces = true; // Geometrical face notion? + sTess3DData.m_uiFaceTessSize = 6; + sTess3DData.m_psFaceTessData = + (A3DTessFaceData*) malloc((size_t) sTess3DData.m_uiFaceTessSize * sizeof(A3DTessFaceData)); + for (ui = 0; ui < sTess3DData.m_uiFaceTessSize; ++ui) + A3D_INITIALIZE_DATA(A3DTessFaceData, (sTess3DData.m_psFaceTessData[ui])); + + // All the point, normal and texture indexes are stored in the A3DTess3D. + // The faces describes how to interpret these indices. + if (puiStyleIndex != NULL) + { + sTess3DData.m_uiTriangulatedIndexSize = 18 * 6; + sTess3DData.m_puiTriangulatedIndexes = (A3DUns32*) malloc(sTess3DData.m_uiTriangulatedIndexSize * A3DUns32(sizeof(A3DUns32))); + for (ui = 0; ui < sTess3DData.m_uiTriangulatedIndexSize; ++ui) + { + sTess3DData.m_puiTriangulatedIndexes[ui] = stTexturedCubeFacesNormalPTrianglesUV[ui]; + } + } + else + { + sTess3DData.m_uiTriangulatedIndexSize = 12 * 6; + + sTess3DData.m_puiTriangulatedIndexes = (A3DUns32*) malloc((size_t) sTess3DData.m_uiTriangulatedIndexSize * sizeof(A3DUns32)); + for (ui = 0; ui < sTess3DData.m_uiTriangulatedIndexSize; ++ui) + { + sTess3DData.m_puiTriangulatedIndexes[ui] = stCubeFacesNormalPTrianglesUV[ui]; + } + } + + // Like above the edge point indices of the faces are stored in the A3DTess3D + sTess3DData.m_uiWireIndexSize = 8 * 6; + sTess3DData.m_puiWireIndexes = (A3DUns32*) malloc((size_t) sTess3DData.m_uiWireIndexSize * sizeof(A3DUns32)); + for (ui = 0; ui < sTess3DData.m_uiWireIndexSize; ++ui) + sTess3DData.m_puiWireIndexes[ui] = stCubeFacesWireframe[ui]; + + A3DUns32 uj; + for (ui = 0; ui < sTess3DData.m_uiFaceTessSize; ++ui) + { + A3DTessFaceData& sFace = sTess3DData.m_psFaceTessData[ui]; + + // Type(s) of the entities of the face. This face contains only triangles with texture (with uv for each vertex). + if (puiStyleIndex != NULL) + { + sFace.m_usUsedEntitiesFlags = kA3DTessFaceDataTriangleTextured; + // indicates the texture of this face + if (*puiStyleIndex != A3D_DEFAULT_STYLE_INDEX) + { + sFace.m_uiStyleIndexesSize = 1; + sFace.m_puiStyleIndexes = (A3DUns32*) malloc(sFace.m_uiStyleIndexesSize * A3DUns32(sizeof(A3DUns32))); + sFace.m_puiStyleIndexes[0] = *puiStyleIndex; + + } + // number of uv indices for each vertex of the face + // (a multi-textured face or a multi-referenced part should involve more than one uv index) + sFace.m_uiTextureCoordIndexesSize = 1; + // the description of the triangles of the face begins at this position + // in the m_puiTriangulatedIndexes array filled above. + sFace.m_uiStartTriangulated = ui * 18; + } + else + { + sFace.m_usUsedEntitiesFlags = kA3DTessFaceDataTriangle; + sFace.m_uiTextureCoordIndexesSize = 0; + sFace.m_uiStartTriangulated = ui * 12; + } + + sFace.m_uiSizesTriangulatedSize = 1; // size of the next array + sFace.m_puiSizesTriangulated = (A3DUns32*) malloc(sFace.m_uiSizesTriangulatedSize * A3DUns32(sizeof(A3DUns32))); + sFace.m_puiSizesTriangulated[0] = 2; // number of triangles for this face + + // wireframe of the face + sFace.m_uiSizesWiresSize = 4; // size of the next array corresponds to the number of edges + sFace.m_puiSizesWires = (A3DUns32*) malloc((size_t) sFace.m_uiSizesWiresSize * sizeof(A3DUns32)); + for (uj = 0; uj < sFace.m_uiSizesWiresSize; ++uj) + sFace.m_puiSizesWires[uj] = 2; // two points for each edge + + // to indicate that the loop is closed, + // the number of vertices of the last edge has the flag kA3DTessFaceDataWireIsClosing + sFace.m_puiSizesWires[sFace.m_uiSizesWiresSize - 1] |= kA3DTessFaceDataWireIsClosing; + + // the description of the wireframe of the face begins at this position + // in the m_puiWireIndexes array filled above. + sFace.m_uiStartWire = ui * 8; + + } +} + +void freeTess3DData(A3DTess3DData& sTess3DData) +{ + free(sTess3DData.m_pdNormals); + free(sTess3DData.m_pdTextureCoords); + free(sTess3DData.m_puiTriangulatedIndexes); + free(sTess3DData.m_puiWireIndexes); + + A3DUns32 ui = sTess3DData.m_uiFaceTessSize; + for (ui = 0; ui < sTess3DData.m_uiFaceTessSize; ++ui) + { + if (sTess3DData.m_psFaceTessData[ui].m_puiStyleIndexes != NULL) // Texture is optionnal + free(sTess3DData.m_psFaceTessData[ui].m_puiStyleIndexes); + free(sTess3DData.m_psFaceTessData[ui].m_puiSizesTriangulated); + free(sTess3DData.m_psFaceTessData[ui].m_puiSizesWires); + } + free(sTess3DData.m_psFaceTessData); +} diff --git a/exchange/exchangesource/CreatePRCCubes/CreateTessellatedCubes.h b/exchange/exchangesource/CreatePRCCubes/CreateTessellatedCubes.h new file mode 100644 index 0000000..b244b8f --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/CreateTessellatedCubes.h @@ -0,0 +1,113 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreateTessellatedCubes.cpp +* This file is containing the data and function used to create PRC Tessellation. +* +* fillCubeTessBaseData is filling the structure A3DTessBaseData +* A3DTessBaseData is the structure containing the coordinates of the tessellation. +* +* fillCubeTessData is filling the structure A3DTess3DData +* A3DTess3DData is the structure describing the coordinates from A3DTessBaseData +* It contains indexes of vertex coordinates, wire frames coordinates, normals and textures coordinates. +* +* +***********************************************************************************************************************/ +#pragma once + +#include "CreatePRCCubesDef.h" + +//###################################################################################################################### +//Cube tessellation data + +static A3DDouble stCubePoints[24] = { + -1, -1, 1, + 1, -1, 1, + -1, 1, 1, + 1, 1, 1, + -1, 1, -1, + 1, 1, -1, + -1, -1, -1, + 1, -1, -1 +}; + +static A3DDouble stCubeNormals[18] = { + 1., 0., 0., + -1., 0., 0., + 0., 1., 0., + 0., -1., 0., + 0., 0., 1., + 0., 0., -1. +}; + +static A3DDouble stCubeUV[8] = { + 0.0, 0.0, + 1.0, 0.0, + 0.0, 1.0, + 1.0, 1.0 + // U V +}; + +#define ADD_FACE_COLOR + + +static A3DUns32 stCubeFacesNormalPTrianglesUV[72] = +{ + //72 buffer count +// N, P, N, P, N, P, N, P, N, P, N, P + 12, 0, 12, 3, 12, 6, 12, 6, 12, 3, 12, 9, // Face 0 + 6, 6, 6, 9, 6, 12, 6, 12, 6, 9, 6, 15, // Face 1 + 15, 12, 15, 15, 15, 18, 15, 18, 15, 15, 15, 21, // .... + 9, 18, 9, 21, 9, 0, 9, 0, 9, 21, 9, 3, + 0, 3, 0, 21, 0, 9, 0, 9, 0, 21, 0, 15, + 3, 18, 3, 0, 3, 12, 3, 12, 3, 0, 3, 6, // Face N +}; + +// N = normal index +// U = UV index +// P = point coordinates index +static A3DUns32 stTexturedCubeFacesNormalPTrianglesUV[108] = { + 12, 0, 0, 12, 2, 3, 12, 4, 6, 12, 4, 6, 12, 2, 3, 12, 6, 9, //Face0 + 6, 0, 6, 6, 2, 9, 6, 4, 12, 6, 4, 12, 6, 2, 9, 6, 6, 15, //Face1 + 15, 6, 12, 15, 4, 15, 15, 2, 18, 15, 2, 18, 15, 4, 15, 15, 0, 21, //.... + 9, 0, 18, 9, 2, 21, 9, 4, 0, 9, 4, 0, 9, 2, 21, 9, 6, 3, + 0, 0, 3, 0, 2, 21, 0, 4, 9, 0, 4, 9, 0, 2, 21, 0, 6, 15, + 3, 0, 18, 3, 2, 0, 3, 4, 12, 3, 4, 12, 3, 2, 0, 3, 6, 6 //FaceN + /* + N,U,P N,U,P N,U,P N,U,P N,U,P N,U,P Face 0 + \ first triangle / \ second triangle / + N,U,P N,U,P N,U,P N,U,P N,U,P N,U,P Face 1 + N,U,P N,U,P N,U,P N,U,P N,U,P N,U,P Face 2 + N,U,P N,U,P N,U,P N,U,P N,U,P N,U,P ... + N,U,P N,U,P N,U,P N,U,P N,U,P N,U,P Face N + */ +}; + +static A3DUns32 stCubeFacesWireframe[48] = { + 0, 3, 3, 9, 9, 6, 6, 0,/* Face 0 */ + 6, 9, 9, 15, 15, 12, 12, 6,/* Face 1 */ + 12, 15, 15, 21, 21, 18, 18, 12,/* .... */ + 18, 21, 21, 3, 3, 0, 0, 18, + 3, 21, 21, 15, 15, 9, 9, 3, + 18, 0, 0, 6, 6, 12, 12, 18 /* Face N */ + /* E1 E2 E3 E4 edges */ +}; + + +//###################################################################################################################### +void fillCubeTessBaseData(A3DTessBaseData& sTessBaseData, A3DDouble cubeWidth, A3DDouble cubeHeight, A3DDouble cubeLength); +void freeTessBaseData(A3DTessBaseData& sTessBaseData); + +//###################################################################################################################### +void fillCubeTessData(A3DTess3DData& sTess3DData, A3DUns32* puiStyleIndex = NULL); +void freeTess3DData(A3DTess3DData& sTess3DData); + diff --git a/exchange/exchangesource/CreatePRCCubes/Logo.jpg b/exchange/exchangesource/CreatePRCCubes/Logo.jpg new file mode 100644 index 0000000..2c48c42 Binary files /dev/null and b/exchange/exchangesource/CreatePRCCubes/Logo.jpg differ diff --git a/exchange/exchangesource/CreatePRCCubes/modules/CreateGraphics.cpp b/exchange/exchangesource/CreatePRCCubes/modules/CreateGraphics.cpp new file mode 100644 index 0000000..15854d4 --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/modules/CreateGraphics.cpp @@ -0,0 +1,144 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreateGraphics.cpp +* This file is containing the function allowing to create graphics. +* +* +***********************************************************************************************************************/ +#include "CreateGraphics.h" + +//###################################################################################################################### +// Color creation +A3DStatus createRGBColor(A3DUns32& uiIndexRgbColor, A3DDouble dRed, A3DDouble dGreen, A3DDouble dBlue) +{ + A3DStatus iRet = A3D_SUCCESS; + A3DGraphRgbColorData sData; + A3D_INITIALIZE_DATA(A3DGraphRgbColorData, sData); + sData.m_dRed = dRed; + sData.m_dGreen = dGreen; + sData.m_dBlue = dBlue; + iRet = A3DGlobalInsertGraphRgbColor(&sData, &uiIndexRgbColor); + + return iRet; +} + +//###################################################################################################################### +// Material creation: Creates a material, then inserts it into the global material table. +A3DStatus createMaterial(A3DUns32& uiMaterialGenericIndex, A3DDouble dRed, A3DDouble dGreen, A3DDouble dBlue) +{ + A3DStatus iRet = A3D_SUCCESS; + A3DUns32 uiAmbient, uiDiffuse, uiEmissive, uiSpecular; + + CHECK_RET(createRGBColor(uiAmbient, dRed, dGreen, dBlue)); + CHECK_RET(createRGBColor(uiDiffuse, dRed, dGreen, dBlue)); + CHECK_RET(createRGBColor(uiEmissive, dRed, dGreen, dBlue)); + CHECK_RET(createRGBColor(uiSpecular, dRed, dGreen, dBlue)); + + A3DGraphMaterialData sMaterialData; + A3D_INITIALIZE_DATA(A3DGraphMaterialData, sMaterialData); + sMaterialData.m_uiAmbient = uiAmbient; + sMaterialData.m_uiDiffuse = uiDiffuse; + sMaterialData.m_uiEmissive = uiEmissive; + sMaterialData.m_uiSpecular = uiSpecular; + sMaterialData.m_dAmbientAlpha = 1.0; + sMaterialData.m_dDiffuseAlpha = 1.0; + sMaterialData.m_dEmissiveAlpha = 1.0; + sMaterialData.m_dSpecularAlpha = 1.0; + sMaterialData.m_dShininess = 0.0; + CHECK_RET(A3DGlobalInsertGraphMaterial(&sMaterialData, &uiMaterialGenericIndex)); + + return iRet; +} + +//###################################################################################################################### +A3DStatus setGraphicsColor(A3DRootBaseWithGraphicsData* pOutRootBaseWithGraphics, A3DDouble dRed, A3DDouble dGreen, A3DDouble dBlue, A3DDouble dAlpha) +{ + A3DStatus iRet = A3D_SUCCESS; + + //Create a style color + A3DUns32 uiColorIndex = 0; + CHECK_RET(createRGBColor(uiColorIndex, dRed, dGreen, dBlue)); + + A3DUns32 uiStyleIndex = 0; + A3DGraphStyleData sStyleData; + A3D_INITIALIZE_DATA(A3DGraphStyleData, sStyleData); + sStyleData.m_bMaterial = false; + sStyleData.m_bVPicture = false; + sStyleData.m_dWidth = 0.1; // default + sStyleData.m_bIsTransparencyDefined = true; + sStyleData.m_ucTransparency = (A3DUns8) (dAlpha * 255.0); + sStyleData.m_bSpecialCulling = false; + sStyleData.m_bBackCulling = false; + sStyleData.m_uiRgbColorIndex = uiColorIndex; + CHECK_RET(A3DGlobalInsertGraphStyle(&sStyleData, &uiStyleIndex)); + + A3DGraphicsData sGraphicsData; + A3D_INITIALIZE_DATA(A3DGraphicsData, sGraphicsData); + + sGraphicsData.m_uiStyleIndex = uiStyleIndex; + sGraphicsData.m_usBehaviour = kA3DGraphicsShow; + sGraphicsData.m_usBehaviour |= kA3DGraphicsSonHeritColor; + + CHECK_RET(A3DGraphicsCreate(&sGraphicsData, &(pOutRootBaseWithGraphics->m_pGraphics))); + + return iRet; +} + +A3DStatus setEntityColor(A3DEntity* inEntity, A3DDouble dRed, A3DDouble dGreen, A3DDouble dBlue, A3DDouble dAlpha) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DRootBaseWithGraphicsData sBaseWithGraphicsData; + A3D_INITIALIZE_DATA(A3DRootBaseWithGraphicsData, sBaseWithGraphicsData); + CHECK_RET(A3DRootBaseWithGraphicsGet(inEntity, &sBaseWithGraphicsData)); + + CHECK_RET(setGraphicsColor(&sBaseWithGraphicsData, dRed, dGreen, dBlue, dAlpha)); + + CHECK_RET(A3DRootBaseWithGraphicsSet(inEntity, &sBaseWithGraphicsData)); + CHECK_RET(A3DGraphicsDelete(sBaseWithGraphicsData.m_pGraphics)); + + return iRet; +} + +//###################################################################################################################### +A3DStatus setGraphicsHidden(A3DRootBaseWithGraphicsData* pOutRootBaseWithGraphics) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DGraphicsData sGraphicsData; + A3D_INITIALIZE_DATA(A3DGraphicsData, sGraphicsData); + CHECK_RET(A3DGraphicsGet(pOutRootBaseWithGraphics->m_pGraphics, &sGraphicsData)); + + sGraphicsData.m_usBehaviour &= ~kA3DGraphicsShow; + sGraphicsData.m_usBehaviour |= kA3DGraphicsSonHeritShow; + + CHECK_RET(A3DGraphicsCreate(&sGraphicsData, &(pOutRootBaseWithGraphics->m_pGraphics))); + + return iRet; +} + +A3DStatus setEntityHidden(A3DEntity* inEntity) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DRootBaseWithGraphicsData sBaseWithGraphicsData; + A3D_INITIALIZE_DATA(A3DRootBaseWithGraphicsData, sBaseWithGraphicsData); + CHECK_RET(A3DRootBaseWithGraphicsGet(inEntity, &sBaseWithGraphicsData)); + + CHECK_RET(setGraphicsHidden(&sBaseWithGraphicsData)); + + CHECK_RET(A3DRootBaseWithGraphicsSet(inEntity, &sBaseWithGraphicsData)); + + return iRet; +} + diff --git a/exchange/exchangesource/CreatePRCCubes/modules/CreateGraphics.h b/exchange/exchangesource/CreatePRCCubes/modules/CreateGraphics.h new file mode 100644 index 0000000..5905106 --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/modules/CreateGraphics.h @@ -0,0 +1,45 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreateGraphics.cpp +* This file is containing the function allowing to create graphics. +* +* +***********************************************************************************************************************/ +#pragma once + +#include "../CreatePRCCubesDef.h" + + +//###################################################################################################################### +#define WHITE 1.,1.,1. +#define DARK_GREY 0.2,0.2,0.2 + +#define RED 1.,0.,0. +#define GREEN 0.,1.,0. +#define BLUE 0.,0.,1. + +#define YELLOW 1.,1.,0. +#define PURPLE 1.,0.,1. +#define TURQUOISE 0.,1.,1. + +//###################################################################################################################### +A3DStatus createRGBColor(A3DUns32& uiIndexRgbColor, A3DDouble dRed, A3DDouble dGreen, A3DDouble dBlue); +A3DStatus createMaterial(A3DUns32& uiMaterialGenericIndex, A3DDouble dRed, A3DDouble dGreen, A3DDouble dBlue); + +A3DStatus setGraphicsColor(A3DRootBaseWithGraphicsData* pOutRootBaseWithGraphics, A3DDouble dRed, A3DDouble dGreen, A3DDouble dBlue, A3DDouble dAlpha); +A3DStatus setEntityColor(A3DEntity* inEntity, A3DDouble dRed, A3DDouble dGreen, A3DDouble dBlue, A3DDouble dAlpha); + +A3DStatus setGraphicsHidden(A3DRootBaseWithGraphicsData* pOutRootBaseWithGraphics); +A3DStatus setEntityHidden(A3DEntity* inEntity); + + diff --git a/exchange/exchangesource/CreatePRCCubes/modules/CreateLinkedItem.cpp b/exchange/exchangesource/CreatePRCCubes/modules/CreateLinkedItem.cpp new file mode 100644 index 0000000..fe1e3eb --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/modules/CreateLinkedItem.cpp @@ -0,0 +1,117 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreateLinkedItem.cpp +* This file is containing the function allowing to create linked items. +* +* +***********************************************************************************************************************/ +#include "CreateMarkups.h" + +//###################################################################################################################### +// +// Linked Items +// +//###################################################################################################################### +// Create a a link mparkup / entity +static A3DStatus stCreateLinkedItem(A3DEntity* pEntity, A3DAsmProductOccurrence *pPOTarget, + A3DMiscMarkupLinkedItem ** ppMLI) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DMiscMarkupLinkedItemData sMLIData; + A3D_INITIALIZE_DATA(A3DMiscMarkupLinkedItemData, sMLIData); + + sMLIData.m_pTargetProductOccurrence = pPOTarget; + sMLIData.m_pReference = pEntity; + CHECK_RET(A3DMiscMarkupLinkedItemCreate(&sMLIData, ppMLI)); + + return iRet; +} + +//###################################################################################################################### + +A3DStatus createMarkupLinkedItemOnProduct(A3DAsmProductOccurrence* pPO, A3DAsmProductOccurrence *pPOTarget, + A3DMiscMarkupLinkedItem ** ppMLI) +{ + A3DStatus iRet = A3D_SUCCESS; + + // pPo: setting a non-null reference + // m_pTargetProductOccurrence: setting the target ProductOccurrence to NULL if the reference is at the same level as the PO, + // or to the level above if the PO tree has several levels + iRet = (stCreateLinkedItem(pPO, pPOTarget, ppMLI)); + + return iRet; +} + +A3DStatus createMarkupLinkedItemOnEntity(A3DEntity* pEntity, + A3DAsmProductOccurrence * pPOTarget, + A3DMiscMarkupLinkedItem ** ppMLI) +{ + A3DStatus iRet = A3D_SUCCESS; + + CHECK_RET(stCreateLinkedItem(pEntity, pPOTarget, ppMLI)); + + return iRet; +} + +A3DStatus createMarkupLinkedItemOnTopo(A3DEntity* pEntity, A3DEEntityType eTopoItemType, + A3DUns32 uiAdditionalIndexesSize, + A3DUns32* puiAdditionalIndexes, + A3DAsmProductOccurrence* pPOTarget, + A3DMiscMarkupLinkedItem ** ppMLI) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DMiscReferenceOnTopologyData sReferenceOnTopologyData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnTopologyData, sReferenceOnTopologyData); + + sReferenceOnTopologyData.m_eTopoItemType = eTopoItemType; // kA3DTypeTopoFace; + sReferenceOnTopologyData.m_pBrepData = pEntity; + sReferenceOnTopologyData.m_uiSize = uiAdditionalIndexesSize; + sReferenceOnTopologyData.m_puiAdditionalIndexes = puiAdditionalIndexes; + + A3DMiscReferenceOnTopology* pReferenceOnTopoItem; + CHECK_RET(A3DMiscReferenceOnTopologyCreate(&sReferenceOnTopologyData, &pReferenceOnTopoItem)); + + // create MarkupLinkedItem + CHECK_RET(stCreateLinkedItem(pReferenceOnTopoItem, pPOTarget, ppMLI)); + + return iRet; +} + +A3DStatus createMarkupLinkedItemOnTess(A3DEntity* pEntity, A3DEEntityType eTessItemType, + A3DUns32 uiAdditionalIndexesSize, + A3DUns32* puiAdditionalIndexes, + A3DAsmProductOccurrence* pPOTarget, + A3DMiscMarkupLinkedItem ** ppMLI) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DMiscReferenceOnTessData sReferenceOnTessData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnTessData, sReferenceOnTessData); + + sReferenceOnTessData.m_eTopoItemType = eTessItemType; // kA3DTypeTessFace / kA3DTypeTessEdge / kA3DTypeTessVertex; + sReferenceOnTessData.m_pPolyBrepModel = pEntity; + sReferenceOnTessData.m_pTargetProductOccurrence = pPOTarget; + sReferenceOnTessData.m_uiSize = uiAdditionalIndexesSize; + sReferenceOnTessData.m_puiAdditionalIndexes = puiAdditionalIndexes; + + A3DMiscReferenceOnTess* pReferenceOnTessItem; + CHECK_RET(A3DMiscReferenceOnTessCreate(&sReferenceOnTessData, &pReferenceOnTessItem)); + + *ppMLI = (A3DMiscMarkupLinkedItem*)pReferenceOnTessItem; + + return iRet; +} + + diff --git a/exchange/exchangesource/CreatePRCCubes/modules/CreateLinkedItem.h b/exchange/exchangesource/CreatePRCCubes/modules/CreateLinkedItem.h new file mode 100644 index 0000000..5f0ac4c --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/modules/CreateLinkedItem.h @@ -0,0 +1,40 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreateLinkedItem.cpp +* This file is containing the function allowing to create linked items. +* +* +***********************************************************************************************************************/ +#pragma once + +#include "../CreatePRCCubesDef.h" + +#include "CreateGraphics.h" + +//###################################################################################################################### +A3DStatus createMarkupLinkedItemOnProduct(A3DAsmProductOccurrence* pPO, A3DAsmProductOccurrence *pPOTarget, + A3DMiscMarkupLinkedItem ** ppMLI); +A3DStatus createMarkupLinkedItemOnEntity(A3DEntity* pEntity, A3DAsmProductOccurrence *pPOTarget, + A3DMiscMarkupLinkedItem ** ppMLI); +A3DStatus createMarkupLinkedItemOnTopo(A3DEntity* pEntity, A3DEEntityType eTopoItemType, + A3DUns32 uiAdditionalIndexesSize, + A3DUns32* puiAdditionalIndexes, + A3DAsmProductOccurrence* pPOTarget, + A3DMiscMarkupLinkedItem ** ppMLI); +A3DStatus createMarkupLinkedItemOnTess(A3DEntity* pEntity, A3DEEntityType eTopoItemType, + A3DUns32 uiAdditionalIndexesSize, + A3DUns32* puiAdditionalIndexes, + A3DAsmProductOccurrence* pPOTarget, + A3DMiscMarkupLinkedItem ** ppMLI); + + diff --git a/exchange/exchangesource/CreatePRCCubes/modules/CreateMarkups.cpp b/exchange/exchangesource/CreatePRCCubes/modules/CreateMarkups.cpp new file mode 100644 index 0000000..59503d4 --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/modules/CreateMarkups.cpp @@ -0,0 +1,444 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreateMartkups.cpp +* This file is containing the function allowing to create markups. +* +* Markups creation exemple +* Create tessellated markups with linked items. +* Different style of markups can be created (normal or face to screen). +* Different links to the PRC entities can be created as well. +* +* These exemples are using the tessellation wrapper: HXWMarkupTessellation.cpp +* +* +***********************************************************************************************************************/ +#include "CreateMarkups.h" + +#include "../tessellation_wrapper/HXWMarkupTessellation.h" + +#include + +//###################################################################################################################### +// +// Tessellation Helper +// +//###################################################################################################################### +// Create a leader and an arrow +static void stCreateLeaderTess(HXWMarkupTessellation* sMarkupLeaderTessellation, A3DVector3dData* pLeaderBegin, A3DVector3dData* pLeaderEnd) +{ + // Leader + A3DDouble* pdLeaderPolylineData = (A3DDouble*) malloc(9 * sizeof(A3DDouble)); + pdLeaderPolylineData[0] = pLeaderBegin->m_dX; + pdLeaderPolylineData[1] = pLeaderBegin->m_dY; + pdLeaderPolylineData[2] = pLeaderBegin->m_dZ; + + pdLeaderPolylineData[3] = pdLeaderPolylineData[0]; + pdLeaderPolylineData[4] = pdLeaderPolylineData[1]; + pdLeaderPolylineData[5] = pLeaderEnd->m_dZ; + + pdLeaderPolylineData[6] = pLeaderEnd->m_dX; + pdLeaderPolylineData[7] = pLeaderEnd->m_dY; + pdLeaderPolylineData[8] = pLeaderEnd->m_dZ; + + sMarkupLeaderTessellation->set_color(YELLOW); + sMarkupLeaderTessellation->add_polyline(pdLeaderPolylineData, 3); + free(pdLeaderPolylineData); + + // Arrow + A3DDouble* pdTriangle = (A3DDouble*) malloc(9 * sizeof(A3DDouble)); + pdTriangle[0] = pLeaderBegin->m_dX; + pdTriangle[1] = pLeaderBegin->m_dY; + pdTriangle[2] = pLeaderBegin->m_dZ; + + pdTriangle[3] = pdTriangle[0]; + pdTriangle[4] = pdTriangle[1] - 3; + pdTriangle[5] = pdTriangle[2] + 6; + + pdTriangle[6] = pdTriangle[0]; + pdTriangle[7] = pdTriangle[1] + 3; + pdTriangle[8] = pdTriangle[2] + 6; + + sMarkupLeaderTessellation->set_color(YELLOW); + sMarkupLeaderTessellation->add_triangle(pdTriangle); + free(pdTriangle); +} + +//###################################################################################################################### +// Create a Frame and Background +static void stCreateFrameTess(HXWMarkupTessellation* pMarkupTessellation, + A3DVector3dData* pBottomLeft, // this feel the most natural as text will begin from that point + A3DDouble width, A3DDouble height) +{ + // Frame + A3DDouble* pdMarkupFrameData = (A3DDouble*) malloc(16 * sizeof(A3DDouble)); + pdMarkupFrameData[0] = pBottomLeft->m_dX; // lower left corner + pdMarkupFrameData[1] = pBottomLeft->m_dY; + pdMarkupFrameData[2] = pBottomLeft->m_dZ; + + pdMarkupFrameData[3] = pdMarkupFrameData[0] + width; // lower right corner + pdMarkupFrameData[4] = pdMarkupFrameData[1]; + pdMarkupFrameData[5] = pdMarkupFrameData[2]; + + pdMarkupFrameData[6] = pdMarkupFrameData[0] + width; // upper right corner + pdMarkupFrameData[7] = pdMarkupFrameData[1] + height; + pdMarkupFrameData[8] = pdMarkupFrameData[2]; + + pdMarkupFrameData[9] = pdMarkupFrameData[0]; // upper left corner + pdMarkupFrameData[10] = pdMarkupFrameData[1] + height; + pdMarkupFrameData[11] = pdMarkupFrameData[2]; + + pdMarkupFrameData[12] = pdMarkupFrameData[0]; // lower left corner + pdMarkupFrameData[13] = pdMarkupFrameData[1]; + pdMarkupFrameData[14] = pdMarkupFrameData[2]; + + pMarkupTessellation->set_color(RED); + pMarkupTessellation->add_polyline(pdMarkupFrameData, 5); + free(pdMarkupFrameData); + + // Background + A3DDouble* pdMarkupBackGroundData = (A3DDouble*) malloc(12 * sizeof(A3DDouble)); + pdMarkupBackGroundData[0] = pBottomLeft->m_dX; // lower left corner + pdMarkupBackGroundData[1] = pBottomLeft->m_dY; + pdMarkupBackGroundData[2] = pBottomLeft->m_dZ - 0.01; + + pdMarkupBackGroundData[3] = pdMarkupBackGroundData[0] + width; // lower right corner + pdMarkupBackGroundData[4] = pdMarkupBackGroundData[1]; + pdMarkupBackGroundData[5] = pdMarkupBackGroundData[2] - 0.01;; + + pdMarkupBackGroundData[6] = pdMarkupBackGroundData[0] + width; // upper right corner + pdMarkupBackGroundData[7] = pdMarkupBackGroundData[1] + height; + pdMarkupBackGroundData[8] = pdMarkupBackGroundData[2] - 0.01;; + + pdMarkupBackGroundData[9] = pdMarkupBackGroundData[0]; // upper left corner + pdMarkupBackGroundData[10] = pdMarkupBackGroundData[1] + height; + pdMarkupBackGroundData[11] = pdMarkupBackGroundData[2] - 0.01;; + + pMarkupTessellation->set_color(WHITE); + pMarkupTessellation->add_polygons(pdMarkupBackGroundData, 4); + free(pdMarkupBackGroundData); + +} + +//###################################################################################################################### +// Create a Text +static void stCreateText(HXWMarkupTessellation* pMarkupTessellation, + const A3DUTF8Char* pcText, + A3DVector3dData* pBottomLeft, A3DDouble width, A3DDouble height) +{ + // Text + HXWVector3d position(pBottomLeft->m_dX + 5, + pBottomLeft->m_dY + 5, + pBottomLeft->m_dZ); + HXWVector3d normal(0., 0., 1.); + HXWVector3d x_direction(1., 0., 0.); + pMarkupTessellation->begin_matrix(position.m_data, normal.m_data, x_direction.m_data); + pMarkupTessellation->set_textfont("Courier New", 10, kA3DFontBold); + pMarkupTessellation->set_color(BLUE); + pMarkupTessellation->add_text(pcText, width, height); + pMarkupTessellation->end_matrix(); + /* to test a second text + position.m_data.m_dX += width + 5; + pMarkupTessellation->begin_matrix(position.m_data, normal.m_data, x_direction.m_data); + pMarkupTessellation->set_textfont("Myriad CAD", 10, kA3DFontBold); + pMarkupTessellation->set_color(BLUE); + pMarkupTessellation->add_text("Publish"); + pMarkupTessellation->end_matrix(); + */ + +} + + +//###################################################################################################################### +// +// Leader, frame and text +// +//###################################################################################################################### +static const double sdFrameWidth = 110; +static const double sdFrameHeight = 25; + +static const double sdTextWidth = 100; +static const double sdTextHeight = 10; + + +// Create a Tessellation +static A3DStatus stCreateFrameAndText(A3DTessMarkup** ppTessMarkup, + const A3DUTF8Char* pcText, + A3DVector3dData* pFramePos) +{ + A3DStatus iRet = A3D_SUCCESS; + + // label + HXWMarkupTessellation sMarkupTessellation; + + stCreateFrameTess(&sMarkupTessellation, pFramePos, sdFrameWidth, sdFrameHeight); + stCreateText(&sMarkupTessellation, pcText, pFramePos, sdTextWidth, sdTextHeight); + + *ppTessMarkup = sMarkupTessellation.GetEntity(); + + return iRet; +} + +// Create a Face to screen Tessellation +static A3DStatus stCreateFrameAndTextFaceToScreen(A3DTessMarkup** ppTessMarkup, + const A3DUTF8Char* pcText, + A3DVector3dData* pFrame3DPos, + FlatToScreenMode inFlatToScreenMode) +{ + + A3DStatus iRet = A3D_SUCCESS; + + HXWMarkupTessellation sMarkupTessellation; + // FaceMode + A3DDouble pFaceModeOrigin[3]; + pFaceModeOrigin[0] = pFrame3DPos->m_dX; + pFaceModeOrigin[1] = pFrame3DPos->m_dY; + pFaceModeOrigin[2] = pFrame3DPos->m_dZ; + + A3DVector3dData sOrigin; + A3D_INITIALIZE_DATA(A3DVector3dData, sOrigin); + sOrigin.m_dX = 0; + sOrigin.m_dY = 0; + sOrigin.m_dZ = 0; + + switch (inFlatToScreenMode) + { + case FlatToScreen: + sMarkupTessellation.BeginFaceView(pFaceModeOrigin); + break; + case FlatToScreenAlwaysOnTop: + sMarkupTessellation.BeginFaceViewAlwaysOnTop(pFaceModeOrigin); + break; + case FlatToScreenNonZoomable: + sMarkupTessellation.BeginFrameDraw(pFaceModeOrigin); + break; + } + + stCreateFrameTess(&sMarkupTessellation, &sOrigin, sdFrameWidth, sdFrameHeight); + stCreateText(&sMarkupTessellation, pcText, &sOrigin, sdTextWidth, sdTextHeight); + + switch (inFlatToScreenMode) + { + case FlatToScreen: + case FlatToScreenAlwaysOnTop: + sMarkupTessellation.EndFaceView(); + break; + case FlatToScreenNonZoomable: + sMarkupTessellation.EndFrameDraw(); + break; + } + + *ppTessMarkup = sMarkupTessellation.GetEntity(); + + return iRet; +} + +//###################################################################################################################### +// Create a Leader Tessellation +static A3DStatus stCreateLeader(A3DMkpLeader** ppMkpLeader, + A3DVector3dData* pBeginLeaderPos, + A3DVector3dData* pEndLeaderPos) +{ + A3DStatus iRet = A3D_SUCCESS; + + // leader + HXWMarkupTessellation sMarkupLeaderTessellation; + stCreateLeaderTess(&sMarkupLeaderTessellation, pBeginLeaderPos, pEndLeaderPos); + + A3DMkpLeaderData sMkpLeaderData; + A3D_INITIALIZE_DATA(A3DMkpLeaderData, sMkpLeaderData); + A3DTessMarkup* pLeaderTessMarkup = sMarkupLeaderTessellation.GetEntity(); + sMkpLeaderData.m_pTessellation = pLeaderTessMarkup; + CHECK_RET(A3DMkpLeaderCreate(&sMkpLeaderData, ppMkpLeader)); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stCreateMkpMarkup(A3DMkpMarkup** ppMarkup, + A3DTessMarkup* pTessMarkup, + A3DUns32 uiMkpLeaderSize, + A3DMkpLeader** ppMkpLeader, + A3DUns32 uiMarkupLinkedItemSize, + A3DMiscMarkupLinkedItem** ppMarkupLinkedItem) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DMkpMarkupData sMarkupData; + A3D_INITIALIZE_DATA(A3DMkpMarkupData, sMarkupData); + sMarkupData.m_eType = kA3DMarkupTypeText; + sMarkupData.m_eSubType = kA3DMarkupSubTypeUnknown; + + sMarkupData.m_uiLeadersSize = uiMkpLeaderSize; + sMarkupData.m_ppLeaders = ppMkpLeader; + + sMarkupData.m_uiLinkedItemsSize = uiMarkupLinkedItemSize; + sMarkupData.m_ppLinkedItems = ppMarkupLinkedItem; + + sMarkupData.m_pTessellation = pTessMarkup; + + CHECK_RET(A3DMkpMarkupCreate(&sMarkupData, ppMarkup)); + + return iRet; +} + + +//###################################################################################################################### +// +// Markups creation +// +//###################################################################################################################### +// Tesselated Markup creation + + +//###################################################################################################################### +// Tesselated Markup creation +A3DStatus createMarkup(A3DMkpAnnotationItem** ppOutAnnotItem, + const A3DUTF8Char* pcText, + A3DUns32 uiLinkedEntitySize, + A3DEntity** ppLinkedEntity, + A3DAsmProductOccurrence** ppPOTarget, + A3DVector3dData* pFramePos, + A3DVector3dData* pLeaderPos) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DMkpLeader* pMkpLeader = 0; + A3DUns32 uiMkpLeaderSize = 0; + if (pLeaderPos) + { + CHECK_RET(stCreateLeader(&pMkpLeader, pLeaderPos, pFramePos)); + uiMkpLeaderSize = 1; + } + + A3DTessMarkup* pTessMarkup = 0; + CHECK_RET(stCreateFrameAndText(&pTessMarkup, pcText, pFramePos)); + + // ----------------------------------------------------------- + // creation of linked item + std::vector vLinkedItems; + for (A3DUns32 i = 0; i < uiLinkedEntitySize; ++i) + { + A3DMiscMarkupLinkedItem* pMarkupLinkedItem = 0; + CHECK_RET(createMarkupLinkedItemOnEntity(ppLinkedEntity[i], ppPOTarget[i], &pMarkupLinkedItem)); + vLinkedItems.push_back(pMarkupLinkedItem); + } + + // ----------------------------------------------------------- + // create a Markup from the MarkupTessData + A3DMkpMarkup* pMarkup = 0; + CHECK_RET(stCreateMkpMarkup(&pMarkup, pTessMarkup, uiMkpLeaderSize, &pMkpLeader, (A3DUns32)vLinkedItems.size(), &(vLinkedItems[0]))); + vLinkedItems.clear(); + + // ----------------------------------------------------------- + // Annotation item creation + A3DMkpAnnotationItemData sAnnotItemData; + A3D_INITIALIZE_DATA(A3DMkpAnnotationItemData, sAnnotItemData); + sAnnotItemData.m_pMarkup = pMarkup; + CHECK_RET(A3DMkpAnnotationItemCreate(&sAnnotItemData, ppOutAnnotItem)); + + return iRet; +} + +//###################################################################################################################### +// Tesselated Markup creation +// Only the linked item creation process will change from the normal sample markup. +A3DStatus createMarkupOnFace(A3DMkpAnnotationItem** ppOutAnnotItem, + const A3DUTF8Char* pcText, + A3DUns32 uiLinkedEntitySize, + A3DEntity** ppLinkedEntity, + A3DAsmProductOccurrence** ppPOTarget, + A3DUns32* puiFaceIndexes, + A3DVector3dData* pFramePos, + A3DVector3dData* pLeaderPos) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DMkpLeader* pMkpLeader = 0; + A3DUns32 uiMkpLeaderSize = 0; + if (pLeaderPos) + { + CHECK_RET(stCreateLeader(&pMkpLeader, pLeaderPos, pFramePos)); + uiMkpLeaderSize = 1; + } + + + A3DTessMarkup* pTessMarkup = 0; + CHECK_RET(stCreateFrameAndText(&pTessMarkup, pcText, pFramePos)); + + // ----------------------------------------------------------- + // creation of linked item on a face + std::vector vLinkedItems; + for (A3DUns32 i = 0; i < uiLinkedEntitySize; ++i) + { + A3DMiscMarkupLinkedItem* pMarkupLinkedItem = 0; + CHECK_RET(createMarkupLinkedItemOnTess(ppLinkedEntity[i], kA3DTypeTessFace, 1, &puiFaceIndexes[i], ppPOTarget[i], &pMarkupLinkedItem)); + vLinkedItems.push_back(pMarkupLinkedItem); + } + + // ----------------------------------------------------------- + // create a Markup from the MarkupTessData + A3DMkpMarkup* pMarkup = 0; + CHECK_RET(stCreateMkpMarkup(&pMarkup, pTessMarkup, uiMkpLeaderSize, &pMkpLeader, (A3DUns32)vLinkedItems.size(), &(vLinkedItems[0]))); + vLinkedItems.clear(); + + // ----------------------------------------------------------- + // Annotation item creation + A3DMkpAnnotationItemData sAnnotItemData; + A3D_INITIALIZE_DATA(A3DMkpAnnotationItemData, sAnnotItemData); + sAnnotItemData.m_pMarkup = pMarkup; + CHECK_RET(A3DMkpAnnotationItemCreate(&sAnnotItemData, ppOutAnnotItem)); + + return iRet; +} + +//###################################################################################################################### +// FaceMode Markup creation +A3DStatus createMarkupFaceToScreen(A3DMkpAnnotationItem** ppOutAnnotItem, + const A3DUTF8Char* pcText, + A3DUns32 uiLinkedEntitySize, + A3DEntity** ppLinkedEntity, + A3DAsmProductOccurrence** ppPOTarget, + A3DVector3dData* pFramePos, + FlatToScreenMode inFlatToScreenMode) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DTessMarkup* pTessMarkup = 0; + CHECK_RET(stCreateFrameAndTextFaceToScreen(&pTessMarkup, pcText, pFramePos, inFlatToScreenMode)); + + // ----------------------------------------------------------- + // creation of linked item + // creation of linked item + std::vector vLinkedItems; + for (A3DUns32 i = 0; i < uiLinkedEntitySize; ++i) + { + A3DMiscMarkupLinkedItem* pMarkupLinkedItem = 0; + CHECK_RET(createMarkupLinkedItemOnEntity(ppLinkedEntity[i], ppPOTarget[i], &pMarkupLinkedItem)); + vLinkedItems.push_back(pMarkupLinkedItem); + } + + // ----------------------------------------------------------- + // create a Markup from the MarkupTessData + A3DMkpMarkup* pMarkup = 0; + CHECK_RET(stCreateMkpMarkup(&pMarkup, pTessMarkup, 0, 0, (A3DUns32)vLinkedItems.size(), &(vLinkedItems[0]))); + vLinkedItems.clear(); + + // ----------------------------------------------------------- + // Annotation item creation + A3DMkpAnnotationItemData sAnnotItemData; + A3D_INITIALIZE_DATA(A3DMkpAnnotationItemData, sAnnotItemData); + sAnnotItemData.m_pMarkup = pMarkup; + CHECK_RET(A3DMkpAnnotationItemCreate(&sAnnotItemData, ppOutAnnotItem)); + + return iRet; +} diff --git a/exchange/exchangesource/CreatePRCCubes/modules/CreateMarkups.h b/exchange/exchangesource/CreatePRCCubes/modules/CreateMarkups.h new file mode 100644 index 0000000..53daa44 --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/modules/CreateMarkups.h @@ -0,0 +1,69 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreateMartkups.cpp +* This file is containing the function allowing to create markups. +* +* Markups creation exemple +* Create tessellated markups with linked items. +* Different style of markups can be created (normal or face to screen). +* Different links to the PRC entities can be created as well. +* +* These exemples are using the tessellation wrapper: HXWMarkupTessellation.cpp +* +* +***********************************************************************************************************************/ +#pragma once + +#include "../CreatePRCCubesDef.h" + +#include "CreateLinkedItem.h" +#include "CreateGraphics.h" + +//###################################################################################################################### + +enum FlatToScreenMode +{ + FlatToScreen, + FlatToScreenAlwaysOnTop, + FlatToScreenNonZoomable +}; + + +//###################################################################################################################### +// Tesselated Markup creation with Publish + +A3DStatus createMarkup(A3DMkpAnnotationItem** ppOutAnnotItem, + const A3DUTF8Char* pcText, + A3DUns32 uiLinkedEntitySize, + A3DEntity** ppLinkedEntity, + A3DAsmProductOccurrence** ppPOTarget, + A3DVector3dData* pFramePos, + A3DVector3dData* pLeaderPos = 0); + +A3DStatus createMarkupOnFace(A3DMkpAnnotationItem** ppOutAnnotItem, + const A3DUTF8Char* pcText, + A3DUns32 uiLinkedEntitySize, + A3DEntity** ppLinkedEntity, + A3DAsmProductOccurrence** ppPOTarget, + A3DUns32* puiFaceIndexes, + A3DVector3dData* pFramePos, + A3DVector3dData* pLeaderPos = 0); + +A3DStatus createMarkupFaceToScreen(A3DMkpAnnotationItem** ppOutAnnotItem, + const A3DUTF8Char* pcText, + A3DUns32 uiLinkedEntitySize, + A3DEntity** ppLinkedEntity, + A3DAsmProductOccurrence** ppPOTarget, + A3DVector3dData* pFramePos, + FlatToScreenMode inFlatToScreenMode = FlatToScreen); + diff --git a/exchange/exchangesource/CreatePRCCubes/modules/CreateTextures.cpp b/exchange/exchangesource/CreatePRCCubes/modules/CreateTextures.cpp new file mode 100644 index 0000000..d98d23d --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/modules/CreateTextures.cpp @@ -0,0 +1,161 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreateTextures.cpp +* This file is containing the function allowing to create Textures. +* +* Texture creation exemple +* Create the style corresponding to texture. +* +* +***********************************************************************************************************************/ +#include "CreateTextures.h" + +#ifdef WIN32 +# include +#else +# include /* stat */ +# include +# include +#endif + +//###################################################################################################################### +// Picture creation +static A3DStatus stFillBinaryDataWithFile(const A3DUTF8Char* pcPictureFilePath, A3DUns8*& pcBinaryData, A3DUns32& iFileSize) +{ + A3DStatus iRet = A3D_SUCCESS; + FILE* psFile = fopen(pcPictureFilePath, "rb"); + if(psFile == NULL) + return A3D_ERROR; + +#ifdef WIN32 + struct _stat ficstat; + iRet = (A3DStatus) _stat(pcPictureFilePath, &ficstat); +#else + struct stat ficstat; +# if defined(Apple) && defined(_UNICODE) + USES_CONVERSION; + iRet = (stat(W2A(pcPictureFilePath), &ficstat) == 0 ? A3D_SUCCESS : A3D_ERROR); +# else + iRet = (stat(pcPictureFilePath, &ficstat) == 0 ? A3D_SUCCESS : A3D_ERROR); +# endif +#endif + if (iRet != A3D_SUCCESS || ficstat.st_size == 0) + { + fclose(psFile); + return A3D_ERROR; + } + + iFileSize = ficstat.st_size; + pcBinaryData = (A3DUns8*)malloc(iFileSize * A3DUns32(sizeof(A3DUns8))); + fread(pcBinaryData, sizeof(unsigned char), size_t(iFileSize), psFile); + fclose(psFile); + return A3D_SUCCESS; +} + +//###################################################################################################################### +static A3DStatus stCreatePicture(const A3DUTF8Char* pcPictureFilePath, A3DEPictureDataFormat eFormat, + A3DUns32 uiPixelHeight, A3DUns32 uiPixelWidth, A3DUns32& uiPictureIndex) +{ + A3DStatus iRet = A3D_SUCCESS; + + // For supported PRC image type, the sizes should be 0 as they are stored in the data + A3DGraphPictureData sPictureData; + A3D_INITIALIZE_DATA(A3DGraphPictureData, sPictureData); + sPictureData.m_eFormat = eFormat; + sPictureData.m_uiPixelHeight = uiPixelHeight; + sPictureData.m_uiPixelWidth = uiPixelWidth; + CHECK_RET(stFillBinaryDataWithFile(pcPictureFilePath, sPictureData.m_pucBinaryData, sPictureData.m_uiSize)); + + CHECK_RET(A3DGlobalInsertGraphPicture(&sPictureData, &uiPictureIndex)); + free(sPictureData.m_pucBinaryData); + + return iRet; +} + +//###################################################################################################################### +// Texture creation +A3DStatus createTexture(const A3DUTF8Char* pcPictureFilePath, A3DEPictureDataFormat eFormat, A3DUns32 uiPixelHeight, A3DUns32 uiPixelWidth, A3DUns32& uiStyleIndex) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DUns32 uiPictureIndex; + CHECK_RET(stCreatePicture(pcPictureFilePath, eFormat, uiPixelHeight, uiPixelWidth, uiPictureIndex)); + + A3DUns32 uiMaterialGenericIndex; + CHECK_RET(createMaterial(uiMaterialGenericIndex, DARK_GREY)); + + A3DGraphTextureDefinitionData sTextureDefinitionData; + A3D_INITIALIZE_DATA(A3DGraphTextureDefinitionData, sTextureDefinitionData); + sTextureDefinitionData.m_uiMappingAttributes = kA3DTextureMappingDiffuse; + sTextureDefinitionData.m_ucTextureDimension = 2; + sTextureDefinitionData.m_eMappingType = kA3DTextureMappingTypeStored; + sTextureDefinitionData.m_eMappingOperator = kA3DTextureMappingOperatorUnknown; + sTextureDefinitionData.m_uiPictureIndex = uiPictureIndex; + sTextureDefinitionData.m_eTextureWrappingModeS = kA3DTextureWrappingModeClampToBorder; + sTextureDefinitionData.m_eTextureWrappingModeT = kA3DTextureWrappingModeClampToBorder; + sTextureDefinitionData.m_eTextureFunction = kA3DTextureFunctionModulate; + sTextureDefinitionData.m_dRed = 0.0; + sTextureDefinitionData.m_dGreen = 0.0; + sTextureDefinitionData.m_dBlue = 0.0; + sTextureDefinitionData.m_dAlpha = 0.0; + sTextureDefinitionData.m_eBlend_src_RGB = kA3DTextureBlendParameterUnknown; + sTextureDefinitionData.m_eBlend_dst_RGB = kA3DTextureBlendParameterUnknown; + sTextureDefinitionData.m_eBlend_src_Alpha = kA3DTextureBlendParameterUnknown; + sTextureDefinitionData.m_eBlend_dst_Alpha = kA3DTextureBlendParameterUnknown; + + sTextureDefinitionData.m_ucTextureApplyingMode = kA3DTextureApplyingModeNone; + sTextureDefinitionData.m_eTextureAlphaTest = kA3DTextureAlphaTestUnknown; + sTextureDefinitionData.m_dAlphaTestReference = 0.0; + + A3DUns32 uiIndexTextureDefinition; + CHECK_RET(A3DGlobalInsertGraphTextureDefinition(&sTextureDefinitionData, &uiIndexTextureDefinition)); + free(sTextureDefinitionData.m_pdMappingAttributesIntensity); + CHECK_RET(iRet); + + A3DGraphTextureApplicationData sTextureApplicationData; + A3D_INITIALIZE_DATA(A3DGraphTextureApplicationData, sTextureApplicationData); + sTextureApplicationData.m_uiMaterialIndex = uiMaterialGenericIndex; + sTextureApplicationData.m_uiTextureDefinitionIndex = uiIndexTextureDefinition; + sTextureApplicationData.m_iUVCoordinatesIndex = 0; + sTextureApplicationData.m_uiNextTextureApplicationIndex = A3D_DEFAULT_MATERIAL_INDEX; + + A3DUns32 uiTextureApplicationIndex; + CHECK_RET(A3DGlobalInsertGraphTextureApplication(&sTextureApplicationData, &uiTextureApplicationIndex)); + + // LinePattern is mandatory + A3DUns32 uiLinePatternIndex; + A3DGraphLinePatternData sLinePatternData; + A3D_INITIALIZE_DATA(A3DGraphLinePatternData, sLinePatternData); + sLinePatternData.m_uiNumberOfLengths = 2; + sLinePatternData.m_pdLengths = + (A3DDouble*)malloc(sLinePatternData.m_uiNumberOfLengths * A3DUns32(sizeof(A3DDouble))); + sLinePatternData.m_pdLengths[0] = 10000.0; + sLinePatternData.m_pdLengths[1] = 0.0; + sLinePatternData.m_dPhase = 0.0; + sLinePatternData.m_bRealLength = true; + CHECK_RET(A3DGlobalInsertGraphLinePattern(&sLinePatternData, &uiLinePatternIndex)); + free(sLinePatternData.m_pdLengths); + CHECK_RET(iRet); + + A3DGraphStyleData sStyleData; + A3D_INITIALIZE_DATA(A3DGraphStyleData, sStyleData); + sStyleData.m_bMaterial = true; + sStyleData.m_bVPicture = false; + sStyleData.m_dWidth = 0.1; // default + sStyleData.m_ucTransparency = 255; + sStyleData.m_uiLinePatternIndex = uiLinePatternIndex; + sStyleData.m_uiRgbColorIndex = uiTextureApplicationIndex; + CHECK_RET(A3DGlobalInsertGraphStyle(&sStyleData, &uiStyleIndex)); + + return iRet; +} diff --git a/exchange/exchangesource/CreatePRCCubes/modules/CreateTextures.h b/exchange/exchangesource/CreatePRCCubes/modules/CreateTextures.h new file mode 100644 index 0000000..6d794ba --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/modules/CreateTextures.h @@ -0,0 +1,30 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreateTextures.cpp +* This file is containing the function allowing to create textures. +* +* Texture creation exemple +* Create the style corresponding to texture. +* +* +***********************************************************************************************************************/ +#pragma once + +#include "../CreatePRCCubesDef.h" + +#include "CreateGraphics.h" + +//###################################################################################################################### +// Create the style corresponding to texture. +A3DStatus createTexture(const A3DUTF8Char* pcPictureFilePath, A3DEPictureDataFormat eFormat, A3DUns32 uiPixelHeight, A3DUns32 uiPixelWidth, A3DUns32& uiStyleIndex); + diff --git a/exchange/exchangesource/CreatePRCCubes/modules/CreateViews.cpp b/exchange/exchangesource/CreatePRCCubes/modules/CreateViews.cpp new file mode 100644 index 0000000..fee65f0 --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/modules/CreateViews.cpp @@ -0,0 +1,275 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreateViews.cpp +* This file is containing the function allowing to create views. +* +* The function createView contains a lot of optionnal elements that function as so: +* +* If pCameraPos and pCameraLookAt are defined: function stiA3DGraphSceneDisplayParametersDataAddCamera +* is used to create a camera placement. +* +* If inGraphicsData is defined: linked item will be created in order to, at view activation, +* apply the graphic behavior on the POs defined by ppLinkedPOs. +* +* If ppAnnotations are defined: the designated annotation will not be hidden at view activation. +* +* +***********************************************************************************************************************/ +#include "CreateViews.h" + +#include + +//###################################################################################################################### +// Camera creation +static int stiA3DGraphSceneDisplayParametersDataAddCamera(A3DGraphSceneDisplayParametersData& sGraphSceneDisplayParametersData, + A3DVector3dData& sCameraPos, + A3DVector3dData& sCameraLookAt, + A3DDouble dXFovy, A3DDouble dYFovy) +{ + A3DGraphCameraData sData; + A3DGraphCamera* pCamera = NULL; + A3D_INITIALIZE_DATA(A3DGraphCameraData, sData); + sData.m_bOrthographic = true; + sData.m_dAspectRatio = 1; + sData.m_dZNear = 0.; + sData.m_dZFar = 2. * INFINITE_COORD; + sData.m_dXFovy = (dXFovy == -1.) ? stCameraFovX : dXFovy; + sData.m_dYFovy = (dYFovy == -1.) ? stCameraFovY : dYFovy; + + sData.m_sLookAt.m_dX = sCameraLookAt.m_dX; + sData.m_sLookAt.m_dY = sCameraLookAt.m_dY; + sData.m_sLookAt.m_dZ = sCameraLookAt.m_dZ; + + sData.m_sLocation.m_dX = sCameraPos.m_dX; + sData.m_sLocation.m_dY = sCameraPos.m_dY; + sData.m_sLocation.m_dZ = sCameraPos.m_dZ; + + sData.m_sUp.m_dX = 0.; + sData.m_sUp.m_dY = 1.; + sData.m_sUp.m_dZ = 0.; + + if (A3DGraphCameraCreate(&sData, &pCamera) != A3D_SUCCESS) + return A3D_ERROR; + + sGraphSceneDisplayParametersData.m_pCamera = pCamera; + return A3D_SUCCESS; +} + + +//###################################################################################################################### +//###################################################################################################################### +A3DStatus setViewCameraPlacement(A3DMkpViewData* pMkpViewData, + A3DVector3dData* pCameraPos, + A3DVector3dData* pCameraLookAt, + A3DDouble dXFovy, A3DDouble dYFovy) +{ + A3DStatus iRet = A3D_SUCCESS; + + if (pCameraPos && pCameraLookAt) + { + A3DGraphSceneDisplayParametersData sGraphSceneDisplayParametersData; + A3D_INITIALIZE_DATA(A3DGraphSceneDisplayParametersData, sGraphSceneDisplayParametersData); + sGraphSceneDisplayParametersData.m_uiBackgroundStyleIndex = A3D_DEFAULT_STYLE_INDEX; + stiA3DGraphSceneDisplayParametersDataAddCamera(sGraphSceneDisplayParametersData, *pCameraPos, *pCameraLookAt, dXFovy, dYFovy); + + CHECK_RET(A3DGraphSceneDisplayParametersCreate(&sGraphSceneDisplayParametersData, &pMkpViewData->m_pSceneDisplayParameters)); + } + + return iRet; +} + +//###################################################################################################################### +A3DStatus addViewLinkedItem(A3DMkpViewData* pMkpViewData, + A3DUns32 uiLinkedItemsSize, + A3DMiscMarkupLinkedItem** ppLinkedItems) +{ + A3DStatus iRet = A3D_SUCCESS; + + std::vector vpMarkupLinkedItems; + + // copy previous linked item of view. + for (A3DUns32 i = 0; i < pMkpViewData->m_uiLinkedItemsSize; ++i) + { + vpMarkupLinkedItems.push_back(pMkpViewData->m_ppLinkedItems); + } + + // add the new ones + for (A3DUns32 i = 0; i < uiLinkedItemsSize; ++i) + { + vpMarkupLinkedItems.push_back(ppLinkedItems[i]); + } + + // replace the data + pMkpViewData->m_uiLinkedItemsSize = (A3DUns32)vpMarkupLinkedItems.size(); + pMkpViewData->m_ppLinkedItems = (A3DMiscMarkupLinkedItem**) malloc(pMkpViewData->m_uiLinkedItemsSize * A3DUns32(sizeof(A3DMiscMarkupLinkedItem*))); + for (A3DUns32 i = 0; i < pMkpViewData->m_uiLinkedItemsSize; ++i) + { + pMkpViewData->m_ppLinkedItems[i] = vpMarkupLinkedItems[i]; + } + + return iRet; +} + +//###################################################################################################################### +A3DStatus setIsDefaultView(A3DMkpViewData* pMkpViewData, + A3DBool bIsDefaultView) +{ + A3DStatus iRet = A3D_SUCCESS; + + pMkpViewData->m_bIsDefaultView = bIsDefaultView; + + return iRet; +} + +//###################################################################################################################### +A3DStatus setViewEntitiesOffsetPosition(A3DMkpViewData* pMkpViewData, + A3DUns32 uiLinkedPOsSize, + A3DAsmProductOccurrence** ppLinkedPOs, + A3DMiscCartesianTransformation** ppOffsetTransformation) +{ + A3DStatus iRet = A3D_SUCCESS; + + std::vector vpMarkupLinkedItems; + + // create new Linked items pointing to entity with new coordinates systems + for (A3DUns32 i = 0; i < uiLinkedPOsSize; ++i) + { + // create a linked item pointing to the entity + A3DMiscMarkupLinkedItem* pLinkedItem = 0; + CHECK_RET(createMarkupLinkedItemOnProduct(ppLinkedPOs[i], NULL, &pLinkedItem)); + + // create the new coordinate system + // add the offset to every PO current position + A3DAsmProductOccurrenceData sPOData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sPOData); + CHECK_RET(A3DAsmProductOccurrenceGet(ppLinkedPOs[i], &sPOData)); + A3DMiscCartesianTransformationData sPOTransformationData; + A3D_INITIALIZE_DATA(A3DMiscCartesianTransformationData, sPOTransformationData); + CHECK_RET(A3DMiscCartesianTransformationGet(sPOData.m_pLocation, &sPOTransformationData)); + + A3DMiscCartesianTransformation* pOffsetTransformation = 0; + A3DMiscCartesianTransformationData sOffsetTransformationData; + A3D_INITIALIZE_DATA(A3DMiscCartesianTransformationData, sOffsetTransformationData); + CHECK_RET(A3DMiscCartesianTransformationGet(ppOffsetTransformation[i], &sOffsetTransformationData)); + sOffsetTransformationData.m_sOrigin.m_dX += sPOTransformationData.m_sOrigin.m_dX; + sOffsetTransformationData.m_sOrigin.m_dY += sPOTransformationData.m_sOrigin.m_dY; + sOffsetTransformationData.m_sOrigin.m_dZ += sPOTransformationData.m_sOrigin.m_dZ; + CHECK_RET(A3DMiscCartesianTransformationCreate(&sOffsetTransformationData, &pOffsetTransformation)); + + //create a CoordSystem + A3DRiCoordinateSystem* pCoordinateSystem = 0; + A3DRiCoordinateSystemData sCoordinateSystemData; + A3D_INITIALIZE_DATA(A3DRiCoordinateSystemData, sCoordinateSystemData); + sCoordinateSystemData.m_pTransformation = pOffsetTransformation; + CHECK_RET(A3DRiCoordinateSystemCreate(&sCoordinateSystemData, &pCoordinateSystem)); + + //Create a A3DMiscEntityReference with the coordinates + A3DMiscEntityReferenceData sMiscEntityRefData; + A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sMiscEntityRefData); + sMiscEntityRefData.m_pEntity = ppLinkedPOs[i]; + sMiscEntityRefData.m_pCoordinateSystem = pCoordinateSystem; + + //Attach A3DMiscEntityReference to the MkpLinkedItem previously created, pointing to entity + CHECK_RET(A3DMiscEntityReferenceSet(pLinkedItem, &sMiscEntityRefData)); + + vpMarkupLinkedItems.push_back(pLinkedItem); + } + + CHECK_RET(addViewLinkedItem(pMkpViewData, (A3DUns32)vpMarkupLinkedItems.size(), &vpMarkupLinkedItems[0])); + + return iRet; +} + +//###################################################################################################################### +A3DStatus setViewEntitiesGraphics(A3DMkpViewData* pMkpViewData, + A3DUns32 uiLinkedPOsSize, + A3DAsmProductOccurrence** ppLinkedPOs, + A3DRootBaseWithGraphicsData* inGraphicsData) +{ + A3DStatus iRet = A3D_SUCCESS; + + std::vector vpMarkupLinkedItems; + + // create new Linked items pointing to entity with graphics + for (A3DUns32 i = 0; i < uiLinkedPOsSize; ++i) + { + // create a linked item pointing to the entity + A3DMiscMarkupLinkedItem* pLinkedItem = 0; + CHECK_RET(createMarkupLinkedItemOnProduct(ppLinkedPOs[i], NULL, &pLinkedItem)); + // add the graphic to the linked item + CHECK_RET(A3DRootBaseWithGraphicsSet(pLinkedItem, inGraphicsData)); + + vpMarkupLinkedItems.push_back(pLinkedItem); + } + + CHECK_RET(addViewLinkedItem(pMkpViewData, (A3DUns32)vpMarkupLinkedItems.size(), &vpMarkupLinkedItems[0])); + + return iRet; +} + +//###################################################################################################################### +// The following function is only to be used when the annotations are owned by the same PO as the view will be. +A3DStatus setViewAnnotations(A3DMkpViewData* pMkpViewData, + A3DUns32 uiAnnotationsSize, + A3DMkpAnnotationEntity ** ppAnnotations) +{ + A3DStatus iRet = A3D_SUCCESS; + + pMkpViewData->m_uiAnnotationsSize = uiAnnotationsSize; + pMkpViewData->m_ppAnnotations = ppAnnotations; + + return iRet; +} + +// The following function is to be used when the annotations are owned by the PO that is a child of the PO that own the view. +A3DStatus setViewAnnotations(A3DMkpViewData* pMkpViewData, + A3DUns32 uiAnnotationsSize, + A3DMkpAnnotationEntity ** ppAnnotations, + A3DAsmProductOccurrence** ppPOOwners) +{ + A3DStatus iRet = A3D_SUCCESS; + + std::vector vpMarkupLinkedItems; + + // create new Linked items pointing to annotation + for (A3DUns32 i = 0; i < uiAnnotationsSize; ++i) + { + // create a linked item pointing to the annotation + // note that the PO owner of the annotation should be set. + A3DMiscMarkupLinkedItem* pLinkedItem = 0; + CHECK_RET(createMarkupLinkedItemOnEntity(ppAnnotations[i], ppPOOwners[i], &pLinkedItem)); + + vpMarkupLinkedItems.push_back(pLinkedItem); + } + + CHECK_RET(addViewLinkedItem(pMkpViewData, (A3DUns32)vpMarkupLinkedItems.size(), &vpMarkupLinkedItems[0])); + + return iRet; +} + + +//###################################################################################################################### +A3DStatus createView(A3DMkpView** ppOutMkupView, + A3DMkpViewData* pMkpViewData, + const A3DUTF8Char* inName) +{ + A3DStatus iRet = A3D_SUCCESS; + + CHECK_RET(A3DMkpViewCreate(pMkpViewData, ppOutMkupView)); + setEntityName(*ppOutMkupView, inName); + + return iRet; +} + + + diff --git a/exchange/exchangesource/CreatePRCCubes/modules/CreateViews.h b/exchange/exchangesource/CreatePRCCubes/modules/CreateViews.h new file mode 100644 index 0000000..7dba0fb --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/modules/CreateViews.h @@ -0,0 +1,74 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +* Sample CreatePRCCubes +* file CreateViews.cpp +* This file is containing the function allowing to create views with optionnal elements. +* +* +* +* +***********************************************************************************************************************/ +#pragma once + +#include "../CreatePRCCubesDef.h" + +#include "CreateLinkedItem.h" +#include "CreateGraphics.h" + +//###################################################################################################################### + +static const double stCameraFovX = 1000; +static const double stCameraFovY = 1000; + +static const A3DVector3dData stCameraPosDefault = {0, 2000, 0, 0}; +static const A3DVector3dData stCameraLookAtDefault = { 0, 300, 1050, 1050 }; + +//###################################################################################################################### +A3DStatus setViewCameraPlacement(A3DMkpViewData* pMkpViewData, + A3DVector3dData* pCameraPos, + A3DVector3dData* pCameraLookAt, + A3DDouble dXFovy, A3DDouble dYFovy); + +A3DStatus addViewLinkedItem(A3DMkpViewData* pMkpViewData, + A3DUns32 uiLinkedItemsSize, + A3DMiscMarkupLinkedItem** ppLinkedItems); + +A3DStatus setIsDefaultView(A3DMkpViewData* pMkpViewData, + A3DBool bIsDefaultView); + +A3DStatus setViewEntitiesOffsetPosition(A3DMkpViewData* pMkpViewData, + A3DUns32 uiLinkedPOsSize, + A3DAsmProductOccurrence** ppLinkedPOs, + A3DMiscCartesianTransformation** ppOffsetTransformation); + +A3DStatus setViewEntitiesGraphics(A3DMkpViewData* pMkpViewData, + A3DUns32 uiLinkedPOsSize, + A3DAsmProductOccurrence** ppLinkedPOs, + A3DRootBaseWithGraphicsData* inGraphicsData); + +// The following function is only to be used when the annotations are owned by the same PO as the view will be. +A3DStatus setViewAnnotations(A3DMkpViewData* pMkpViewData, + A3DUns32 uiAnnotationsSize, + A3DMkpAnnotationEntity ** ppAnnotations); + +// The following function is to be used when the annotations are owned by the PO that is a child of the PO that own the view. +A3DStatus setViewAnnotations(A3DMkpViewData* pMkpViewData, + A3DUns32 uiAnnotationsSize, + A3DMkpAnnotationEntity ** ppAnnotations, + A3DAsmProductOccurrence** ppPOOwners); + +A3DStatus createView(A3DMkpView** ppOutMkupView, + A3DMkpViewData* pMkpViewData, + const A3DUTF8Char* inName); + + + diff --git a/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWBasicTessellation.cpp b/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWBasicTessellation.cpp new file mode 100644 index 0000000..a0e4670 --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWBasicTessellation.cpp @@ -0,0 +1,112 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file wrapper/HXWBasicTessellation.cpp + +***********************************************************************************************************************/ + +#include +#include "HXWBasicTessellation.h" + + + +//###################################################################################################################### +HXWBasicTessellation::HXWBasicTessellation() +{ + A3D_INITIALIZE_DATA(A3DTessBaseData, m_coordsdata); + m_coordsdata.m_pdCoords = NULL; + m_coordsdata.m_uiCoordSize = m_uiCoordsAllocated = 0; +} + +//###################################################################################################################### +HXWBasicTessellation::~HXWBasicTessellation() +{ + A3D_INITIALIZE_DATA(A3DTessBaseData, m_coordsdata); + reset(); +} + +//###################################################################################################################### +void HXWBasicTessellation::reset() +{ + free(m_coordsdata.m_pdCoords); + m_coordsdata.m_pdCoords = NULL; + m_coordsdata.m_uiCoordSize = m_uiCoordsAllocated = 0; +} + +//###################################################################################################################### +void HXWBasicTessellation::add_coords(A3DDouble* pdCoords, A3DUns32 uiCoordsSize) +{ + if(m_uiCoordsAllocated == 0) + { + m_uiCoordsAllocated = ALLOCATION_STEP + uiCoordsSize; + m_coordsdata.m_pdCoords = (A3DDouble*) malloc((size_t) m_uiCoordsAllocated * sizeof(A3DDouble)); + } + else if(!(uiCoordsSize + m_coordsdata.m_uiCoordSize < m_uiCoordsAllocated)) + { + m_uiCoordsAllocated = uiCoordsSize + m_coordsdata.m_uiCoordSize + ALLOCATION_STEP; + A3DDouble* temp = (A3DDouble*) malloc((size_t) m_uiCoordsAllocated * sizeof(A3DDouble)); + memcpy(temp, m_coordsdata.m_pdCoords, (size_t) m_coordsdata.m_uiCoordSize * sizeof(A3DDouble)); + if(m_coordsdata.m_pdCoords != NULL) + { + free(m_coordsdata.m_pdCoords); + m_coordsdata.m_pdCoords = NULL; + } + m_coordsdata.m_pdCoords = temp; + } + m_coordsdata.m_uiCoordSize += uiCoordsSize; + for(unsigned i = 0 ; i < uiCoordsSize; ++i) + m_coordsdata.m_pdCoords[m_coordsdata.m_uiCoordSize-uiCoordsSize+i] = pdCoords[i]; +} + +//###################################################################################################################### +void HXWBasicTessellation::add_coord(A3DDouble dCoord) +{ + if(m_uiCoordsAllocated == 0) + { + m_coordsdata.m_pdCoords = (A3DDouble*) malloc(ALLOCATION_STEP * sizeof(A3DDouble)); + m_uiCoordsAllocated = ALLOCATION_STEP; + } + else if(!(m_coordsdata.m_uiCoordSize + 1< m_uiCoordsAllocated)) + { + m_uiCoordsAllocated = m_coordsdata.m_uiCoordSize + ALLOCATION_STEP; + A3DDouble* temp =(A3DDouble*) malloc((size_t) m_uiCoordsAllocated * sizeof(A3DDouble)); + memcpy(temp, m_coordsdata.m_pdCoords, (size_t) m_coordsdata.m_uiCoordSize * sizeof(A3DDouble)); + if(m_coordsdata.m_pdCoords != NULL) + { + free(m_coordsdata.m_pdCoords); + m_coordsdata.m_pdCoords = NULL; + } + m_coordsdata.m_pdCoords = temp; + } + m_coordsdata.m_pdCoords[m_coordsdata.m_uiCoordSize++] = dCoord; +} + +//###################################################################################################################### +void HXWBasicTessellation::free_extra_coords() +{ + if(m_coordsdata.m_uiCoordSize == m_uiCoordsAllocated) + return; + + A3DDouble* pnew = NULL; + if(m_coordsdata.m_uiCoordSize != 0) + { + pnew = (A3DDouble*) malloc((size_t) m_coordsdata.m_uiCoordSize * sizeof(A3DDouble)); + memcpy(pnew, m_coordsdata.m_pdCoords, (size_t) m_coordsdata.m_uiCoordSize * sizeof(A3DDouble)); + } + if(m_coordsdata.m_pdCoords != NULL) + { + free(m_coordsdata.m_pdCoords); + m_coordsdata.m_pdCoords = NULL; + } + + m_coordsdata.m_pdCoords = pnew; + m_uiCoordsAllocated = m_coordsdata.m_uiCoordSize; +} diff --git a/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWBasicTessellation.h b/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWBasicTessellation.h new file mode 100644 index 0000000..46daad8 --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWBasicTessellation.h @@ -0,0 +1,58 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file wrapper/HXWBasicTessellation.h + +Header file for the wrapper Tessellation module. + +***********************************************************************************************************************/ + +#include "HXWEntity.h" + +#include + +/*! +\defgroup wrapper_tessellation_module Tessellation Module +\ingroup wrapper_module +Entity type is \ref HXWBasicTessellation. +*/ + +/*! \class HXWBasicTessellation HXWBasicTessellation.h "HXWBasicTessellation.h" +* \brief This is a tessellation builder. +* \ingroup wrapper_tessellation_module +*/ +class HXWBasicTessellation: public HXWEntity +{ +protected: + static const int ALLOCATION_STEP = 5; /*! step in allocation or reallocation array of coords, codes, etc. */ + +protected: + A3DTessBaseData m_coordsdata; /*!< tessellation that is built */ + A3DUns32 m_uiCoordsAllocated; + +protected: + A3DPtr my_alloc(A3DUns32 uiSize) { return malloc((size_t) uiSize); } /*!< allocation for A3DTessBaseData */ + A3DVoid my_free(A3DPtr ptr) { free(ptr); ptr = NULL; } /*!< free for A3DTessBaseData */ + +public: + HXWBasicTessellation(); + ~HXWBasicTessellation(); + +protected: + void add_coord(A3DDouble dCoord); /*!< add one double in tessellation */ + void add_coords(A3DDouble* pdCoords, A3DUns32 uiCoordsSize); /*!< add an array of doubles in tessellation */ + virtual void reset(); /*!< reset of doubles in tessellation */ + void free_extra_coords(); /*!< to manage extra allocations */ + +public: + /*!< set the tessellation in exchange owner structure */ + inline int SetCoords(A3DTessBase* pTessMarkup) { return A3DTessBaseSet(pTessMarkup,&m_coordsdata); } +}; diff --git a/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWEntity.cpp b/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWEntity.cpp new file mode 100644 index 0000000..2131aea --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWEntity.cpp @@ -0,0 +1,29 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file wrapper/HXWEntity.cpp + +***********************************************************************************************************************/ + +#include +#include "HXWEntity.h" + + + +//###################################################################################################################### +HXWEntity::HXWEntity() +{ +} + +//###################################################################################################################### +HXWEntity::~HXWEntity() +{ +} diff --git a/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWEntity.h b/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWEntity.h new file mode 100644 index 0000000..10f4efb --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWEntity.h @@ -0,0 +1,53 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file wrapper/HXWEntity.h + +Header file for the wrapper Tessellation module. + +***********************************************************************************************************************/ + +#define ERR_RET(TEST) { if(TEST != A3D_SUCCESS) return A3D_ERROR; } + + + +/*! +\defgroup wrapper_module Wrapper Module +*/ + +class HXWVector3d +{ +public: + A3DVector3dData m_data; + +public: + HXWVector3d(double dx, double dy, double dz) + { + A3D_INITIALIZE_DATA(A3DVector3dData, m_data); + m_data.m_dX = dx; + m_data.m_dY = dy; + m_data.m_dZ = dz; + } + ~HXWVector3d() {}; +}; + +/*! \class HXWEntity HXWEntity.h "HXWEntity.h" +* \ingroup wrapper_module +*/ +class HXWEntity +{ +public: + HXWEntity(); + ~HXWEntity(); + +public: + virtual A3DEntity* GetEntity() = 0; +}; diff --git a/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWMarkupTessellation.cpp b/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWMarkupTessellation.cpp new file mode 100644 index 0000000..2828b97 --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWMarkupTessellation.cpp @@ -0,0 +1,556 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file wrapper/HXWMarkupTessellation.cpp + +***********************************************************************************************************************/ + +#include +#include "HXWMarkupTessellation.h" + +#include + +//###################################################################################################################### +HXWMarkupTessellation::HXWMarkupTessellation() +{ + A3D_INITIALIZE_DATA(A3DTessMarkupData, m_data); + m_data.m_puiCodes = NULL; + m_data.m_ppcTexts = NULL; + m_data.m_uiCodesSize = m_uiAllocatedCodes = 0; + m_data.m_uiTextsSize = m_uiAllocatedTexts = 0; +} + +//###################################################################################################################### +HXWMarkupTessellation::~HXWMarkupTessellation() +{ + reset(); +} + +//###################################################################################################################### +A3DEntity* HXWMarkupTessellation::GetEntity() +{ + A3DTessMarkup* pTessMarkup; + GetMarkupTess(pTessMarkup); + return pTessMarkup; +} + +//###################################################################################################################### +void HXWMarkupTessellation::reset() +{ + HXWBasicTessellation::reset(); + + free(m_data.m_pcLabel); + m_data.m_pcLabel = NULL; + + free(m_data.m_puiCodes); + m_data.m_puiCodes = NULL; + + A3DUns32 i; + for(i = 0; i < m_data.m_uiTextsSize; ++i) + free(m_data.m_ppcTexts[i]); + + free(m_data.m_ppcTexts); + m_data.m_ppcTexts = NULL; + + m_data.m_uiCodesSize = m_uiAllocatedCodes = 0; + m_data.m_uiTextsSize = m_uiAllocatedTexts = 0; +} + +//###################################################################################################################### +void HXWMarkupTessellation::add_code(A3DUns32 uiCode) +{ + if(m_uiAllocatedCodes == 0) + { + m_data.m_puiCodes = (A3DUns32*) malloc(ALLOCATION_STEP * sizeof(A3DUns32)); + m_uiAllocatedCodes = ALLOCATION_STEP; + } + else if(!(m_data.m_uiCodesSize + 1 < m_uiAllocatedCodes)) + { + m_uiAllocatedCodes = m_data.m_uiCodesSize + ALLOCATION_STEP; + A3DUns32* temp = (A3DUns32*) malloc((size_t) m_uiAllocatedCodes * sizeof(A3DUns32)); + memcpy(temp, m_data.m_puiCodes, (size_t) m_data.m_uiCodesSize * sizeof(A3DUns32)); + if(m_data.m_puiCodes != NULL) + { + free(m_data.m_puiCodes); + m_data.m_puiCodes = NULL; + } + m_data.m_puiCodes = temp; + } + m_data.m_puiCodes[m_data.m_uiCodesSize++] = uiCode; +} + +//###################################################################################################################### +int HXWMarkupTessellation::set_color(A3DDouble dRed, A3DDouble dGreen, A3DDouble dBlue) +{ + // add color in session color table + A3DUns32 uiIndexColor; + A3DGraphRgbColorData sData; + A3D_INITIALIZE_DATA(A3DGraphRgbColorData, sData); + sData.m_dRed = dRed; + sData.m_dGreen = dGreen; + sData.m_dBlue = dBlue; + ERR_RET(A3DGlobalInsertGraphRgbColor(&sData,&uiIndexColor)); + + // add in tessellation + return set_color(uiIndexColor); +} + +//###################################################################################################################### +int HXWMarkupTessellation::set_color(A3DUns32 uiIndexColor) +{ + if(uiIndexColor == A3D_DEFAULT_COLOR_INDEX) + return 0; + // add in tessellation + // 1 = number of additionnal codes, here just one for the index color + add_code(A3D_ENCODE_EXTRA_DATA(kA3DMarkupColorMask, 1)); + add_code(0); + add_code(uiIndexColor); + return A3D_SUCCESS; +} + +//###################################################################################################################### +int HXWMarkupTessellation::set_textfont(const A3DUTF8Char* pcFamilyName, A3DUns32 uiSize, A3DInt8 cAttributes, + A3DECharSet eCharset) +{ + // add font in session font tables + A3DFontData sFontData; + A3D_INITIALIZE_DATA(A3DFontData, sFontData); + sFontData.m_cAttributes = cAttributes; // kA3DFontItalic | kA3DFontUnderlined; + sFontData.m_eCharset = eCharset; + + unsigned int uiLength = (A3DUns32) (pcFamilyName ? strlen(pcFamilyName) : 0); + if(!uiLength) + return A3D_ERROR; + + A3DUTF8Char* newText = (A3DUTF8Char*) malloc(((size_t) (uiLength + 1)) * sizeof(A3DUTF8Char)); + memcpy(newText, pcFamilyName, ((size_t) (uiLength + 1)) * sizeof(A3DUTF8Char)); + sFontData.m_pcFamilyName = newText; + + sFontData.m_uiSize = uiSize; + A3DFontKeyData sFontKeyData; + A3D_INITIALIZE_DATA(A3DFontKeyData, sFontKeyData); + ERR_RET(A3DGlobalFontKeyCreate(&sFontData, &sFontKeyData)); + free(newText); + + m_sFontKeyData.m_cAttributes = sFontKeyData.m_cAttributes; + m_sFontKeyData.m_iFontFamilyIndex = sFontKeyData.m_iFontFamilyIndex; + m_sFontKeyData.m_iFontSizeIndex = sFontKeyData.m_iFontSizeIndex; + m_sFontKeyData.m_iFontStyleIndex = sFontKeyData.m_iFontStyleIndex; + m_sFontKeyData.m_usStructSize = sFontKeyData.m_usStructSize; + + // the font attributes are compressed + A3DUns32 uiAttrib = + (sFontKeyData.m_cAttributes) + (sFontKeyData.m_iFontSizeIndex << 12) + (sFontKeyData.m_iFontStyleIndex << 24); + + // add in tessellation + add_code(A3D_ENCODE_EXTRA_DATA(kA3DMarkupFontMask, 2)); + add_code(0); + add_code(sFontKeyData.m_iFontFamilyIndex); + add_code(uiAttrib); + + return A3D_SUCCESS; +} + +//###################################################################################################################### +void HXWMarkupTessellation::setlabel(A3DUTF8Char* pcLabel) +{ + free(m_data.m_pcLabel); + + unsigned int uiSize = (A3DUns32) (pcLabel ? strlen(pcLabel) : 0); + m_data.m_pcLabel = (A3DUTF8Char*) malloc(((size_t) (uiSize + 1)) * sizeof(A3DUTF8Char)); + memcpy(m_data.m_pcLabel, pcLabel, (size_t) (uiSize + 1) * sizeof(A3DUTF8Char)); + + return; +} + +//###################################################################################################################### +void HXWMarkupTessellation::add_text(const A3DUTF8Char* pcText, A3DDouble dTextWidth, A3DDouble dTextHeight) +{ + unsigned int uiSize = (A3DUns32) (pcText ? strlen(pcText) : 0); + if (!uiSize) + return; + + if (m_data.m_uiTextsSize == 0) + { + m_data.m_ppcTexts = (A3DUTF8Char**) malloc(ALLOCATION_STEP * sizeof(A3DUTF8Char*)); + m_uiAllocatedTexts = ALLOCATION_STEP; + } + else if (!(m_data.m_uiTextsSize + 1 < m_uiAllocatedTexts)) + { + m_uiAllocatedTexts = m_data.m_uiTextsSize + ALLOCATION_STEP; + m_data.m_ppcTexts = + (A3DUTF8Char**) realloc(m_data.m_ppcTexts, (size_t) m_uiAllocatedTexts * sizeof(A3DUTF8Char*)); + } + + A3DUTF8Char* newText = (A3DUTF8Char*) malloc(((size_t) (uiSize + 1)) * sizeof(A3DUTF8Char)); + memcpy(newText, pcText, ((size_t) (uiSize + 1)) * sizeof(A3DUTF8Char)); + m_data.m_ppcTexts[m_data.m_uiTextsSize] = newText; + + add_code(A3D_ENCODE_EXTRA_DATA(kA3DMarkupTextMask, 1)); + add_code(2); // width of text + height of text + add_code(m_data.m_uiTextsSize); //index in text array + m_data.m_uiTextsSize++; + + double dWidth, dHeight; + A3DGlobalFontTextBoxGet(&m_sFontKeyData, (char*)pcText, &dWidth, &dHeight); + + double dScaleWidth, dScaleHeight; + // dScaleHeight = dScaleWidth = 1; + dScaleWidth = dTextWidth / dWidth; + dScaleHeight = dTextHeight / dHeight; + + m_coordsdata.m_pdCoords[m_coordsdata.m_uiCoordSize - 16] *= dScaleWidth; + m_coordsdata.m_pdCoords[m_coordsdata.m_uiCoordSize - 15] *= dScaleWidth; + m_coordsdata.m_pdCoords[m_coordsdata.m_uiCoordSize - 14] *= dScaleWidth; + + m_coordsdata.m_pdCoords[m_coordsdata.m_uiCoordSize - 12] *= dScaleHeight; + m_coordsdata.m_pdCoords[m_coordsdata.m_uiCoordSize - 11] *= dScaleHeight; + m_coordsdata.m_pdCoords[m_coordsdata.m_uiCoordSize - 10] *= dScaleHeight; + + add_coord(dWidth); + add_coord(dHeight); +} + +//###################################################################################################################### +void HXWMarkupTessellation::add_text(const A3DUTF8Char* pcText) +{ + unsigned int uiSize = (A3DUns32) (pcText ? strlen(pcText) : 0); + if (!uiSize) + return; + + if (m_data.m_uiTextsSize == 0) + { + m_data.m_ppcTexts = (A3DUTF8Char**) malloc(ALLOCATION_STEP * sizeof(A3DUTF8Char*)); + m_uiAllocatedTexts = ALLOCATION_STEP; + } + else if (!(m_data.m_uiTextsSize + 1 < m_uiAllocatedTexts)) + { + m_uiAllocatedTexts = m_data.m_uiTextsSize + ALLOCATION_STEP; + m_data.m_ppcTexts = + (A3DUTF8Char**) realloc(m_data.m_ppcTexts, (size_t) m_uiAllocatedTexts * sizeof(A3DUTF8Char*)); + } + + A3DUTF8Char* newText = (A3DUTF8Char*) malloc(((size_t) (uiSize + 1)) * sizeof(A3DUTF8Char)); + memcpy(newText, pcText, ((size_t) (uiSize + 1)) * sizeof(A3DUTF8Char)); + m_data.m_ppcTexts[m_data.m_uiTextsSize] = newText; + + add_code(A3D_ENCODE_EXTRA_DATA(kA3DMarkupTextMask, 1)); + add_code(2); // width of text + height of text + add_code(m_data.m_uiTextsSize); //index in text array + m_data.m_uiTextsSize++; + + double dWidth, dHeight; + A3DGlobalFontTextBoxGet(&m_sFontKeyData, (char*)pcText, &dWidth, &dHeight); + + add_coord(dWidth); + add_coord(dHeight); +} + +//###################################################################################################################### +void HXWMarkupTessellation::free_extra_codes() +{ + if(m_data.m_uiCodesSize == m_uiAllocatedCodes) + return; + A3DUns32* pnew = NULL; + if(m_data.m_uiCodesSize != 0) + { + pnew = (A3DUns32*) malloc((size_t) m_data.m_uiCodesSize * sizeof(A3DUns32)); + memcpy(pnew, m_data.m_puiCodes, (size_t) m_data.m_uiCodesSize * sizeof(A3DUns32)); + } + if(m_data.m_puiCodes != NULL) + { + free(m_data.m_puiCodes); + m_data.m_puiCodes = NULL; + } + m_data.m_puiCodes = pnew; + m_uiAllocatedCodes = m_data.m_uiCodesSize; +} + +//###################################################################################################################### +void HXWMarkupTessellation::add_polyline(A3DDouble* ppoints, A3DUns32 uPtSize) +{ + add_code(0); // start of coords in tessellation array + add_code(uPtSize*3); // number of doubles to take into account + add_coords(ppoints, uPtSize*3); +} + +//###################################################################################################################### +void HXWMarkupTessellation::add_polygon(A3DDouble* ppoints, A3DUns32 uPtSize) +{ + add_code(A3D_ENCODE_EXTRA_DATA(kA3DMarkupPolygonMask, 0)); + add_code(uPtSize * 3); // number of doubles to take into account + add_coords(ppoints, uPtSize * 3); +} + +//###################################################################################################################### +void HXWMarkupTessellation::add_triangle(A3DDouble* pptriangles) +{ + add_code(A3D_ENCODE_EXTRA_DATA(kA3DMarkupTrianglesMask, 0)); + add_code(9); + add_coords(pptriangles, 9); +} + +//###################################################################################################################### +void HXWMarkupTessellation::add_triangles(A3DDouble* pptriangles, A3DUns32 uTriangleSize) +{ + add_code(A3D_ENCODE_EXTRA_DATA(kA3DMarkupTrianglesMask, 0)); + add_code(uTriangleSize * 9); + add_coords(pptriangles, uTriangleSize * 9); +} + +//###################################################################################################################### +void HXWMarkupTessellation::add_polygons(A3DDouble* ppolygons, A3DUns32 uPolygonSize) +{ + add_code(A3D_ENCODE_EXTRA_DATA(kA3DMarkupPolygonMask, 0)); + add_code(uPolygonSize * 3); + add_coords(ppolygons, uPolygonSize * 3); +} + +//###################################################################################################################### +void HXWMarkupTessellation::add_ellipse(A3DDouble dWidth, A3DDouble dHeight) +{ + int numPoints = 150; + // Background + A3DDouble* pdMarkupEllipseData = (A3DDouble*) malloc(3* numPoints * sizeof(A3DDouble)); + + for (int p = 0; p < numPoints; ++p) + { + pdMarkupEllipseData[3 * p] = dWidth / 2 * std::cos(p * 2 * 3.14159265 / numPoints); + pdMarkupEllipseData[3 * p + 1] = dHeight / 2 * std::sin(p * 2 * 3.14159265 / numPoints); + pdMarkupEllipseData[3 * p + 2] = 0; + } + + add_polygons(pdMarkupEllipseData, numPoints); + //set_color(0, 0, 1); + //dd_polyline(pdMarkupEllipseData, numPoints); + free(pdMarkupEllipseData); +} + + +//###################################################################################################################### +void HXWMarkupTessellation::add_ellipseFrame(A3DDouble dWidth, A3DDouble dHeight) +{ + int numPoints = 150; + // Background + A3DDouble* pdMarkupEllipseData = (A3DDouble*) malloc(3 * numPoints * sizeof(A3DDouble)); + + for (int p = 0; p < numPoints; ++p) + { + pdMarkupEllipseData[3 * p] = dWidth / 2 * std::cos(p * 2 * 3.14159265 / numPoints); + pdMarkupEllipseData[3 * p + 1] = dHeight / 2 * std::sin(p * 2 * 3.14159265 / numPoints); + pdMarkupEllipseData[3 * p + 2] = 0; + } + + add_polyline(pdMarkupEllipseData, numPoints); + free(pdMarkupEllipseData); +} + + +//###################################################################################################################### +void HXWMarkupTessellation::add_rectFrame(A3DDouble dWidth, A3DDouble dHeight) +{ + // Frame + A3DDouble* pdMarkupFrameData = (A3DDouble*) malloc(16 * sizeof(A3DDouble)); + pdMarkupFrameData[0] = -dWidth / 2; // lower left corner + pdMarkupFrameData[1] = -dHeight / 2; + pdMarkupFrameData[2] = 0; + + pdMarkupFrameData[3] = pdMarkupFrameData[0] + dWidth; // lower right corner + pdMarkupFrameData[4] = pdMarkupFrameData[1]; + pdMarkupFrameData[5] = pdMarkupFrameData[2]; + + pdMarkupFrameData[6] = pdMarkupFrameData[0] + dWidth; // upper right corner + pdMarkupFrameData[7] = pdMarkupFrameData[1] + dHeight; + pdMarkupFrameData[8] = pdMarkupFrameData[2]; + + pdMarkupFrameData[9] = pdMarkupFrameData[0]; // upper left corner + pdMarkupFrameData[10] = pdMarkupFrameData[1] + dHeight; + pdMarkupFrameData[11] = pdMarkupFrameData[2]; + + pdMarkupFrameData[12] = pdMarkupFrameData[0]; // lower left corner + pdMarkupFrameData[13] = pdMarkupFrameData[1]; + pdMarkupFrameData[14] = pdMarkupFrameData[2]; + + add_polyline(pdMarkupFrameData, 5); + free(pdMarkupFrameData); + +} + + +//###################################################################################################################### +void HXWMarkupTessellation::add_rect(A3DDouble dWidth, A3DDouble dHeight) +{ + A3DDouble* pdMarkupBackGroundData = (A3DDouble*) malloc(12 * sizeof(A3DDouble)); + pdMarkupBackGroundData[0] = -dWidth / 2; // lower left corner + pdMarkupBackGroundData[1] = - dHeight / 2; + pdMarkupBackGroundData[2] = 0; + + pdMarkupBackGroundData[3] = pdMarkupBackGroundData[0] + dWidth; // lower right corner + pdMarkupBackGroundData[4] = pdMarkupBackGroundData[1]; + pdMarkupBackGroundData[5] = pdMarkupBackGroundData[2]; + + pdMarkupBackGroundData[6] = pdMarkupBackGroundData[0] + dWidth; // upper right corner + pdMarkupBackGroundData[7] = pdMarkupBackGroundData[1] + dHeight; + pdMarkupBackGroundData[8] = pdMarkupBackGroundData[2]; + + pdMarkupBackGroundData[9] = pdMarkupBackGroundData[0]; // upper left corner + pdMarkupBackGroundData[10] = pdMarkupBackGroundData[1] + dHeight; + pdMarkupBackGroundData[11] = pdMarkupBackGroundData[2]; + + add_polygons(pdMarkupBackGroundData, 4); + free(pdMarkupBackGroundData); +} + + + +//###################################################################################################################### +void HXWMarkupTessellation::begin_matrix(A3DDouble* matrix) +{ + if(matrix) + { + add_code(kA3DMarkupIsMatrix); + add_code(16); // start of coords in tessellation array + add_coords(matrix, 16); + } +} + +//###################################################################################################################### +void HXWMarkupTessellation::begin_matrix(const A3DVector3dData& position_3d, const A3DVector3dData& plane_normal, + const A3DVector3dData& x_direction) +{ + A3DVector3dData y_direction; + y_direction.m_dX = plane_normal.m_dY * x_direction.m_dZ - plane_normal.m_dZ * x_direction.m_dY; + y_direction.m_dY = -(plane_normal.m_dX * x_direction.m_dZ - plane_normal.m_dZ * x_direction.m_dX); + y_direction.m_dZ = plane_normal.m_dX * x_direction.m_dY - plane_normal.m_dY * x_direction.m_dX; + double dScaleX = 1; + double dScaleY = 1; + A3DDouble *matrix = (A3DDouble*) malloc(16 * sizeof(A3DDouble)); + matrix[0] = x_direction.m_dX * dScaleX; + matrix[1] = x_direction.m_dY * dScaleX; + matrix[2] = x_direction.m_dZ * dScaleX; + matrix[3] = 0.0; + matrix[4] = y_direction.m_dX * dScaleY; + matrix[5] = y_direction.m_dY * dScaleY; + matrix[6] = y_direction.m_dZ * dScaleY; + matrix[7] = 0.0; + matrix[8] = plane_normal.m_dX * 1; + matrix[9] = plane_normal.m_dY* 1; + matrix[10] = plane_normal.m_dZ* 1; + matrix[11] = 0.0; + matrix[12] = position_3d.m_dX; + matrix[13] = position_3d.m_dY; + matrix[14] = position_3d.m_dZ; + matrix[15] = 1.0; + add_code(kA3DMarkupIsMatrix); + add_code(16); //start of coords in tessellation array + add_coords(matrix, 16); + free(matrix); +} + +//###################################################################################################################### +void HXWMarkupTessellation::end_matrix() +{ + /* end of matrix mode */ + add_code(kA3DMarkupIsMatrix); + add_code(0); +} + +//###################################################################################################################### +void HXWMarkupTessellation::GetMarkupTess(A3DTessMarkup*& pTessMarkup) +{ + pTessMarkup = NULL; + + A3DTessMarkupData sTessData; + A3D_INITIALIZE_DATA(A3DTessMarkupData, sTessData); + + free_extra_coords(); + free_extra_codes(); + + A3DTessMarkupCreate(&m_data,&pTessMarkup); + + A3DTessBaseData sTessBaseData; + A3D_INITIALIZE_DATA(A3DTessBaseData, sTessBaseData); + SetCoords(pTessMarkup); +} + +/* +Not managed by Acrobat Reader for now - Tech Soft 3D needs to work with Adobe on this issue. +//###################################################################################################################### +void HXWMarkupTessellation::set_line_width(double dWidth) +{ + add_code(A3D_ENCODE_EXTRA_DATA(kA3DMarkupLineWidthMask, 0)); + add_code(1); + add_coords(&dWidth, 1); +} + +//###################################################################################################################### +void HXWMarkupTessellation::end_line_width() +{ + add_code(A3D_ENCODE_EXTRA_DATA(kA3DMarkupLineWidthMask, 0)); + add_code(0); +} +*/ + + +//######################################################################################################################*/ +void HXWMarkupTessellation::BeginFaceView(A3DDouble* pOrigin) +{ + add_code(A3D_ENCODE_EXTRA_DATA(kA3DMarkupFaceViewMask, 0)); + add_code(3); + add_coords(pOrigin, 3); + + m_uiStartSizeWireFV = m_data.m_uiCodesSize - 2; + m_uiStartCoordsFV = m_coordsdata.m_uiCoordSize - 3; + +} + +//######################################################################################################################*/ +void HXWMarkupTessellation::BeginFaceViewAlwaysOnTop(A3DDouble* pOrigin) +{ + add_code(A3D_ENCODE_EXTRA_DATA(kA3DMarkupFaceViewMask, 0)); + m_data.m_cBehaviour |= kA3DMarkupIsOnTop; + add_code(3); + add_coords(pOrigin, 3); + + m_uiStartSizeWireFV = m_data.m_uiCodesSize - 2; + m_uiStartCoordsFV = m_coordsdata.m_uiCoordSize - 3; + +} + +//######################################################################################################################*/ +void HXWMarkupTessellation::EndFaceView() +{ + add_code(A3D_ENCODE_EXTRA_DATA(kA3DMarkupFaceViewMask, 0)); + add_code(0); // start of coords in tessellation array + + // definition de la taille du mode + m_data.m_puiCodes[m_uiStartSizeWireFV] += m_data.m_uiCodesSize - m_uiStartSizeWireFV - 2; + m_data.m_puiCodes[m_uiStartSizeWireFV+1] = m_coordsdata.m_uiCoordSize - m_uiStartCoordsFV; +} + +//######################################################################################################################*/ +void HXWMarkupTessellation::BeginFrameDraw(A3DDouble* pOrigin) +{ + add_code(A3D_ENCODE_EXTRA_DATA(kA3DMarkupFrameDrawMask, 15)); + add_code(3); + add_coords(pOrigin, 3); + m_uiStartSizeWireFS = m_data.m_uiCodesSize - 2; + m_uiStartCoordsFS = m_coordsdata.m_uiCoordSize - 3; +} + +//######################################################################################################################*/ +void HXWMarkupTessellation::EndFrameDraw() +{ + add_code(A3D_ENCODE_EXTRA_DATA(kA3DMarkupFrameDrawMask, 0)); + add_code(0); + m_data.m_puiCodes[m_uiStartSizeWireFS] += m_data.m_uiCodesSize - m_uiStartSizeWireFS - 2; + m_data.m_puiCodes[m_uiStartSizeWireFS+1] = m_coordsdata.m_uiCoordSize - m_uiStartCoordsFS; +} diff --git a/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWMarkupTessellation.h b/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWMarkupTessellation.h new file mode 100644 index 0000000..ad61330 --- /dev/null +++ b/exchange/exchangesource/CreatePRCCubes/tessellation_wrapper/HXWMarkupTessellation.h @@ -0,0 +1,161 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file wrapper/HXWMarkupTessellation.h + +Header file for the wrapper Tessellation module. + +***********************************************************************************************************************/ + +#include "HXWBasicTessellation.h" + +/*! +\defgroup wrapper_markuptessellation_module Markup tessellation Module +\ingroup wrapper_tessellation_module +Entity type is \ref HXWMarkupTessellation. +*/ + +/*! \class HXWMarkupTessellation HXWMarkupTessellation.h "HXWMarkupTessellation.h" +* \brief This is a markup tessellation builder. +* \ingroup wrapper_markuptessellation_module +*/ +class HXWMarkupTessellation : public HXWBasicTessellation +{ +private: + A3DFontKeyData m_sFontKeyData; + A3DTessMarkupData m_data; /*!< markup tessellation data */ + A3DUns32 m_uiAllocatedTexts; /*!< size of allocated texts */ + A3DUns32 m_uiAllocatedCodes; /*!< size of allocated codes */ + A3DUns32 m_uiStartSizeWireFD; + A3DUns32 m_uiStartCoordsFD; + A3DUns32 m_uiStartSizeWireFV; + A3DUns32 m_uiStartCoordsFV; + A3DUns32 m_uiStartSizeWireFS; + A3DUns32 m_uiStartCoordsFS; + + +public: + HXWMarkupTessellation(); + virtual ~HXWMarkupTessellation(); + +private: + + void free_extra_codes(); /*!< to manage extra allocation */ + + void add_code(A3DUns32 uiCode); /*!< add code in tessellation */ + + void reset(); /*!< reset tessellation data */ + +public: + + /*! set markup label + \param pcLabel label. */ + inline void setlabel(A3DUTF8Char* pcLabel); + + /*! set RGB color + \param dRed [0..1] red value. + \param dGreen [0..1] green value. + \param dBlue [0..1] blue value. */ + int set_color(A3DDouble dRed, A3DDouble dGreen, A3DDouble dBlue); + + /*! set color + \param uiIndexColor color index in global data */ + int set_color(A3DUns32 uiIndexColor); + + /*! set font information + \param pcFamilyName Font family name. + \param uiSize Font size. Must be set to 10. + \param cAttributes Font attributes. See \ref a3d_fontattribdef. + \param m_eCharset Font character set. */ + int set_textfont(const A3DUTF8Char* pcFamilyName, A3DUns32 uiSize = 10, A3DInt8 cAttributes = 0, + A3DECharSet m_eCharset = kA3DCharsetRoman); + + /*! set font information using current preferences */ + //int add_current_textfont(); + + /*! set matrix + \param matrix array of 16 doubles */ + void begin_matrix(A3DDouble* matrix); + + /*! set matrix using 3 vector + \param position_3d is the orgin + \param plane_normal is the plane normal. Must be a unit vector + \param x_direction is the x_direction; Must be a unit vector + */ + void begin_matrix(const A3DVector3dData& position_3d, const A3DVector3dData& plane_normal, + const A3DVector3dData& x_direction); + + void end_matrix(); + + /*! define a polyline in tessellation + \param ppoints array of 3xN doubles to define points of polyline. + \param uPtSize number of points (N). */ + void add_polyline(A3DDouble* ppoints, A3DUns32 uPtSize); + + void add_polygon(A3DDouble* ppoints, A3DUns32 uPtSize); + + /*! define add triangle tessellation + \param pptriangles array of 3x3xN doubles to define triangle points. */ + void add_triangle(A3DDouble* pptriangles); + + /*! define add triangle tessellation + \param pptriangles array of 3x3xN doubles to define triangle points. + \param uTriangleSize number of triangles (N). */ + void add_triangles(A3DDouble* pptriangles, A3DUns32 uTriangleSize); + + /*! define add polygon tessellation + \param ppolygons array of 3xN doubles to define polygon points. + \param uPolygonSize number of points (N). */ + void add_polygons(A3DDouble* ppolygons, A3DUns32 uPolygonSize); + + /*! define add ellipse tesselation + \param width on current X axe + \param height on current Y axe*/ + void add_ellipse(A3DDouble dWidth, A3DDouble dHeight); + void add_ellipseFrame(A3DDouble dWidth, A3DDouble dHeight); + + /*! define add rect tesselation + \param width on current X axe + \param height on current Y axe*/ + void add_rect(A3DDouble dWidth, A3DDouble dHeight); + void add_rectFrame(A3DDouble dWidth, A3DDouble dHeight); + + /*! define text in tessellation. Use add matrix to position the text + \param pcText text to add. + \param dWidth text width. + \param dHeight text height. */ + void add_text(const A3DUTF8Char* pcText, A3DDouble dWidth, A3DDouble dHeight); + //, A3DDouble dWidth = 100.0, A3DDouble dHeight = 10.0); + /*! define text in tessellation. Use add matrix to position the text. + The width and height are automatically calculated from the string specified. + \param pcText text to add. + \param dHeight text height. */ + void add_text(const A3DUTF8Char* pcText); + + //void set_line_width(double dWidth); + //void end_line_width(); + + /*! define Start the Face View Mode (parralele / Billboard mode). Once Activated, The global coordinate system origin change becoming the Face Mode Origin. + \param pOrigin 3D point*/ + void BeginFaceView(A3DDouble* pOrigin); + void BeginFaceViewAlwaysOnTop(A3DDouble* pOrigin); + void EndFaceView(); + + /*! define Start the non Zoomable Mode + \param pOrigin 3D point*/ + void BeginFrameDraw(A3DDouble* pOrigin); + void EndFrameDraw(); + + + void GetMarkupTess(A3DTessMarkup*& pTessMarkup); + + virtual A3DEntity* GetEntity(); +}; diff --git a/exchange/exchangesource/DrawingViewer/DrawingViewer.vcxproj b/exchange/exchangesource/DrawingViewer/DrawingViewer.vcxproj new file mode 100644 index 0000000..0cf22e9 --- /dev/null +++ b/exchange/exchangesource/DrawingViewer/DrawingViewer.vcxproj @@ -0,0 +1,214 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {0C9C33A6-D497-45A8-A74D-95E794C3AF78} + A3DPRCDrawingViewerGL + Win32Proj + 10.0 + + + + Application + v145 + false + true + + + Application + v145 + false + + + Application + v145 + false + true + + + Application + v145 + false + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + ..\Viewer\glut\include;..\Viewer;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + Sync + EnableFastChecks + MultiThreadedDebugDLL + true + false + + Level4 + ProgramDatabase + 4505;%(DisableSpecificWarnings) + false + + + glut32.lib;legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + LinkVerboseLib + $(OutDir)$(ProjectName).exe + ..\Viewer\glut\lib;%(AdditionalLibraryDirectories) + true + Console + false + + MachineX86 + + + if $(SolutionName) equ exchange copy /y ..\Viewer\glut\dll\glut32.dll .\$(Platform)\$(Configuration)\ + + + + + X64 + + + Disabled + ..\Viewer\glut\include;..\Viewer;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + Sync + EnableFastChecks + MultiThreadedDebugDLL + true + false + + Level4 + ProgramDatabase + 4505;%(DisableSpecificWarnings) + false + + + glut64.lib;legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + LinkVerboseLib + $(OutDir)$(ProjectName).exe + ..\Viewer\glut\lib;%(AdditionalLibraryDirectories) + true + Console + false + + MachineX64 + + + if $(SolutionName) equ exchange copy /y ..\Viewer\glut\dll\glut64.dll .\$(Platform)\$(Configuration)\ + + + + + ..\Viewer\glut\include;..\Viewer;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level4 + ProgramDatabase + 4505;%(DisableSpecificWarnings) + false + + + glut32.lib;legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + $(OutDir)$(ProjectName).exe + ..\Viewer\glut\lib;%(AdditionalLibraryDirectories) + false + Console + true + true + false + + MachineX86 + + + if $(SolutionName) equ exchange copy /y ..\Viewer\glut\dll\glut32.dll .\$(Platform)\$(Configuration)\ + + + + + X64 + + + ..\Viewer\glut\include;..\Viewer;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level4 + ProgramDatabase + 4505;%(DisableSpecificWarnings) + false + + + glut64.lib;legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + $(OutDir)$(ProjectName).exe + ..\Viewer\glut\lib;%(AdditionalLibraryDirectories) + false + Console + true + true + false + + MachineX64 + + + if $(SolutionName) equ exchange copy /y ..\Viewer\glut\dll\glut64.dll .\$(Platform)\$(Configuration)\ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/DrawingViewer/DrawingViewer.vcxproj.filters b/exchange/exchangesource/DrawingViewer/DrawingViewer.vcxproj.filters new file mode 100644 index 0000000..16db07a --- /dev/null +++ b/exchange/exchangesource/DrawingViewer/DrawingViewer.vcxproj.filters @@ -0,0 +1,57 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {4926d425-3139-4fe4-8496-5b3d2825b658} + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {8add5ea3-1594-44e8-986b-a7e276db34a7} + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files\Viewer + + + Source Files\Viewer + + + Source Files\Viewer + + + + + Header Files + + + Header Files + + + Header Files\Viewer + + + \ No newline at end of file diff --git a/exchange/exchangesource/DrawingViewer/callback_opengl.cpp b/exchange/exchangesource/DrawingViewer/callback_opengl.cpp new file mode 100644 index 0000000..55aaa4b --- /dev/null +++ b/exchange/exchangesource/DrawingViewer/callback_opengl.cpp @@ -0,0 +1,1260 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file callback_opengl.cpp + +This file demonstrates how to programmatically visualize a PRC file from a basic OpenGL program using HOOPS Exchange. + +***********************************************************************************************************************/ + +#include +#include "callback_opengl.h" + +#if !defined _MSC_VER && !defined CALLBACK +#define CALLBACK +#endif + +#define _USE_MATH_DEFINES +#include +#include + +#define IS_EQUAL(A, B) (fabs(A-B) < 1e-12 * (1 + (fabs(A) > fabs(B) ? fabs(A) : fabs(B)))) + + + +//###################################################################################################################### +static int stiDisplayTriangles = 1; +static int stiDisplayTriangleNormals = 0; +static double stdDisplayTriangleNormalLength = 1; + +//###################################################################################################################### +int& DisplayTriangles() { return stiDisplayTriangles; } + +//###################################################################################################################### +int& DisplayTriangleNormals() { return stiDisplayTriangleNormals; } + +//###################################################################################################################### +double& DisplayTriangleNormalLength() { return stdDisplayTriangleNormalLength; } + +//###################################################################################################################### +A3DStatus DrawInitCallbacks(A3DDrawCallbacksData* psCallbacks); + +//###################################################################################################################### +static double stDeterminant4x4(double const m[16]) +{ + return m[12]*m[9]*m[6]*m[3] - m[8]*m[13]*m[6]*m[3] - m[12]*m[5]*m[10]*m[3] + m[4]*m[13]*m[10]*m[3] + + m[8]*m[5]*m[14]*m[3] - m[4]*m[9]*m[14]*m[3] - m[12]*m[9]*m[2]*m[7] + m[8]*m[13]*m[2]*m[7] + + m[12]*m[1]*m[10]*m[7] - m[0]*m[13]*m[10]*m[7] - m[8]*m[1]*m[14]*m[7] + m[0]*m[9]*m[14]*m[7] + + m[12]*m[5]*m[2]*m[11] - m[4]*m[13]*m[2]*m[11] - m[12]*m[1]*m[6]*m[11] + m[0]*m[13]*m[6]*m[11] + + m[4]*m[1]*m[14]*m[11] - m[0]*m[5]*m[14]*m[11] - m[8]*m[5]*m[2]*m[15] + m[4]*m[9]*m[2]*m[15] + + m[8]*m[1]*m[6]*m[15] - m[0]*m[9]*m[6]*m[15] - m[4]*m[1]*m[10]*m[15] + m[0]*m[5]*m[10]*m[15]; +} + +//###################################################################################################################### +static bool stGenerateInverseMatrix4x4(const double m[16], double r[16]) +{ + double d = stDeterminant4x4(m); + if(d == 0.) + return false; + + r[0] = (-m[13]*m[10]*m[7] +m[9]*m[14]*m[7] +m[13]*m[6]*m[11]-m[5]*m[14]*m[11] -m[9]*m[6]*m[15] +m[5]*m[10]*m[15])/d; + r[4] = (m[12]*m[10]*m[7] -m[8]*m[14]*m[7] -m[12]*m[6]*m[11]+m[4]*m[14]*m[11] +m[8]*m[6]*m[15] -m[4]*m[10]*m[15])/d; + r[8] = (-m[12]*m[9]*m[7] +m[8]*m[13]*m[7] +m[12]*m[5]*m[11]-m[4]*m[13]*m[11] -m[8]*m[5]*m[15] +m[4]*m[9]* m[15])/d; + r[12] = (m[12]*m[9]*m[6] -m[8]*m[13]*m[6] -m[12]*m[5]*m[10]+m[4]*m[13]*m[10] +m[8]*m[5]*m[14] -m[4]*m[9]* m[14])/d; + r[1] = (m[13]*m[10]*m[3] -m[9]*m[14]*m[3] -m[13]*m[2]*m[11]+m[1]*m[14]*m[11] +m[9]*m[2]*m[15] -m[1]*m[10]*m[15])/d; + r[5] = (-m[12]*m[10]*m[3] +m[8]*m[14]*m[3] +m[12]*m[2]*m[11]-m[0]*m[14]*m[11] -m[8]*m[2]*m[15] +m[0]*m[10]*m[15])/d; + r[9] = (m[12]*m[9]*m[3] -m[8]*m[13]*m[3] -m[12]*m[1]*m[11]+m[0]*m[13]*m[11] +m[8]*m[1]*m[15] -m[0]*m[9]* m[15])/d; + r[13] = (-m[12]*m[9]*m[2] +m[8]*m[13]*m[2] +m[12]*m[1]*m[10]-m[0]*m[13]*m[10] -m[8]*m[1]*m[14] +m[0]*m[9]*m[14])/d; + r[2] = (-m[13]*m[6]*m[3] +m[5]*m[14]*m[3] +m[13]*m[2]*m[7]-m[1]*m[14]*m[7] -m[5]*m[2]*m[15] +m[1]*m[6]*m[15])/d; + r[6] = (m[12]*m[6]*m[3] -m[4]*m[14]*m[3] -m[12]*m[2]*m[7]+m[0]*m[14]*m[7] +m[4]*m[2]*m[15] -m[0]*m[6]*m[15])/d; + r[10] = (-m[12]*m[5]*m[3] +m[4]*m[13]*m[3] +m[12]*m[1]*m[7]-m[0]*m[13]*m[7] -m[4]*m[1]*m[15] +m[0]*m[5]*m[15])/d; + r[14] = (m[12]*m[5]*m[2] -m[4]*m[13]*m[2] -m[12]*m[1]*m[6]+m[0]*m[13]*m[6] +m[4]*m[1]*m[14] -m[0]*m[5]*m[14])/d; + r[3] = (m[9]*m[6]*m[3] -m[5]*m[10]*m[3] -m[9]*m[2]*m[7]+m[1]*m[10]*m[7] +m[5]*m[2]*m[11] -m[1]*m[6]*m[11])/d; + r[7] = (-m[8]*m[6]*m[3] +m[4]*m[10]*m[3] +m[8]*m[2]*m[7]-m[0]*m[10]*m[7] -m[4]*m[2]*m[11] +m[0]*m[6]*m[11])/d; + r[11] = (m[8]*m[5]*m[3] -m[4]*m[9]*m[3] -m[8]*m[1]*m[7]+m[0]*m[9]*m[7] +m[4]*m[1]*m[11] -m[0]*m[5]*m[11])/d; + r[15] = (-m[8]*m[5]*m[2] +m[4]*m[9]*m[2] +m[8]*m[1]*m[6]-m[0]*m[9]*m[6] -m[4]*m[1]*m[10] +m[0]*m[5]*m[10])/d; + + return true; +} + +//###################################################################################################################### +static void stTranfoPt(A3DDouble adMatrix[16], A3DDouble* adPt) +{ + A3DDouble adTmp[4]; + adTmp[0] = adPt[0] * adMatrix[0] + adPt[1] * adMatrix[4] + adPt[2] * adMatrix[8] + adMatrix[12]; + adTmp[1] = adPt[0] * adMatrix[1] + adPt[1] * adMatrix[5] + adPt[2] * adMatrix[9] + adMatrix[13]; + adTmp[2] = adPt[0] * adMatrix[2] + adPt[1] * adMatrix[6] + adPt[2] * adMatrix[10] + adMatrix[14]; + adTmp[3] = 1. * adMatrix[3] + 1. * adMatrix[7] + 1. * adMatrix[11] + adMatrix[15]; + adTmp[0] /= adTmp[3]; + adTmp[1] /= adTmp[3]; + adTmp[2] /= adTmp[3]; + + memcpy(adPt, adTmp, 3*sizeof(A3DDouble)); +} + +//###################################################################################################################### +void OpenGL_PushMatrix() +{ + glPushMatrix(); + +} + +//###################################################################################################################### +void OpenGL_PopMatrix() +{ + glPopMatrix(); +} + +//###################################################################################################################### +void OpenGL_MultMatrix(const A3DDouble adMatrix[16]) +{ + glMultMatrixd(adMatrix); +} + +//###################################################################################################################### +void OpenGL_GetMatrix(A3DDouble adMatrix[16]) +{ + glGetDoublev(GL_MODELVIEW_MATRIX, adMatrix); +} + +//###################################################################################################################### +static void stOpenGL_TreatColorIndex(A3DUns32 uiRgbColorIndex, A3DBool* pbPush) +{ + if(uiRgbColorIndex != A3D_DEFAULT_COLOR_INDEX) + { + if(pbPush != NULL) + { + OpenGL_BeginMaterial(); + *pbPush = TRUE; + } + + A3DGraphRgbColorData sRgbColorData; + A3D_INITIALIZE_DATA(A3DGraphRgbColorData, sRgbColorData); + if(A3DGlobalGetGraphRgbColorData(uiRgbColorIndex,&sRgbColorData) == A3D_SUCCESS) + { + A3DDouble adColor[3] = { sRgbColorData.m_dRed, sRgbColorData.m_dGreen, sRgbColorData.m_dBlue }; + OpenGL_Material(kA3DDrawMaterialDiffuse, adColor, 3); + } + + A3DGlobalGetGraphRgbColorData(A3D_DEFAULT_COLOR_INDEX, &sRgbColorData); + } + else if(pbPush != NULL) + *pbPush = FALSE; +} + +//###################################################################################################################### +static void stOpenGL_TreatLinePattern(A3DUns32 uiLinePatternIndex) +{ + if(uiLinePatternIndex != A3D_DEFAULT_LINEPATTERN_INDEX) + { + A3DGraphLinePatternData sPatternData; + A3D_INITIALIZE_DATA(A3DGraphLinePatternData, sPatternData); + if(A3DGlobalGetGraphLinePatternData(uiLinePatternIndex,&sPatternData) == A3D_SUCCESS) + { + glEnable(GL_LINE_STIPPLE); + + A3DDouble dLength = 0.; + A3DUns32 i, j, p = 0; + for(i=0; i < sPatternData.m_uiNumberOfLengths; ++i) + { + dLength += sPatternData.m_pdLengths[i]; + } + + //std::vector asByte; + unsigned short usLineStipple = 0; + for(i=0; i < sPatternData.m_uiNumberOfLengths; ++i) + { + A3DUns8 ucValue = (A3DUns8) floor(sPatternData.m_pdLengths[i]*16/dLength + 0.5); + if(!(i%2)) + { + for(j=0;jm_dX, pasNormals->m_dY, pasNormals->m_dZ); + for(A3DUns32 ui = 0; ui < uiPointSize; ++ui) + glVertex3d(pasPoints[ui].m_dX, pasPoints[ui].m_dY, pasPoints[ui].m_dZ); + glEnd(); + } + + glStartLineDrawing(); + for(A3DUns32 ui = 0; ui < uiPointSize/3; ++ui) + { + glTriangleAndNormalDisplay(pasPoints [ui*3 ],pasPoints [ui*3+1],pasPoints [ui*3+2], pasNormals[0], + pasNormals[0], pasNormals[0], true); + } + glEndLineDrawing(); +} + +//###################################################################################################################### +void OpenGL_TriangleFanOneNormal(const A3DVector3dData* psNormal, const A3DVector3dData* pasPoints, + A3DUns32 uiPointSize) +{ + if(stiDisplayTriangles&1) + { + glBegin(GL_TRIANGLE_FAN); + glNormal3d(psNormal->m_dX, psNormal->m_dY, psNormal->m_dZ); + for(A3DUns32 ui = 0; ui < uiPointSize; ++ui) + { + glVertex3d(pasPoints[ui].m_dX, pasPoints[ui].m_dY, pasPoints[ui].m_dZ); + } + glEnd(); + } + + glStartLineDrawing(); + for(A3DUns32 ui = 2; ui < uiPointSize; ++ui) + { + glTriangleAndNormalDisplay(pasPoints[ui-1], pasPoints[ui], pasPoints[0], psNormal[0], psNormal[0], psNormal[0], + true); + } + glEndLineDrawing(); +} + +//###################################################################################################################### +void OpenGL_TriangleStripeOneNormal(const A3DVector3dData* psNormal, const A3DVector3dData* pasPoints, + A3DUns32 uiPointSize) +{ + if(stiDisplayTriangles&1) + { + glBegin(GL_TRIANGLE_STRIP); + glNormal3d(psNormal->m_dX, psNormal->m_dY, psNormal->m_dZ); + for(A3DUns32 ui = 0; ui < uiPointSize; ++ui) + { + glVertex3d(pasPoints[ui].m_dX, pasPoints[ui].m_dY, pasPoints[ui].m_dZ); + } + glEnd(); + } + + glStartLineDrawing(); + for(A3DUns32 ui = 2; ui < uiPointSize; ++ui) + { + if(ui%2 == 0) + { + glTriangleAndNormalDisplay(pasPoints[ui-2], pasPoints[ui-1], pasPoints[ui], psNormal[0], psNormal[0], + psNormal[0]); + } + else + { + glTriangleAndNormalDisplay(pasPoints[ui-1], pasPoints[ui-2], pasPoints[ui], psNormal[0], psNormal[0], + psNormal[0]); + } + } + glEndLineDrawing(); +} + +//###################################################################################################################### +void OpenGL_TriangleTextured(const A3DVector3dData* pasNormals, const A3DVector3dData* pasPoints, A3DUns32 uiPointSize) +{ + OpenGL_Triangle(pasNormals, pasPoints, uiPointSize); +} + +//###################################################################################################################### +void OpenGL_TriangleFanTextured(const A3DVector3dData* pasNormals, const A3DVector3dData* pasPoints, + A3DUns32 uiPointSize) +{ + OpenGL_TriangleFan(pasNormals, pasPoints, uiPointSize); +} + +//###################################################################################################################### +void OpenGL_TriangleStripeTextured(const A3DVector3dData* pasNormals, const A3DVector3dData* pasPoints, + A3DUns32 uiPointSize) +{ + OpenGL_TriangleStripe(pasNormals, pasPoints, uiPointSize); +} + +//###################################################################################################################### +void OpenGL_TriangleOneNormalTextured(const A3DVector3dData* pasNormals, const A3DVector3dData* pasPoints, + A3DUns32 uiPointSize) +{ + OpenGL_TriangleOneNormal(pasNormals, pasPoints, uiPointSize); +} + +//###################################################################################################################### +void OpenGL_TriangleFanOneNormalTextured(const A3DVector3dData* psNormal, const A3DVector3dData* pasPoints, + A3DUns32 uiPointSize) +{ + OpenGL_TriangleFanOneNormal(psNormal, pasPoints, uiPointSize); +} + +//###################################################################################################################### +void OpenGL_TriangleStripeOneNormalTextured(const A3DVector3dData* psNormal, const A3DVector3dData* pasPoints, + A3DUns32 uiPointSize) +{ + OpenGL_TriangleStripeOneNormal(psNormal, pasPoints, uiPointSize); +} + +//###################################################################################################################### +void OpenGL_Color(const A3DDouble adValues[3]) +{ + GLfloat afValues[3] = { static_cast(adValues[0]), static_cast(adValues[1]), static_cast(adValues[2]) }; + glColor3fv(afValues); + +} + +//###################################################################################################################### +void OpenGL_Material(A3DEDrawMaterialType eType, const A3DDouble* pdValues, A3DUns32 uiSize) +{ + if(uiSize == 1 && eType == kA3DDrawMaterialShininess) + { + GLfloat afValues[] = { static_cast(pdValues[0]) }; + glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, afValues); + } + else + { + GLfloat afValues[4] = { static_cast(pdValues[0]), static_cast(pdValues[1]), static_cast(pdValues[2]), static_cast((uiSize == 4) ? pdValues[3] : 1) }; + + GLenum glMaterialType = GL_AMBIENT; + switch(eType) + { + case kA3DDrawMaterialDiffuse: glMaterialType = GL_DIFFUSE; break; + case kA3DDrawMaterialAmbient: glMaterialType = GL_AMBIENT; break; + case kA3DDrawMaterialEmission: glMaterialType = GL_EMISSION; break; + case kA3DDrawMaterialShininess: return; + default: + break; + } + + glMaterialfv(GL_FRONT_AND_BACK, glMaterialType, afValues); + } +} + +//###################################################################################################################### +void OpenGL_BeginMaterial(void) +{ + glPushAttrib(GL_LIGHTING_BIT | GL_CURRENT_BIT); +} + +//###################################################################################################################### +void OpenGL_EndMaterial(void) +{ + glPopAttrib(); +} + +//###################################################################################################################### +void OpenGL_GetDrawContext(A3DDouble /*adProjection*/[16], A3DDouble /*adModelView*/[16], A3DInt32 /*aiViewport*/[4]) +{ +} + +//###################################################################################################################### +void OpenGL_MarkupTriangle(const A3DDouble* pdPoints, A3DUns32 uiPointSize) +{ + const A3DDouble* pdData = &pdPoints[0]; + glBegin(GL_TRIANGLES); + for(A3DUns32 ui = 0; ui < uiPointSize/3; ++ui) + { + glVertex3dv(pdData); + pdData += 3; + glVertex3dv(pdData); + pdData += 3; + glVertex3dv(pdData); + pdData += 3; + } + glEnd(); +} + +//###################################################################################################################### +void OpenGL_UnProject(const A3DVector3dData* psPoint, A3DVector3dData* psResult) +{ + double adProjection[16], adModelView[16]; + int aiViewport[4]; + glGetDoublev(GL_MODELVIEW_MATRIX, adModelView); + glGetDoublev(GL_PROJECTION_MATRIX, adProjection); + glGetIntegerv(GL_VIEWPORT, aiViewport); + gluUnProject(psPoint->m_dX, psPoint->m_dY, psPoint->m_dZ, adModelView, adProjection, aiViewport, + &psResult->m_dX, &psResult->m_dY, &psResult->m_dZ); +} + +//###################################################################################################################### +void OpenGL_BeginFrameDraw(const A3DVector3dData* psPoint3d, A3DBool bIsZoomable, A3DDouble dFixedSize) +{ + double adProjection[16], adModelView[16]; + int aiViewport[4]; + glGetDoublev(GL_MODELVIEW_MATRIX, adModelView); + glGetDoublev(GL_PROJECTION_MATRIX, adProjection); + glGetIntegerv(GL_VIEWPORT, aiViewport); + double dXProj, dYProj, dZProj; + gluProject(psPoint3d->m_dX, psPoint3d->m_dY, psPoint3d->m_dZ, adModelView, adProjection, aiViewport, + &dXProj, &dYProj, &dZProj); + + glPushAttrib(GL_TRANSFORM_BIT | GL_VIEWPORT_BIT); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluOrtho2D(0.0, aiViewport[2], 0.0, aiViewport[3]); + + glTranslated(dXProj, dYProj, 0.0); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + if(bIsZoomable) + glScaled(1.0/dFixedSize, 1.0/dFixedSize, 1.0/dFixedSize); +} + +//###################################################################################################################### +void OpenGL_EndFrameDraw(void) +{ + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + + glPopAttrib(); +} + +//###################################################################################################################### +static double stGetFixedSize(double dPX, double dPY, double dPZ) +{ + double adMv[16], adPj[16]; + int aiVp[4]; + glGetDoublev(GL_MODELVIEW_MATRIX, adMv); + glGetDoublev(GL_PROJECTION_MATRIX, adPj); + glGetIntegerv(GL_VIEWPORT, aiVp); + + double xProj, yProj, zProj; + gluProject(dPX, dPY, dPZ, adMv, adPj, aiVp, &xProj, &yProj, &zProj); + + double x0, y0, z0; + double x1, y1, z1; + gluUnProject(aiVp[0], aiVp[2], zProj, adMv, adPj, aiVp, &x0, &y0, &z0); + gluUnProject(aiVp[1], aiVp[3], zProj, adMv, adPj, aiVp, &x1, &y1, &z1); + + double dL = sqrt((x1-x0) * (x1-x0) + (y1-y0) * (y1-y0) + (z1-z0) * (z1-z0)); + + double dD = dL/500.0; + + return dD; +} + +//###################################################################################################################### +void OpenGL_BeginFixedSize(const A3DVector3dData* psPoint3d) +{ +#define SIZE_ARROW 15.0 + double dFixedSize = stGetFixedSize(psPoint3d->m_dX, psPoint3d->m_dY, psPoint3d->m_dZ); + double dFixedSizeArrow = dFixedSize * SIZE_ARROW; + glPushMatrix(); + glTranslated(psPoint3d->m_dX, psPoint3d->m_dY, psPoint3d->m_dZ); + glScaled(dFixedSizeArrow, dFixedSizeArrow, dFixedSizeArrow); +} + +//###################################################################################################################### +void OpenGL_EndFixedSize(void) +{ + glPopMatrix(); +} + +//###################################################################################################################### +void OpenGL_Cylinder(A3DDouble dBaseRadius, A3DDouble dTopRadius, A3DDouble dHeight) +{ + GLUquadricObj* qCylinder = gluNewQuadric(); + gluQuadricDrawStyle(qCylinder, GLU_FILL); + gluCylinder(qCylinder, dBaseRadius, dTopRadius, dHeight, 8, 8); + gluDeleteQuadric(qCylinder); +} + +//###################################################################################################################### +void OpenGL_Polygon(const A3DDouble* pdPoints, A3DUns32 uiPointSize) +{ + const A3DDouble* pdData = &pdPoints[0]; + glBegin(GL_POLYGON); + for(A3DUns32 ui = 0; ui < uiPointSize; ++ui) + { + glVertex3dv(pdData); + pdData += 3; + } + glEnd(); +} + +//###################################################################################################################### +void OpenGL_BeginLineWidth(A3DDouble dWidth) +{ + glPushAttrib(GL_LINE_BIT); + glLineWidth((GLfloat)dWidth); +} + +//###################################################################################################################### +void OpenGL_EndLineWidth(void) +{ + glPopAttrib(); +} + +//###################################################################################################################### +void OpenGL_Point(const A3DDouble* pdPoints, A3DUns32 uiPointSize) +{ + const A3DDouble* pdData = &pdPoints[0]; + glBegin(GL_POINTS); + for(A3DUns32 ui = 0; ui < uiPointSize; ++ui) + { + glVertex3dv(pdData); + pdData += 3; + } + glEnd(); +} + + +//###################################################################################################################### +void OpenGL_Font(const A3DFontKeyData* /* psFontKeyData */) +{ +} + +//###################################################################################################################### +void OpenGL_BeginLineStipple(const A3DGraphStyleData* psGraphStyleData ) +{ + glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT); + glEnable(GL_LINE_STIPPLE); + if(!psGraphStyleData->m_bVPicture) + { + stOpenGL_TreatLinePattern(psGraphStyleData->m_uiLinePatternIndex); + } + +} + +//###################################################################################################################### +void OpenGL_EndLineStipple(void) +{ + glDisable(GL_LINE_STIPPLE); + glPopAttrib(); +} + +//###################################################################################################################### +void OpenGL_Symbol(const A3DGraphVPicturePatternData* /* psPatternData */, const A3DVector3dData* /* psPosition */) +{ +} + +//###################################################################################################################### +void OpenGL_PolyLine(const A3DDouble* pdPoints, A3DUns32 uiPointSize) +{ + const A3DDouble* pdData = &pdPoints[0]; + glBegin(GL_LINE_STRIP); + for(A3DUns32 ui = 0; ui < uiPointSize; ++ui) + { + glVertex3dv(pdData); + pdData += 3; + } + glEnd(); +} + +//###################################################################################################################### +void OpenGL_Text(const A3DUTF8Char* /* pcBuffer */, A3DDouble dWidth, A3DDouble dHeight) +{ + // Draw only frame text + if(dWidth > 0.0) + { + glBegin(GL_LINE_STRIP); + glVertex2f(0.0f, 0.0f); + glVertex2f((GLfloat) dWidth, 0.0f); + glVertex2f((GLfloat) dWidth, (GLfloat) dHeight); + glVertex2f(0.0f, (GLfloat) dHeight); + glVertex2f(0.0f, 0.0f); + glEnd(); + } +} + +//###################################################################################################################### +static void stOpenGL_Pattern_Start(A3DUns32 uiLoopsSize, const A3DDouble* pdPoints, const A3DUns32* puiLoopsPointSize, + A3DDouble* adMin, A3DDouble* adMax) +{ + adMin[0] = adMin[1] = adMin[2] = DBL_MAX; + adMax[0] = adMax[1] = adMax[2] = -DBL_MAX; + + glPushAttrib(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT); + glEnable(GL_STENCIL_TEST); + glClearStencil(~2); + glClear(GL_STENCIL_BUFFER_BIT); + glStencilMask(2); + + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + glDisable(GL_DEPTH_TEST); + glStencilFunc(GL_NOTEQUAL, 0x2, 0x2); + glStencilOp(GL_ZERO, GL_REPLACE, GL_REPLACE); + + // Clipping + glDisable(GL_CULL_FACE); + A3DDouble const* psCurPt = pdPoints; + A3DUns32 uiLoop; + for(uiLoop = 0; uiLoop < uiLoopsSize; ++uiLoop) + { + A3DUns32 uiPt, uiNbPt = puiLoopsPointSize[uiLoop]; + if(uiNbPt > 0) + { + GLUtesselator* tobj = gluNewTess(); + gluTessCallback(tobj, GLU_TESS_BEGIN, (void (CALLBACK*) ()) glBegin); + gluTessCallback(tobj, GLU_TESS_VERTEX, (void (CALLBACK*) ()) glVertex3dv); + gluTessCallback(tobj, GLU_TESS_END, (void (CALLBACK*) ()) glEnd); + + gluTessEndPolygon(tobj); + gluTessBeginContour(tobj); + for(uiPt = 0; uiPt < uiNbPt; uiPt++, psCurPt += 3) + { + gluTessVertex(tobj, (GLdouble*) psCurPt, (void*) psCurPt); + + if(*psCurPt < adMin[0]) + adMin[0] = *psCurPt; + else if(*psCurPt > adMax[0]) + adMax[0] = *psCurPt; + + if(*(psCurPt+1) < adMin[1]) + adMin[1] = *(psCurPt+1); + else if(*(psCurPt+1) > adMax[1]) + adMax[1] = *(psCurPt+1); + + if(*(psCurPt+2) < adMin[2]) + adMin[2] = *(psCurPt+2); + else if(*(psCurPt+2) > adMax[2]) + adMax[2] = *(psCurPt+2); + } + gluTessEndContour(tobj); + gluTessEndPolygon(tobj); + gluDeleteTess(tobj); + } + } + + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + + glStencilFunc(GL_EQUAL, 0x3, 0x3); + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); +} + +//###################################################################################################################### +static void stOpenGL_Pattern_End() +{ + glPopAttrib(); +} + +//###################################################################################################################### +static void stOpenGL_Pattern_HatchingLine_ComputeStep(A3DGraphHatchingPatternLineData const* psData, + A3DDouble& dStepX, A3DDouble& dStepY) +{ + double dTan = tan(psData->m_dAngle); + + if(!IS_EQUAL(psData->m_dAngle, 0.) && !IS_EQUAL(psData->m_dAngle, M_PI)) + { + dStepX = psData->m_sOffset.m_dX; + if(!IS_EQUAL(fabs(psData->m_dAngle), M_PI/2)) + dStepX -= psData->m_sOffset.m_dY / dTan; + } + else + { + dStepX = 0.f; + } + + if(!IS_EQUAL(fabs(psData->m_dAngle), M_PI/2.)) + { + dStepY = psData->m_sOffset.m_dY - psData->m_sOffset.m_dX * dTan; + } + else + { + dStepY = 0.f; + } +} + +//###################################################################################################################### +static void stOpenGL_Pattern_HatchingLine_ComputeOccurrence(A3DGraphHatchingPatternLineData const* psData, + A3DDouble const* adMin, A3DDouble const* adMax, + A3DInt32& iOcLgMin, A3DInt32& iOcLgMax) +{ + A3DDouble dStepX, dStepY; + stOpenGL_Pattern_HatchingLine_ComputeStep(psData, dStepX, dStepY); + + + A3DInt32 iXMin = 0, iXMax = 0; + if(fabs(dStepX) > 1e-12) + { + iXMax = -(int) ((psData->m_sStart.m_dX - adMin[0]) / dStepX); + iXMin = -(int) ((psData->m_sStart.m_dX - adMax[0]) / dStepX); + if(iXMin > iXMax) + { + int iTmp = iXMin; + iXMin = iXMax; + iXMax = iTmp; + } + } + + A3DInt32 iYMin = 0, iYMax = 0; + if(fabs(dStepY) > 1e-12) + { + iYMax = -(int) ((psData->m_sStart.m_dY - adMin[1]) / dStepY); + iYMin = -(int) ((psData->m_sStart.m_dY - adMax[1]) / dStepY); + if(iYMin > iYMax) + { + int iTmp = iYMin; + iYMin = iYMax; + iYMax = iTmp; + } + } + + iOcLgMin = iXMin + iYMin - 1; + iOcLgMax = iXMax + iYMax + 1; +} + +//###################################################################################################################### +static void stOpenGL_Pattern_HatchingLine(A3DGraphHatchingPatternLineData* psData, A3DUns32 /*uiBehavior*/, + A3DDouble const* adMin, A3DDouble const* adMax) +{ + bool bWithStipple = false; + if(psData->m_uiStyleIndex != A3D_DEFAULT_STYLE_INDEX) + { + A3DGraphStyleData sStyleData; + A3D_INITIALIZE_DATA(A3DGraphStyleData, sStyleData); + + if(A3DGlobalGetGraphStyleData(psData->m_uiStyleIndex, &sStyleData) == A3D_SUCCESS) + { + OpenGL_BeginLineStipple(&sStyleData); + bWithStipple = true; + } + } + + A3DInt32 iOcLgMin, iOcLgMax, iOcLg; + stOpenGL_Pattern_HatchingLine_ComputeOccurrence(psData, adMin, adMax, iOcLgMin, iOcLgMax); + + double dStartX = (psData->m_sStart.m_dX + iOcLgMin * psData->m_sOffset.m_dX); + double dStartY = (psData->m_sStart.m_dY + iOcLgMin * psData->m_sOffset.m_dY); + double dCos = cos(psData->m_dAngle); + double dSin = sin(psData->m_dAngle); + double dPatMin, dPatMax; + bool bCosSupSin = fabs(dCos) > fabs(dSin); + + glBegin(GL_LINES); + for(iOcLg = iOcLgMin; iOcLg < iOcLgMax; ++iOcLg) + { + if(bCosSupSin) + { + dPatMax = (adMin[0] - dStartX) / dCos; + dPatMin = (adMax[0] - dStartX) / dCos; + } + else + { + dPatMax = (adMin[1] - dStartY) / dSin; + dPatMin = (adMax[1] - dStartY) / dSin; + } + + if(dPatMin>dPatMax) + { + double dTmp = dPatMin; + dPatMin = dPatMax; + dPatMax = dTmp; + } + + glVertex2f(dStartX + dPatMin * dCos, dStartY + dPatMin * dSin); + glVertex2f(dStartX + dPatMax * dCos, dStartY + dPatMax * dSin); + + dStartX += psData->m_sOffset.m_dX; + dStartY += psData->m_sOffset.m_dY; + } + glEnd(); + + if(bWithStipple) + { + OpenGL_EndLineStipple(); + } +} + +//###################################################################################################################### +static void stOpenGL_Pattern_Hatching(A3DUns32 uiPatternId, A3DUns32 uiBehavior, A3DDouble* adMin, A3DDouble* adMax) +{ + A3DGraphHatchingPatternData sData; + A3D_INITIALIZE_DATA(A3DGraphHatchingPatternData, sData); + + if(A3DGlobalGetGraphHatchingPatternData(uiPatternId, &sData) != A3D_SUCCESS) + { + A3DGlobalGetGraphHatchingPatternData(A3D_DEFAULT_PATTERN_INDEX, &sData); + return; + } + + A3DUns32 uiLine; + for(uiLine = 0; uiLine < sData.m_uiSize; ++uiLine) + { + stOpenGL_Pattern_HatchingLine(&sData.m_psHatchLines[uiLine], uiBehavior, adMin, adMax); + } + + + A3DGlobalGetGraphHatchingPatternData(A3D_DEFAULT_PATTERN_INDEX, &sData); +} + +//###################################################################################################################### +static void stOpenGL_Pattern_Solid(A3DUns32 uiPatternId, A3DUns32 /*uiBehavior*/, A3DDouble* adMin, A3DDouble* adMax) +{ + A3DGraphSolidPatternData sData; + A3D_INITIALIZE_DATA(A3DGraphSolidPatternData, sData); + + if(A3DGlobalGetGraphSolidPatternData(uiPatternId, &sData) != A3D_SUCCESS) + return; + + A3DBool bPush = FALSE; + + if(!sData.m_bMaterial) + { + stOpenGL_TreatColorIndex(sData.m_uiRgbColorIndex, &bPush); + } + else + { + // TODO ... + } + + glBegin(GL_QUADS); + glVertex3d(adMin[0], adMin[1], adMin[2]); + glVertex3d(adMin[0], adMax[1], adMin[2]); + glVertex3d(adMax[0], adMax[1], adMin[2]); + glVertex3d(adMax[0], adMin[1], adMin[2]); + glEnd(); + + if(bPush) + OpenGL_EndMaterial(); +} + +//###################################################################################################################### +static void stOpenGL_Pattern_Dotting(A3DUns32 uiPatternId, A3DUns32 /*uiBehavior*/, A3DDouble* adMin, A3DDouble* adMax) +{ + A3DGraphDottingPatternData sData; + A3D_INITIALIZE_DATA(A3DGraphDottingPatternData, sData); + + if(A3DGlobalGetGraphDottingPatternData(uiPatternId, &sData) != A3D_SUCCESS) + return; + + A3DBool bPush; + stOpenGL_TreatColorIndex(sData.m_uiColorIndex, &bPush); + + double dPitch = sData.m_dPitch; + + double dX, dY = adMin[1]; + double dXMax = adMax[0]; + double dYMax = adMax[1]; + + glPointSize(0.5f); + glBegin(GL_POINTS); + if(sData.m_bZigZag) + { + double dPitch2 = dPitch * 2.f; + double dXStart = adMin[0]; + + for(; dY < dYMax; dY += dPitch2) + { + for(dX = dXStart; dX < dXMax; dX += dPitch) + { + glVertex2d(dX, dY); + } + } + + dXStart += dPitch/2.; + dY = adMin[1] + dPitch; + for(; dY < dYMax; dY += dPitch2) + { + for(dX = dXStart; dX < dXMax; dX += dPitch) + { + glVertex2d(dX, dY); + } + } + } + else + { + for(; dY < dYMax; dY += dPitch) + { + dX = adMin[0]; + for(; dX +#else +#include +#endif + + +//#define USE_A3D_CALLBACKS + +#ifdef USE_A3D_CALLBACKS +#define A3DORNOTDrawGetBoundingBox A3DDrawGetBoundingBox +#define A3DORNOTDraw A3DDraw +#define A3DORNOTDrawInitCallbacks A3DDrawInitCallbacks +#else +#define A3DORNOTDrawGetBoundingBox DrawGetBoundingBox +#define A3DORNOTDraw Draw +#define A3DORNOTDrawInitCallbacks DrawInitCallbacks +#endif + +//###################################################################################################################### +A3DStatus OpenGL_SetAndInitCallBack(A3DDrawCallbacksData &sDrawCallbacksData); + +//###################################################################################################################### +void OpenGL_PushMatrix(); + +//###################################################################################################################### +void OpenGL_PopMatrix(); + +//###################################################################################################################### +void OpenGL_MultMatrix(const A3DDouble adMatrix[16]); + +//###################################################################################################################### +void OpenGL_GetMatrix(A3DDouble adMatrix[16]); + +//###################################################################################################################### +void OpenGL_SetIgnoreViewMatrix(A3DDouble adIgnoreViewMatrix[16]); + +//###################################################################################################################### +void OpenGL_Begin(A3DEDrawBeginEndType eType, const A3DUTF8Char* pcName, A3DUns32 uiTrianglesCount); + +//###################################################################################################################### +void OpenGL_End(A3DEDrawBeginEndType eType); + +//###################################################################################################################### +void OpenGL_Triangle(const A3DVector3dData* pasNormals, const A3DVector3dData* pasPoints, A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_TriangleFan(const A3DVector3dData* pasNormals, const A3DVector3dData* pasPoints, A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_TriangleStripe(const A3DVector3dData* pasNormals, const A3DVector3dData* pasPoints, A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_TriangleOneNormal(const A3DVector3dData* pasNormals, const A3DVector3dData* pasPoints, + A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_TriangleFanOneNormal(const A3DVector3dData* psNormal, const A3DVector3dData* pasPoints, + A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_TriangleStripeOneNormal(const A3DVector3dData* psNormal, const A3DVector3dData* pasPoints, + A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_TriangleTextured(const A3DVector3dData* pasNormals, const A3DVector3dData* pasPoints, A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_TriangleFanTextured(const A3DVector3dData* pasNormals, const A3DVector3dData* pasPoints, + A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_TriangleStripeTextured(const A3DVector3dData* pasNormals, const A3DVector3dData* pasPoints, + A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_TriangleOneNormalTextured(const A3DVector3dData* pasNormals, const A3DVector3dData* pasPoints, + A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_TriangleFanOneNormalTextured(const A3DVector3dData* psNormal, const A3DVector3dData* pasPoints, + A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_TriangleStripeOneNormalTextured(const A3DVector3dData* psNormal, const A3DVector3dData* pasPoints, + A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_Material(A3DEDrawMaterialType eType, const A3DDouble* pdValues, A3DUns32 uiSize); + +//###################################################################################################################### +void OpenGL_BeginMaterial(void); + +//###################################################################################################################### +void OpenGL_EndMaterial(void); + +//###################################################################################################################### +void OpenGL_GetDrawContext(A3DDouble adProjection[16], A3DDouble adModelView[16], A3DInt32 aiViewport[4]); + +//###################################################################################################################### +void OpenGL_MarkupTriangle(const A3DDouble* pdPoints, A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_UnProject(const A3DVector3dData* psPoint, A3DVector3dData* psResult); + +//###################################################################################################################### +void OpenGL_BeginFrameDraw(const A3DVector3dData* psPoint3d, A3DBool bIsZoomable, A3DDouble dFixedSize); + +//###################################################################################################################### +void OpenGL_EndFrameDraw(void); + +//###################################################################################################################### +void OpenGL_BeginFixedSize(const A3DVector3dData* psPoint3d); + +//###################################################################################################################### +void OpenGL_EndFixedSize(void); + +//###################################################################################################################### +void OpenGL_Cylinder(A3DDouble dBaseRadius, A3DDouble dTopRadius, A3DDouble dHeight); + +//###################################################################################################################### +void OpenGL_Polygon(const A3DDouble* pdPoints, A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_BeginLineWidth(A3DDouble dWidth); + +//###################################################################################################################### +void OpenGL_EndLineWidth(void); + +//###################################################################################################################### +void OpenGL_Point(const A3DDouble* pdPoints, A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_Font(const A3DFontKeyData* psFontKeyData); + +//###################################################################################################################### +void OpenGL_BeginLineStipple(const A3DGraphStyleData* psGraphStyleData); + +//###################################################################################################################### +void OpenGL_EndLineStipple(void); + +//###################################################################################################################### +void OpenGL_Symbol(const A3DGraphVPicturePatternData* psPatternData, const A3DVector3dData* psPosition); + +//###################################################################################################################### +void OpenGL_PolyLine(const A3DDouble* pdPoints, A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_Text(const A3DUTF8Char* pcBuffer, A3DDouble dWidth, A3DDouble dHeight); + +//###################################################################################################################### +void OpenGL_Pattern(A3DUns32 uiLoopsSize, A3DUns32 uiPatternId, A3DUns32 uiFilledMode, A3DUns32 uiBehavior, + const A3DDouble* pdPoints, const A3DUns32* puiLoopsPointSize); + +//###################################################################################################################### +void OpenGL_Picture(const A3DGraphPictureData* psPictureData); + +//###################################################################################################################### +void OpenGL_Color(const A3DDouble* pdValues, A3DUns32 uiSize); + +//###################################################################################################################### +int& DisplayTriangles(); + +//###################################################################################################################### +int& DisplayTriangleNormals(); + +//###################################################################################################################### +double& DisplayTriangleNormalLength(); + +#endif // _CALLBACK_OPENGL_H_ diff --git a/exchange/exchangesource/DrawingViewer/drawing_collect.cpp b/exchange/exchangesource/DrawingViewer/drawing_collect.cpp new file mode 100644 index 0000000..ed317d5 --- /dev/null +++ b/exchange/exchangesource/DrawingViewer/drawing_collect.cpp @@ -0,0 +1,138 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include + +#include + + + +//###################################################################################################################### +#define CHECK_RET(function_call) {\ + iRet = function_call; if(iRet != A3D_SUCCESS) { std::cout << "Error number=" << iRet << std::endl; return iRet; }\ +} + +//###################################################################################################################### +static A3DStatus stCollectDrawingOnPartDefinition(A3DEntity* psEntity, std::vector &apDrawingModels) +{ + // Check type of entity + A3DEEntityType eType = kA3DTypeUnknown; + A3DEntityGetType(psEntity, &eType); + if(eType != kA3DTypeAsmPartDefinition) + return A3D_INVALID_ENTITY_TYPE; + + A3DStatus iRet = A3D_SUCCESS; + + // Get data of A3DAsmPartDefinition + A3DAsmPartDefinition* pPartDefinition = (A3DAsmPartDefinition*) psEntity; + A3DAsmPartDefinitionData sPartData; + A3D_INITIALIZE_DATA(A3DAsmPartDefinitionData, sPartData); + CHECK_RET(A3DAsmPartDefinitionGet(pPartDefinition, &sPartData)); + + // Collect all DrawingModels + if(sPartData.m_uiDrawingModelsSize != 0) + { + A3DUns32 uiElem; + for(uiElem = 0; uiElem < sPartData.m_uiDrawingModelsSize; uiElem++) + { + if(sPartData.m_ppDrawingModels[uiElem] != NULL) + apDrawingModels.push_back(sPartData.m_ppDrawingModels[uiElem]); + } + } + + // Free allocated data + A3DAsmPartDefinitionGet(NULL, &sPartData); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stProductOccurrenceGetPart(A3DAsmProductOccurrenceData* psPOccData, A3DAsmPartDefinition** ppPart) +{ + if(psPOccData == NULL) + return A3D_ERROR; + + A3DStatus iRet = A3D_SUCCESS; + + *ppPart = NULL; + + if(psPOccData->m_pPart != NULL) + { + *ppPart = psPOccData->m_pPart; + return iRet; + } + + A3DAsmProductOccurrence* pProductPrototype = psPOccData->m_pPrototype; + while(pProductPrototype != NULL) + { + A3DAsmProductOccurrenceData sProductPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductPrototypeData); + CHECK_RET(A3DAsmProductOccurrenceGet(pProductPrototype, &sProductPrototypeData)); + + if(sProductPrototypeData.m_pPart != NULL) + { + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sProductPrototypeData)); + *ppPart = sProductPrototypeData.m_pPart; + return iRet; + } + else + pProductPrototype = sProductPrototypeData.m_pPrototype; + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sProductPrototypeData)); + } + return iRet; +} + +//###################################################################################################################### +static A3DStatus stParseProductOccurrence(A3DAsmProductOccurrence* pOccurrence, + std::vector &apDrawingModels) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DAsmProductOccurrenceData sData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sData); + CHECK_RET(A3DAsmProductOccurrenceGet(pOccurrence, &sData)); + + if(sData.m_ucBehaviour != 1) + { + A3DAsmPartDefinition* pPart = NULL; + stProductOccurrenceGetPart(&sData, &pPart); + + if(pPart) + CHECK_RET(stCollectDrawingOnPartDefinition(pPart, apDrawingModels)); + + unsigned int uiPO; + for(uiPO = 0; uiPO < sData.m_uiPOccurrencesSize; ++uiPO) + CHECK_RET(stParseProductOccurrence(sData.m_ppPOccurrences[uiPO], apDrawingModels)); + } + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sData)); + + return iRet; +} + +//###################################################################################################################### +A3DStatus CollectDrawing(A3DAsmModelFile* pModelFile, std::vector &apDrawingModels) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DAsmModelFileData sData; + A3D_INITIALIZE_DATA(A3DAsmModelFileData, sData); + CHECK_RET(A3DAsmModelFileGet(pModelFile, &sData)); + + for(A3DUns32 ui = 0; ui < sData.m_uiPOccurrencesSize; ++ui) + { + CHECK_RET(stParseProductOccurrence(sData.m_ppPOccurrences[ui], apDrawingModels)); + } + + CHECK_RET(A3DAsmModelFileGet(NULL, &sData)); + + return iRet; +} diff --git a/exchange/exchangesource/DrawingViewer/drawing_draw.cpp b/exchange/exchangesource/DrawingViewer/drawing_draw.cpp new file mode 100644 index 0000000..6f5762b --- /dev/null +++ b/exchange/exchangesource/DrawingViewer/drawing_draw.cpp @@ -0,0 +1,481 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "drawing_parse.h" +#include "callback_opengl.h" +#include +#include + + + +//###################################################################################################################### +typedef struct +{ + std::vector* m_paSheetDL; + std::vector* m_paSheetSize; + bool m_bDrawMarkup; +} GLGlobalData; + +//###################################################################################################################### +static A3DDrawCallbacksData *st_psDrawCallBacks = NULL; +#define A3D_DRAW_CALL0(name) { if(st_psDrawCallBacks) st_psDrawCallBacks->m_pfunc##name(); } +#define A3D_DRAW_CALL1(name, p1) { if(st_psDrawCallBacks) st_psDrawCallBacks->m_pfunc##name(p1); } +#define A3D_DRAW_CALL2(name, p1, p2) { if(st_psDrawCallBacks) st_psDrawCallBacks->m_pfunc##name(p1, p2); } +#define A3D_DRAW_CALL3(name, p1, p2, p3) { if(st_psDrawCallBacks) st_psDrawCallBacks->m_pfunc##name(p1, p2, p3); } +#define A3D_DRAW_CALL6(name, p1, p2, p3, p4, p5, p6) { if(st_psDrawCallBacks) st_psDrawCallBacks->m_pfunc##name(p1, p2, p3, p4, p5, p6); } + +//###################################################################################################################### +#define MAT_INIT_ANGLE(mat, angle) \ + memset(mat,0, sizeof(double)*16); \ + mat[0] = +cos(angle);\ + mat[1] = +sin(angle);\ + mat[4] = -sin(angle);\ + mat[5] = +cos(angle);\ + mat[10] = 1.; \ + mat[15] = 1 + +#define MAT_SCALE(mat, scale) \ + for(int iInd = 0; iInd < 15; ++iInd) mat[iInd] *= scale + +#define MAT_TRANSLAT(mat, offsetX, offsetY, offsetZ) \ + mat[12] += offsetX;\ + mat[13] += offsetY;\ + mat[14] += offsetZ + +//###################################################################################################################### +A3DStatus DrawRepresentationItem(const A3DRiRepresentationItem* pRepItem, const A3DMiscCascadedAttributes* pFatherAttr); + +//###################################################################################################################### +A3DStatus DrawMarkup(const A3DMkpMarkup* pMarkup, const A3DMiscCascadedAttributes* pFatherAttr); + +//###################################################################################################################### +static void stVectoriel(const A3DVector3dData* X, const A3DVector3dData* Y, A3DVector3dData* Z) +{ + Z->m_dX=X->m_dY*Y->m_dZ - X->m_dZ*Y->m_dY; + Z->m_dY=X->m_dZ*Y->m_dX - X->m_dX*Y->m_dZ; + Z->m_dZ=X->m_dX*Y->m_dY - X->m_dY*Y->m_dX; +} + +//###################################################################################################################### +static void stInitializeMatrix(A3DDouble adMatrix[16]) +{ + adMatrix[0] = 1.; adMatrix[4] = 0.; adMatrix[8] = 0.; adMatrix[12] = 0.; + adMatrix[1] = 0.; adMatrix[5] = 1.; adMatrix[9] = 0.; adMatrix[13] = 0.; + adMatrix[2] = 0.; adMatrix[6] = 0.; adMatrix[10] = 1.; adMatrix[14] = 0.; + adMatrix[3] = 0.; adMatrix[7] = 0.; adMatrix[11] = 0.; adMatrix[15] = 1.; +} + +//###################################################################################################################### +static bool stbGetVisibilityFromAttribute(A3DMiscCascadedAttributes const* pAttr) +{ + bool bVibility = true; + if(pAttr != NULL) + { + A3DMiscCascadedAttributesData sAttribData; + A3D_INITIALIZE_DATA(A3DMiscCascadedAttributesData, sAttribData); + if(A3DMiscCascadedAttributesGet(pAttr, &sAttribData)==A3D_SUCCESS) + { + bVibility = (sAttribData.m_bShow && !sAttribData.m_bRemoved); + A3DMiscCascadedAttributesGet(NULL, &sAttribData); + } + } + + return bVibility; +} + +//###################################################################################################################### +// Apply current transformation, to current matrix +static A3DStatus stDrawTransformation(const A3DMiscTransformation* pTransfo3d) +{ + if(pTransfo3d == NULL) + return A3D_SUCCESS; + + A3DStatus iRet = A3D_SUCCESS; + + A3DEEntityType eType = kA3DTypeUnknown; + A3DEntityGetType(pTransfo3d, &eType); + switch(eType) + { + case kA3DTypeMiscCartesianTransformation : + { + A3DMiscCartesianTransformationData sData; + A3D_INITIALIZE_DATA(A3DMiscCartesianTransformationData, sData); + + CHECK_RET(A3DMiscCartesianTransformationGet(pTransfo3d, &sData)); + + double adMatrix[16]; + double dMirror = (sData.m_ucBehaviour & kA3DTransformationMirror) ? -1. : 1.; + + A3DVector3dData sZVector; + memset(adMatrix, 0, 16*sizeof(double)); + stVectoriel(&sData.m_sXVector, &sData.m_sYVector, &sZVector); + + adMatrix[12] = sData.m_sOrigin.m_dX; + adMatrix[13] = sData.m_sOrigin.m_dY; + adMatrix[14] = sData.m_sOrigin.m_dZ; + + adMatrix[0] = sData.m_sXVector.m_dX*sData.m_sScale.m_dX; + adMatrix[1] = sData.m_sXVector.m_dY*sData.m_sScale.m_dX; + adMatrix[2] = sData.m_sXVector.m_dZ*sData.m_sScale.m_dX; + + adMatrix[4] = sData.m_sYVector.m_dX*sData.m_sScale.m_dY; + adMatrix[5] = sData.m_sYVector.m_dY*sData.m_sScale.m_dY; + adMatrix[6] = sData.m_sYVector.m_dZ*sData.m_sScale.m_dY; + + adMatrix[8] = dMirror*sZVector.m_dX*sData.m_sScale.m_dZ; + adMatrix[9] = dMirror*sZVector.m_dY*sData.m_sScale.m_dZ; + adMatrix[10] = dMirror*sZVector.m_dZ*sData.m_sScale.m_dZ; + + adMatrix[15] = 1.; + + A3D_DRAW_CALL1(MultMatrix, adMatrix); + + CHECK_RET(A3DMiscCartesianTransformationGet(NULL, &sData)); + } + break; + + case kA3DTypeMiscGeneralTransformation : + { + A3DMiscGeneralTransformationData sData; + A3D_INITIALIZE_DATA(A3DMiscGeneralTransformationData, sData); + + CHECK_RET(A3DMiscGeneralTransformationGet(pTransfo3d, &sData)); + + A3D_DRAW_CALL1(MultMatrix, sData.m_adCoeff); + + CHECK_RET(A3DMiscGeneralTransformationGet(NULL, &sData)); + } + break; + default: + iRet = A3D_INVALID_ENTITY_TYPE; + } + + return iRet; +} + +//###################################################################################################################### +// DrawingBlockBasic and DrawingBlockOperator are A3DRiRepresentationItem: use the same function +A3DStatus stPreDrawBlock(A3DEntity* psEntity, A3DMiscCascadedAttributes const* pAttr, A3DVoid* pGlobalData, + A3DVoid** pFunctionData, A3DUns32 /*uiBehavior*/) +{ + A3DStatus iRet = A3D_SUCCESS; + *pFunctionData = NULL; + + if(!stbGetVisibilityFromAttribute(pAttr)) + return A3D_CALLBACK_CONTINUE; + + // Get and apply local transformation + A3DRiRepresentationItemData sData; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, sData); + CHECK_RET(A3DRiRepresentationItemGet(psEntity, &sData)); + + const A3DRiCoordinateSystem* pCoordSys = sData.m_pCoordinateSystem; + if(pCoordSys != NULL) + { + *pFunctionData = (void*) 1; + A3D_DRAW_CALL0(PushMatrix); + + A3DRiCoordinateSystemData sCSysData; + A3D_INITIALIZE_DATA(A3DRiCoordinateSystemData, sCSysData); + CHECK_RET(A3DRiCoordinateSystemGet(sData.m_pCoordinateSystem, &sCSysData)); + CHECK_RET(stDrawTransformation(sCSysData.m_pTransformation)); + + // free memory + CHECK_RET(A3DRiCoordinateSystemGet(NULL, &sCSysData)); + } + + bool bDrawMkupOnly = ((GLGlobalData*)pGlobalData)->m_bDrawMarkup; + + // Parse current tessellation + if(!bDrawMkupOnly) + CHECK_RET(DrawRepresentationItem(psEntity, pAttr)); + + // free memory + CHECK_RET(A3DRiRepresentationItemGet(NULL, &sData)); + + // Parse markup + if(bDrawMkupOnly) + { + A3DDrawingBlockBasicData sBlkData; + A3D_INITIALIZE_DATA(A3DDrawingBlockBasicData, sBlkData); + A3DDrawingBlockBasicGet(psEntity, &sBlkData); + + unsigned int uiMk, uiNbMk = sBlkData.m_uiMarkupsSize; + for(uiMk=0; uiMk* paGLSheetDisplayList = ((GLGlobalData*) pGlobalData)->m_paSheetDL; + std::vector *paGLSheetSize = ((GLGlobalData*) pGlobalData)->m_paSheetSize; + bool bDrawMkupOnly = ((GLGlobalData*) pGlobalData)->m_bDrawMarkup; + paGLSheetDisplayList->push_back(uiDisplayList); + + // activate DisplayList + glNewList(uiDisplayList, GL_COMPILE_AND_EXECUTE); + A3DUns32* puiInternalData = new A3DUns32; + *pFunctionData = puiInternalData; + *puiInternalData = 1; + + A3DStatus iRet = A3D_SUCCESS; + + A3DDrawingSheetData sSheetData; + A3D_INITIALIZE_DATA(A3DDrawingSheetData, sSheetData); + iRet = A3DDrawingSheetGet((A3DDrawingSheet*) psEntity, &sSheetData); + if(iRet == A3D_SUCCESS) + { + if(sSheetData.m_pFormat != NULL) + { + A3DDrawingSheetFormatData sFormatData; + A3D_INITIALIZE_DATA(A3DDrawingSheetFormatData, sFormatData); + iRet = A3DDrawingSheetFormatGet(sSheetData.m_pFormat, &sFormatData); + if (iRet==A3D_SUCCESS) + { + if (!bDrawMkupOnly) + { + A3DDouble aPts[5 * 3]; + aPts[0] = 0; + aPts[1] = 0; + aPts[2] = 0; + + aPts[3] = sFormatData.m_sSize.m_dX; + aPts[4] = 0; + aPts[5] = 0; + + aPts[6] = sFormatData.m_sSize.m_dX; + aPts[7] = sFormatData.m_sSize.m_dY; + aPts[8] = 0; + + aPts[9] = 0; + aPts[10] = sFormatData.m_sSize.m_dY; + aPts[11] = 0; + + aPts[12] = 0; + aPts[13] = 0; + aPts[14] = 0; + + GLfloat afValues[3] = { 1, 1, 0 }; + glColor3fv(afValues); + OpenGL_PolyLine(aPts, 5); + } + iRet = A3DDrawingSheetFormatGet(NULL, &sFormatData); + } + if(paGLSheetSize != NULL) + paGLSheetSize->push_back(sFormatData.m_sSize); + } + else + { + if(paGLSheetSize != NULL) + paGLSheetSize->push_back(sSheetData.m_sSize); + } + + *puiInternalData = 2; + A3D_DRAW_CALL0(PushMatrix); + + // Transformation matrix + A3DDouble adMatrix[16]; + stInitializeMatrix(adMatrix); + adMatrix[0] = sSheetData.m_dScale; + adMatrix[5] = sSheetData.m_dScale; + adMatrix[12] = sSheetData.m_sRefPoint.m_dX * sSheetData.m_dScale; + adMatrix[13] = sSheetData.m_sRefPoint.m_dY * sSheetData.m_dScale; + OpenGL_MultMatrix(adMatrix); + A3DDrawingSheetGet(NULL, &sSheetData); + } + + + return iRet; +} + +//###################################################################################################################### +unsigned int OpenGL_GetPushLevel(); + +//###################################################################################################################### +A3DStatus stPostDrawDrawingSheet(A3DEntity* /*psEntity*/, A3DMiscCascadedAttributes const* /*pAttr*/, A3DVoid* /*pGlobalData*/, + A3DVoid* pFunctionData, A3DUns32 /*uiBehavior*/) +{ + if(pFunctionData != NULL) + { + A3DUns32* puiInternalData = (A3DUns32*) pFunctionData; + // pop current transformation + if(*puiInternalData > 1) + A3D_DRAW_CALL0(PopMatrix); + + // Close DisplayList + glEndList(); + delete puiInternalData; + } + + return A3D_SUCCESS; +} + +//###################################################################################################################### +A3DStatus A3DDrawDrawing(A3DDrawingModel* pDrawingModel, A3DDrawCallbacksData* psCallbacks, + std::vector &aGLSheetDisplayList, std::vector* paGLSheetSize, + bool bDrawMarkup) +{ + st_psDrawCallBacks = psCallbacks; + + A3DParseDrawingModelData sCallBackData; + A3D_INITIALIZE_DATA_VAR(sCallBackData); + sCallBackData.m_pfSheet.m_pfPreProcess = stPreDrawDrawingSheet; + sCallBackData.m_pfSheet.m_pfPostProcess = stPostDrawDrawingSheet; + sCallBackData.m_pfView.m_pfPreProcess = stPreDrawDrawingView; + sCallBackData.m_pfView.m_pfPostProcess = stPostDrawDrawingView; + sCallBackData.m_pfBlockBasic.m_pfPreProcess = stPreDrawBlock; + sCallBackData.m_pfBlockBasic.m_pfPostProcess = stPostDrawBlock; + sCallBackData.m_pfBlockOperator.m_pfPreProcess = stPreDrawBlock; + sCallBackData.m_pfBlockOperator.m_pfPostProcess = stPostDrawBlock; + + GLGlobalData sGlobalData; + sGlobalData.m_paSheetDL = &aGLSheetDisplayList; + sGlobalData.m_paSheetSize = paGLSheetSize; + sGlobalData.m_bDrawMarkup = bDrawMarkup; + sCallBackData.m_pGlobalData = &sGlobalData; + + sCallBackData.m_pDrawingModel = pDrawingModel; + + A3DStatus iRet = A3DParseDrawingModel(&sCallBackData); + + st_psDrawCallBacks = NULL; + + return iRet; +} diff --git a/exchange/exchangesource/DrawingViewer/drawing_main.cpp b/exchange/exchangesource/DrawingViewer/drawing_main.cpp new file mode 100644 index 0000000..4546fa9 --- /dev/null +++ b/exchange/exchangesource/DrawingViewer/drawing_main.cpp @@ -0,0 +1,868 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file drawing_main.cpp + +This file demonstrates how to programmatically visualize a drawing PRC file +from a basic OpenGL program using HOOPS Exchange. + +***********************************************************************************************************************/ + +#define INITIALIZE_A3D_API +#include + +#include "../common.hpp" + +#include "callback_opengl.h" +#include "drawing_main.h" +#include "trackball.h" + +#include +#include +#include + +//###################################################################################################################### +A3DStatus CollectDrawing(A3DAsmModelFile* pModelFile, std::vector &apDrawingModels); + +//###################################################################################################################### +A3DStatus A3DDrawDrawing(A3DDrawingModel* pDrawingModel, A3DDrawCallbacksData* psCallbacks, + std::vector &aGLSheetDisplayList, std::vector* paGLSheetSize, + bool bDrawMarkup); + +//###################################################################################################################### +static bool stbTrackBallAnimate = GL_FALSE; + +//###################################################################################################################### +static GLsizei stiXScreen = 0; +static GLsizei stiYScreen = 0; +static GLdouble stdXPan = 0.0; +static GLdouble stdYPan = 0.0; +static GLdouble stdZoom = 1.0; +static GLint staiViewport[4]; + +//###################################################################################################################### +static bool stbLButtonDown = false; +static bool stbRButtonDown = false; + +//###################################################################################################################### +static GLuint stuiModelFileDisplayList = 0; +static GLuint stuiMarkupsDisplayList = 0; +static GLuint stuiTriedronDisplayList = 0; + +//###################################################################################################################### +static std::vector st_aGLSheetDisplayList; +static std::vector st_aGLSheetSize; + +//###################################################################################################################### +static std::vector st_aGLSheetMarkupDisplayList; +static GLuint st_CurrentSheetIndex = 0; + +//###################################################################################################################### +static GLfloat stafLightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }; +static GLfloat stafLightAmbient[] = { 0.1f, 0.1f, 0.1f, 1.0f }; +static GLfloat stafLightPosition[] = { 0.0f, 0.0f, 1.0f, 0.0f }; + +//###################################################################################################################### +static GLfloat stafMaterialDiffuse[] = { 0.6f, 0.6f, 0.6f, 1.0f }; +static GLfloat stafMaterialSpecular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; +static GLfloat stafMaterialShininess[] = { 100.0f }; + +//###################################################################################################################### +static GLfloat stafTextColor[] = { 1.0f, 1.0f, 0.0f, 1.0f }; + +//###################################################################################################################### +static unsigned int stuiClearColor = 0xB2B2B2; + +//###################################################################################################################### +static GLint staiWinSize[2]; +static GLint staiWinPosition[2]; +static bool stbFullScreen = false; + +//###################################################################################################################### +static clock_t stiStart, stiEnd; +static float stfElapsed; +static unsigned int stiNbFrames = 0; +static float stfFps = 0.0f; + +//###################################################################################################################### +static A3DUTF8Char stpcWinTitle[_MAX_PATH]; + +//###################################################################################################################### +static bool stbDisplayHelp = false; +static bool stbDisplayInfos = false; +static bool stbDisplayMarkups = true; + +//###################################################################################################################### +#define TRIEDRON_SIZE 40.0 + +//###################################################################################################################### +#define A3DGL_MIN(a,b) (((a)<(b)) ? (a) : (b)) +#define A3DGL_MAX(a,b) (((a)>(b)) ? (a) : (b)) + +//###################################################################################################################### +class A3DPRCViewerGLInfo +{ +public: + A3DBoundingBoxData sBoundingBox; + double dBoundingBoxRadius; + A3DVector3dData sBoundingBoxCenter; + A3DVector2dData sDelta; + +public: + //################################################################################################################## + A3DPRCViewerGLInfo() { Init(); } + + //################################################################################################################## + void Init() + { + A3D_INITIALIZE_DATA(A3DBoundingBoxData, sBoundingBox); + A3D_INITIALIZE_DATA(A3DVector3dData, sBoundingBoxCenter); + dBoundingBoxRadius = 0.0; + } + + //################################################################################################################## + void operator=(const A3DPRCViewerGLInfo& sOther) + { + sBoundingBox.m_sMin.m_dX = sOther.sBoundingBox.m_sMin.m_dX; + sBoundingBox.m_sMin.m_dY = sOther.sBoundingBox.m_sMin.m_dY; + sBoundingBox.m_sMin.m_dZ = sOther.sBoundingBox.m_sMin.m_dZ; + sBoundingBox.m_sMax.m_dX = sOther.sBoundingBox.m_sMax.m_dX; + sBoundingBox.m_sMax.m_dY = sOther.sBoundingBox.m_sMax.m_dY; + sBoundingBox.m_sMax.m_dZ = sOther.sBoundingBox.m_sMax.m_dZ; + dBoundingBoxRadius = sOther.dBoundingBoxRadius; + sBoundingBoxCenter.m_dX = sOther.sBoundingBoxCenter.m_dX; + sBoundingBoxCenter.m_dY = sOther.sBoundingBoxCenter.m_dY; + sBoundingBoxCenter.m_dZ = sOther.sBoundingBoxCenter.m_dZ; + } + + //################################################################################################################## + void Calculate() + { + A3DVector3dData sMin; + A3DVector3dData sMax; + sMin.m_dX = sBoundingBox.m_sMin.m_dX; + sMin.m_dY = sBoundingBox.m_sMin.m_dY; + sMin.m_dZ = sBoundingBox.m_sMin.m_dZ; + sMax.m_dX = sBoundingBox.m_sMax.m_dX; + sMax.m_dY = sBoundingBox.m_sMax.m_dY; + sMax.m_dZ = sBoundingBox.m_sMax.m_dZ; + + A3DDouble dBX = sMax.m_dX - sMin.m_dX; + A3DDouble dBY = sMax.m_dY - sMin.m_dY; + A3DDouble dBZ = sMax.m_dZ - sMin.m_dZ; + dBoundingBoxRadius = (float)sqrt(dBX*dBX + dBY*dBY + dBZ*dBZ) / 2.0f; + sBoundingBoxCenter.m_dX = (sMin.m_dX + sMax.m_dX) / 2.0; + sBoundingBoxCenter.m_dY = (sMin.m_dY + sMax.m_dY) / 2.0; + sBoundingBoxCenter.m_dZ = (sMin.m_dZ + sMax.m_dZ) / 2.0; + } + + //################################################################################################################## + A3DPRCViewerGLInfo operator+(const A3DPRCViewerGLInfo& sOther) + { + A3DPRCViewerGLInfo sSum; + ExtentUnion(&sBoundingBox, &sOther.sBoundingBox, &sSum.sBoundingBox); + sSum.Calculate(); + return sSum; + } + +private: + + //################################################################################################################## + void ExtentUnion(const A3DBoundingBoxData* e1, const A3DBoundingBoxData* e2, A3DBoundingBoxData* r) + { + r->m_sMin.m_dX = A3DGL_MIN(e1->m_sMin.m_dX, e2->m_sMin.m_dX); + r->m_sMax.m_dX = A3DGL_MAX(e1->m_sMax.m_dX, e2->m_sMax.m_dX); + r->m_sMin.m_dY = A3DGL_MIN(e1->m_sMin.m_dY, e2->m_sMin.m_dY); + r->m_sMax.m_dY = A3DGL_MAX(e1->m_sMax.m_dY, e2->m_sMax.m_dY); + r->m_sMin.m_dZ = A3DGL_MIN(e1->m_sMin.m_dZ, e2->m_sMin.m_dZ); + r->m_sMax.m_dZ = A3DGL_MAX(e1->m_sMax.m_dZ, e2->m_sMax.m_dZ); + } +}; + +//###################################################################################################################### +static A3DDrawCallbacksData stsDrawCallbacksData; +static A3DSDKHOOPSExchangeLoader* stpHOOPSExchangeLoader = NULL; + +//###################################################################################################################### +static A3DPRCViewerGLInfo stsInfo; +static A3DPRCViewerGLInfo stsInfo3D; +static A3DPRCViewerGLInfo stsInfoMarkups; + +//###################################################################################################################### +#define HEX_TO_RED(hexcolor) ((GLclampf) ((hexcolor & 0xFF0000) >> 16) / 255.0f) +#define HEX_TO_GREEN(hexcolor) ((GLclampf) ((hexcolor & 0x00FF00) >> 8) / 255.0f) +#define HEX_TO_BLUE(hexcolor) ((GLclampf) (hexcolor & 0x0000FF) / 255.0f) + +//###################################################################################################################### +static enum +{ + KE_NONE = 0, + KE_ZOOMING, + KE_PANNING +} eMotionType; + +//###################################################################################################################### +void Reshape(GLsizei w, GLsizei h) +{ + tbReshape(w, h); + + glViewport(0, 0, w, h); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + double dLengthX = stsInfo.sBoundingBox.m_sMax.m_dX - stsInfo.sBoundingBox.m_sMin.m_dX; + double dLengthY = stsInfo.sBoundingBox.m_sMax.m_dY - stsInfo.sBoundingBox.m_sMin.m_dY; + + stsInfo.sDelta.m_dX = (dLengthY * w / h - dLengthX)/2.; + stsInfo.sDelta.m_dY = (dLengthX * h / w - dLengthY)/2.; + if(stsInfo.sDelta.m_dX > stsInfo.sDelta.m_dY) + stsInfo.sDelta.m_dY = 0; + else + stsInfo.sDelta.m_dX = 0; + + glOrtho(stsInfo.sBoundingBox.m_sMin.m_dX - stsInfo.sDelta.m_dX, + stsInfo.sBoundingBox.m_sMax.m_dX + stsInfo.sDelta.m_dX, + stsInfo.sBoundingBox.m_sMin.m_dY - stsInfo.sDelta.m_dY, + stsInfo.sBoundingBox.m_sMax.m_dY + stsInfo.sDelta.m_dY, + -1, 1); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glGetIntegerv(GL_VIEWPORT, staiViewport); + + if(!stbFullScreen) + { + staiWinSize[0] = w; + staiWinSize[1] = h; + } +} + +//###################################################################################################################### +void InitGL(void) +{ + glClearColor(HEX_TO_RED(stuiClearColor), HEX_TO_GREEN(stuiClearColor), HEX_TO_BLUE(stuiClearColor), 1.0f); + + glPointSize(5.0f); + + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LEQUAL); + glEnable(GL_NORMALIZE); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + + stuiTriedronDisplayList = glGenLists(1); + glNewList(stuiTriedronDisplayList, GL_COMPILE); + { + glPushAttrib(GL_LIGHTING_BIT | GL_LINE_BIT); + glDisable(GL_LIGHTING); + glLineWidth(2.0); + glBegin(GL_LINES); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(0.0f, 0.0f, 0.0f); + glVertex3f(TRIEDRON_SIZE, 0.0f, 0.0f); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(0.0f, 0.0f, 0.0f); + glVertex3f(0.0f, TRIEDRON_SIZE, 0.0f); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(0.0f, 0.0f, 0.0f); + glVertex3f(0.0f, 0.0f, TRIEDRON_SIZE); + glEnd(); + glPopAttrib(); + } + glEndList(); + + stdZoom = 1.; + stdXPan = 0.0; + stdYPan = 0.0; + +#ifdef _DEBUG + stiStart = clock(); +#endif + + glClearDepth(1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + +//###################################################################################################################### +static float stfX = 1.0f, stfY = 97.0f, stfLineH = 2.0f; +static char stpcMsg[2048]; + +//###################################################################################################################### +void PrintString(const char* format, ...) +{ + va_list args; + va_start(args, format); + vsprintf(stpcMsg, format, args); + va_end(args); + + glRasterPos2f(stfX, stfY); + char* pcPos = &stpcMsg[0]; + while(*pcPos) + { + if(*pcPos == '\n') + { + stfY -= stfLineH; + glRasterPos2f(stfX, stfY); + } + else + glutBitmapCharacter(GLUT_BITMAP_8_BY_13, *pcPos); + pcPos++; + } +} + +//###################################################################################################################### +void DrawStrings(void) +{ + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluOrtho2D(0.0, 100.0, 0.0, 100.0); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + + glColor3fv(stafTextColor); + + if(stbDisplayInfos) + { + stfX = 1.0f; + stfY = 97.0f; + + stiNbFrames++; + stiEnd = clock(); + stfElapsed = (float)(stiEnd - stiStart) / CLOCKS_PER_SEC; + if(stfElapsed >= 1.0) + { + stfFps = stiNbFrames/stfElapsed; + stiStart = stiEnd; + stiNbFrames = 0; + } + + PrintString("%.2f fps\n", stfFps); + PrintString("Bounding box\n"); + A3DVector3dData& sMin = stsInfo.sBoundingBox.m_sMin; + A3DVector3dData& sMax = stsInfo.sBoundingBox.m_sMax; + PrintString(" Extent: [%.3f, %.3f, %.3f] -> [%.3f, %.3f, %.3f]\n", sMin.m_dX, sMin.m_dY, sMin.m_dZ, + sMax.m_dX, sMax.m_dY, sMax.m_dZ); + PrintString(" Radius: %.3f\n", stsInfo.dBoundingBoxRadius); + } + + if(stbDisplayHelp) + { + stfX = 1.0f; + stfY = 70.0f; + PrintString("HELP\n"); + PrintString(" MOUSE :\n"); + PrintString(" Left button: panning\n"); + PrintString(" Right button: zooming\n"); + PrintString("\n"); + PrintString(" KEYBOARD :\n"); + PrintString(" F1: print this help\n"); + PrintString(" F2: open a file (in the console)\n"); + PrintString(" F3: save file as Prc\n"); + PrintString(" F4: toggle display markups\n"); + PrintString(" F5: toggle full screen\n"); + PrintString(" F6: change background color\n"); + PrintString(" F11: toggle display information\n"); + PrintString(" PAGE_UP / PAGE_DOWN: change current sheet\n"); + } + + glPopAttrib(); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} + +//###################################################################################################################### +void Display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + { + glLoadIdentity(); + + glLightfv(GL_LIGHT0, GL_POSITION, stafLightPosition); + double dOffsetX = (stsInfo.sBoundingBox.m_sMax.m_dX-stsInfo.sBoundingBox.m_sMin.m_dX)/2. + stsInfo.sDelta.m_dX; + double dOffsetY = (stsInfo.sBoundingBox.m_sMax.m_dY-stsInfo.sBoundingBox.m_sMin.m_dY)/2. + stsInfo.sDelta.m_dY; + + glTranslated(dOffsetX, dOffsetY, 0.); + + glScaled(stdZoom, stdZoom, 1.); + + glTranslated(-dOffsetX, -dOffsetY, 0.); + + glTranslated(-stsInfo.dBoundingBoxRadius*stdXPan, -stsInfo.dBoundingBoxRadius*stdYPan, 0); + //-stsInfo.dBoundingBoxRadius*stdZoom); + + if (st_aGLSheetDisplayList.size() > 0) + { + GLfloat afValues[3] = { 1, 1, 1 }; + glColor3fv(afValues); + glCallList(st_aGLSheetDisplayList.at(size_t(st_CurrentSheetIndex))); + } + if (stbDisplayMarkups && st_aGLSheetMarkupDisplayList.size() > 0) + { + glCallList(st_aGLSheetMarkupDisplayList.at(size_t(st_CurrentSheetIndex))); + } + } + glPopMatrix(); + + if(stbDisplayInfos || stbDisplayHelp) + DrawStrings(); + + glFlush(); + glFinish(); + glutSwapBuffers(); +} + +//###################################################################################################################### +static bool stbTBRunning = false; + +//###################################################################################################################### +void MouseButton(int button, int state, GLsizei x, GLsizei y) +{ + if(button == GLUT_LEFT_BUTTON) + { + if(state == GLUT_DOWN) + stbLButtonDown = true; + else if(state == GLUT_UP) + stbLButtonDown = false; + } + else if(button == GLUT_RIGHT_BUTTON) + { + if(state == GLUT_DOWN) + stbRButtonDown = true; + else if(state == GLUT_UP) + stbRButtonDown = false; + } + + if(!stbLButtonDown && !stbRButtonDown) + glutSetCursor(GLUT_CURSOR_LEFT_ARROW); + + eMotionType = KE_NONE; + + if(stbLButtonDown) + { + if(stbTBRunning) + tbMouse(GLUT_LEFT_BUTTON, GLUT_UP, x, y); + eMotionType = KE_PANNING; + glutSetCursor(GLUT_CURSOR_SPRAY); + } + else + { + if(stbRButtonDown) + { + eMotionType = KE_ZOOMING; + glutSetCursor(GLUT_CURSOR_UP_DOWN); + } + else + { + tbMouse(button, state, x, y); + stbTBRunning = false; + } + } + + stiXScreen = x; + stiYScreen = y; + + glutPostRedisplay(); +} + +//###################################################################################################################### +void Motion(GLsizei x, GLsizei y) +{ + tbMotion(x, y); + + switch(eMotionType) + { + case KE_PANNING : + { + stdXPan -= (GLdouble)(x - stiXScreen)/(GLdouble)staiViewport[2] * 2.0 / stdZoom; + stdYPan += (GLdouble)(y - stiYScreen)/(GLdouble)staiViewport[3] * 2.0 / stdZoom; + break; + } + case KE_ZOOMING : + { + stdZoom += (GLdouble)(y - stiYScreen)/(GLdouble)staiViewport[3] * 10.0; + if(stdZoom < 0.1) + stdZoom = 0.1; + break; + } + default: + break; + } + stiXScreen = x; + stiYScreen = y; + + glutPostRedisplay(); +} + +//###################################################################################################################### +A3DInt32 CloseFile() +{ + A3DInt32 iRet = A3D_SUCCESS; + + size_t uiList, uiNbList = st_aGLSheetDisplayList.size(); + for(uiList = 0; uiList < uiNbList; ++uiList) + { + glDeleteLists(st_aGLSheetDisplayList.back(), 1); + st_aGLSheetDisplayList.pop_back(); + + glDeleteLists(st_aGLSheetMarkupDisplayList.back(), 1); + st_aGLSheetMarkupDisplayList.pop_back(); + } + + st_aGLSheetSize.clear(); + + glDeleteLists(stuiModelFileDisplayList, 1); + glDeleteLists(stuiMarkupsDisplayList, 1); + stuiModelFileDisplayList = stuiMarkupsDisplayList = 0; + + return iRet; +} + +//###################################################################################################################### +A3DInt32 OpenFile(const A3DUTF8Char*pcCADFileName) +{ + if(stpHOOPSExchangeLoader == NULL) + return A3D_ERROR; + + A3DImport sImport(pcCADFileName); + sImport.m_sLoadData.m_sGeneral.m_eReadingMode2D3D = kA3DRead_Drawings; + + A3DInt32 iRet = stpHOOPSExchangeLoader->Import(sImport); + + printf("Done.\n"); + + return iRet; +} + +//###################################################################################################################### +A3DInt32 ProcessModelFile() +{ + if(stpHOOPSExchangeLoader == NULL || stpHOOPSExchangeLoader->m_psModelFile == NULL) + return A3D_ERROR; + + // Collect all DrawingModels + std::vector apDrawingModels; + A3DInt32 iRet = CollectDrawing(stpHOOPSExchangeLoader->m_psModelFile, apDrawingModels); + if(iRet != A3D_SUCCESS) + return iRet; + + if(apDrawingModels.size() == 0) + return A3D_ERROR; + + // Draws and stores all the sheets in list + st_aGLSheetDisplayList.clear(); + size_t uiModel, uiNbModel = apDrawingModels.size(); + for(uiModel = 0; uiModel < uiNbModel; ++uiModel) + { + iRet = A3DDrawDrawing(apDrawingModels.at(uiModel), &stsDrawCallbacksData, st_aGLSheetDisplayList, + &st_aGLSheetSize, false); + if(iRet != A3D_SUCCESS) + break; + + iRet = A3DDrawDrawing(apDrawingModels.at(uiModel), &stsDrawCallbacksData, st_aGLSheetMarkupDisplayList, + NULL, true); + if(iRet != A3D_SUCCESS) + break; + } + + if(iRet == A3D_SUCCESS && st_aGLSheetSize.size() > 0) + { + st_CurrentSheetIndex = 0; + stsInfo.sBoundingBox.m_sMin.m_dX = 0.; + stsInfo.sBoundingBox.m_sMin.m_dY = 0.; + stsInfo.sBoundingBox.m_sMax.m_dX = st_aGLSheetSize[st_CurrentSheetIndex].m_dX; + stsInfo.sBoundingBox.m_sMax.m_dY = st_aGLSheetSize[st_CurrentSheetIndex].m_dY; + stsInfo.Calculate(); + } + + stdZoom = 1.; + stdXPan = 0.0; + stdYPan = 0.0; + + return iRet; +} + +//###################################################################################################################### +A3DInt32 SaveFileAsPrc() +{ + A3DStatus iRet = A3D_SUCCESS; + + if(stpHOOPSExchangeLoader->m_psModelFile != NULL) + { + PrintString("Enter file name in console\n"); + printf("Enter file name:\n"); + + A3DUTF8Char pcPRCFileName[_MAX_PATH]; + scanf("%s", pcPRCFileName); + + A3DRWParamsExportPrcData sParamsExportData; + A3D_INITIALIZE_DATA(A3DRWParamsExportPrcData, sParamsExportData); + sParamsExportData.m_bCompressBrep = false; + sParamsExportData.m_bCompressTessellation = false; + + CHECK_RET(A3DAsmModelFileExportToPrcFile(stpHOOPSExchangeLoader->m_psModelFile, &sParamsExportData, pcPRCFileName, NULL)); + if(iRet == A3D_SUCCESS) + printf("Done.\n"); + else + printf("failure [%d]\n", iRet); + } + + return iRet; +} + +//###################################################################################################################### +void terminate2() +{ + CloseFile(); + + delete stpHOOPSExchangeLoader; + stpHOOPSExchangeLoader = NULL; + ListLeaks(); +} + +//###################################################################################################################### +void stChangeViewedSheet(bool bPrevious) +{ + bool bChange = false; + if(bPrevious) + { + if(st_CurrentSheetIndex > 0) + { + st_CurrentSheetIndex--; + bChange = true; + } + } + else + { + if(st_CurrentSheetIndex + 1 < unsigned(st_aGLSheetDisplayList.size())) + { + st_CurrentSheetIndex++; + bChange = true; + } + } + + if(bChange) + { + stsInfo.sBoundingBox.m_sMin.m_dX = 0.; + stsInfo.sBoundingBox.m_sMin.m_dY = 0.; + stsInfo.sBoundingBox.m_sMax.m_dX = st_aGLSheetSize[st_CurrentSheetIndex].m_dX; + stsInfo.sBoundingBox.m_sMax.m_dY = st_aGLSheetSize[st_CurrentSheetIndex].m_dY; + stsInfo.Calculate(); + + Reshape(staiWinSize[0], staiWinSize[1]); + glutPostRedisplay(); + } +} + +//###################################################################################################################### +void Key(unsigned char key, int /* x */, int /* y */) +{ + + switch(key) + { + case 27 : + exit(0); + + case GLUT_KEY_F1: + stbDisplayHelp = !stbDisplayHelp; + glutPostRedisplay(); + break; + + case GLUT_KEY_F2: + { + A3DUTF8Char pcFilePath[_MAX_PATH]; + printf("\nFile path: "); + scanf("%s", pcFilePath); + + CloseFile(); + if (OpenFile(pcFilePath) == A3D_SUCCESS) + { + ProcessModelFile(); + Reshape(staiWinSize[0], staiWinSize[1]); + } + Display(); + } + break; + + case GLUT_KEY_F3: + { + SaveFileAsPrc(); + } + break; + + case GLUT_KEY_F4: + stbDisplayMarkups = !stbDisplayMarkups; + Reshape(staiWinSize[0], staiWinSize[1]); + glutPostRedisplay(); + break; + + case GLUT_KEY_F5: + stbFullScreen = !stbFullScreen; + if(stbFullScreen) + glutFullScreen(); + else + { + glutPositionWindow(staiWinPosition[0], staiWinPosition[1]); + glutReshapeWindow(staiWinSize[0], staiWinSize[1]); + } + break; + + case GLUT_KEY_F6: + { + char pcNewColor[_MAX_PATH]; + printf("\nNew color (0xHHHHHH) : "); + scanf("%s", pcNewColor); + sscanf(pcNewColor, "%x", &stuiClearColor); + glClearColor(HEX_TO_RED(stuiClearColor), HEX_TO_GREEN(stuiClearColor), HEX_TO_BLUE(stuiClearColor), 1.0f); + glutPostRedisplay(); + } + break; + + + case GLUT_KEY_F11: + stbDisplayInfos = !stbDisplayInfos; + glutPostRedisplay(); + break; + + case GLUT_KEY_PAGE_UP: + stChangeViewedSheet(true); + break; + + case GLUT_KEY_PAGE_DOWN: + stChangeViewedSheet(false); + break; + + default: + break; + } +} + +//###################################################################################################################### +void SpecialKey(int k, int x, int y) +{ + Key((unsigned char) k, x, y); +} + +static MY_CHAR acSrcFileName[_MAX_PATH * 2]; +static MY_CHAR acLogFileName[_MAX_PATH * 2]; + +//###################################################################################################################### +// Main function +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + // + // ### COMMAND LINE ARGUMENTS + // + + if (iArgc > 4) + { + MY_PRINTF2("Usage:\n %s [input CATDrawing file] [Clear color value] [output LOG file]\n", ppcArgv[0]); + MY_PRINTF(" Default output LOG file is [input CATDrawing file]_Log.txt\n\n"); + } + + if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]); + else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_DRAWING); + if (iArgc > 2) MY_SSCANF(ppcArgv[2], "%x", &stuiClearColor); + else stuiClearColor = 0xB2B2B2; + if (iArgc > 3) MY_STRCPY(acLogFileName, ppcArgv[3]); + else MY_SPRINTF(acLogFileName, "%s_Log.txt", acSrcFileName); + GetLogFile(acLogFileName); // Initialize log file + + // + // ### INITIALIZE HOOPS EXCHANGE + // + + stpHOOPSExchangeLoader = new A3DSDKHOOPSExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); + if (stpHOOPSExchangeLoader->m_eSDKStatus != A3D_SUCCESS) + { + A3DStatus eSDKStatus = stpHOOPSExchangeLoader->m_eSDKStatus; + delete stpHOOPSExchangeLoader; + stpHOOPSExchangeLoader = NULL; + return eSDKStatus; + } + + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + // + // ### PROCESS SAMPLE CODE + // + + A3DInt32 iRet = A3D_SUCCESS; + glutInit((int*)(&iArgc), (char**)ppcArgv); + GLsizei iScreenW = glutGet(GLUT_SCREEN_WIDTH); + GLsizei iScreenH = glutGet(GLUT_SCREEN_HEIGHT); + staiWinSize[0] = (GLsizei)((double)iScreenW * 0.7); + staiWinSize[1] = (GLsizei)((double)iScreenH * 0.7); + staiWinPosition[0] = (iScreenW - staiWinSize[0]) / 2; + staiWinPosition[1] = (iScreenH - staiWinSize[1]) / 2; + + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_STENCIL); // GLUT_DEPTH + glutInitWindowPosition(staiWinPosition[0], staiWinPosition[1]); + glutInitWindowSize(staiWinSize[0], staiWinSize[1]); + + glutCreateWindow("A3DPRCDrawingViewerGL"); + glViewport(0, 0, staiWinSize[0], staiWinSize[1]); + + tbInit(GLUT_LEFT_BUTTON); + tbAnimate(stbTrackBallAnimate); + + stsInfo.Init(); + stsInfo3D.Init(); + stsInfoMarkups.Init(); + + CHECK_RET(OpenGL_SetAndInitCallBack(stsDrawCallbacksData)); + + A3DUTF8Char sSrcFileNameUTF8[_MAX_PATH]; +#ifdef _MSC_VER + A3DMiscUTF16ToUTF8(acSrcFileName, sSrcFileNameUTF8); +#else + MY_STRCPY(sSrcFileNameUTF8, acSrcFileName); +#endif + CHECK_RET_TERM(OpenFile(sSrcFileNameUTF8)); + + CHECK_RET_TERM(ProcessModelFile()); + + InitGL(); + + glutReshapeFunc(Reshape); + glutDisplayFunc(Display); + glutKeyboardFunc(Key); + glutSpecialFunc(SpecialKey); + glutMouseFunc(MouseButton); + glutMotionFunc(Motion); + glutIdleFunc(NULL); + + printf("\nF1 for help\n"); + + // glut call exit(0) when closing windows, so set atexit to close properly dll + atexit(terminate2); + + glutMainLoop(); + + return 0; +} diff --git a/exchange/exchangesource/DrawingViewer/drawing_main.h b/exchange/exchangesource/DrawingViewer/drawing_main.h new file mode 100644 index 0000000..5dc85c2 --- /dev/null +++ b/exchange/exchangesource/DrawingViewer/drawing_main.h @@ -0,0 +1,51 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file drawing_main.h + +***********************************************************************************************************************/ + +#ifndef _A3DPRCViewerGL_H +#define _A3DPRCViewerGL_H + +#define _CRT_SECURE_NO_DEPRECATE 1 +#include +#include +#include + +#ifdef __APPLE__ +#include +#else +#include +#endif + +#include + +//###################################################################################################################### +#define CHECK_RET_TERM(function_call) {\ + iRet = function_call;\ + if(iRet != A3D_SUCCESS)\ + {\ + std::cout << #function_call " returned error " << iRet << std::endl;\ + terminate2();\ + return iRet;\ + }\ +} + +//###################################################################################################################### +#define FOVY 30.0f +#define Stringize(L) #L +#define MakeString(M, L) M(L) +#define $Line \ + MakeString(Stringize, __LINE__) +#define Todo __FILE__ "(" $Line ") : TODO: " + +#endif diff --git a/exchange/exchangesource/DrawingViewer/drawing_parse.cpp b/exchange/exchangesource/DrawingViewer/drawing_parse.cpp new file mode 100644 index 0000000..d224f2b --- /dev/null +++ b/exchange/exchangesource/DrawingViewer/drawing_parse.cpp @@ -0,0 +1,431 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include + +#include +#include "drawing_parse.h" + + + +//###################################################################################################################### +#define CHECK(FCT) \ + if(!bExit) \ + { \ + A3DStatus iLocRet = (FCT); \ + if(iLocRet != A3D_SUCCESS) \ + { \ + if(iLocRet == A3D_CALLBACK_CONTINUE) \ + bExit = true; \ + else \ + { \ + iRet = iLocRet; \ + bExit = (uiParseBehavior & A3D_PARSE_CONTINUE_EVEN_IF_ERROR) && (iLocRet != A3D_SUCCESS); \ + } \ + } \ + } + +//###################################################################################################################### +#define A3DDRAWING_PARSE_SHEET 0x80000000 // 1000 0000 0000 0000 +#define A3DDRAWING_PARSE_VIEW 0x40000000 // 0100 0000 0000 0000 +#define A3DDRAWING_PARSE_BLOCK 0x20000000 // 0010 0000 0000 0000 +#define A3DDRAWING_PARSE_BLOCKBASIC 0x10000000 // 0001 0000 0000 0000 +#define A3DDRAWING_PARSE_BLOCKOPERATOR 0x08000000 // 0000 1000 0000 0000 +#define A3DDRAWING_PARSE_ENTITY 0x00400000 // 0000 0100 0000 0000 + +//###################################################################################################################### +#define A3DDRAWING_SET_PARSE_SHEET 0x80000000 // 1000 0000 0000 0000 +#define A3DDRAWING_SET_PARSE_VIEW 0xC0000000 // 1100 0000 0000 0000 +#define A3DDRAWING_SET_PARSE_BLOCK 0xE0000000 // 1110 0000 0000 0000 +#define A3DDRAWING_SET_PARSE_BLOCKBASIC 0xF0000000 // 1111 0000 0000 0000 +#define A3DDRAWING_SET_PARSE_BLOCKOPERATOR 0xE8000000 // 1110 1000 0000 0000 +#define A3DDRAWING_SET_PARSE_ENTITY 0xF8000000 // 1111 1000 0000 0000 + +//###################################################################################################################### +static A3DStatus stCreateAndPushCascadedAttributes(const A3DRootBaseWithGraphics* pBase, + const A3DMiscCascadedAttributes* pFatherAttr, + A3DMiscCascadedAttributes** ppAttr) +{ + A3DStatus iRet = A3D_SUCCESS; + + CHECK_RET(A3DMiscCascadedAttributesCreate(ppAttr)); + CHECK_RET(A3DMiscCascadedAttributesPush(*ppAttr, pBase, pFatherAttr)); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stFreeCascadedAttributes(A3DMiscCascadedAttributes* ppAttr) +{ + A3DStatus iRet = A3D_SUCCESS; + + CHECK_RET(A3DMiscCascadedAttributesDelete(ppAttr)); + return iRet; +} + +//###################################################################################################################### +#define CREATE_AUTOCLEAN_CLASS_DATA(TYPE) \ + class AutoClean##TYPE##Data : public TYPE##Data\ + { \ + public: \ + AutoClean##TYPE##Data() { A3D_INITIALIZE_##TYPE##Data(*this)}; \ + ~AutoClean##TYPE##Data() { TYPE##Get(NULL, (TYPE##Data*)this);}; \ + } + +//###################################################################################################################### +CREATE_AUTOCLEAN_CLASS_DATA(A3DDrawingBlockBasic); + +//###################################################################################################################### +static A3DStatus stA3DParse_Block(A3DParseDrawingModelData const* const pParseData, A3DUns32 uiParseBehavior, + A3DDrawingBlock* pBlock, A3DMiscCascadedAttributes const* pFatherAttr); + +//###################################################################################################################### +static A3DStatus stA3DParse_BlockBasic(A3DParseDrawingModelData const* const pParseData, A3DUns32 uiParseBehavior, + A3DDrawingBlockBasic* pBlock, A3DMiscCascadedAttributes const* pFatherAttr) +{ + if((uiParseBehavior & A3DDRAWING_PARSE_BLOCKBASIC) == 0) + return A3D_SUCCESS; + + A3DStatus iRet = A3D_SUCCESS; + A3DVoid* pFunctionData = NULL; + A3DUns32 uiFunctionBehavior = 0; + bool bExit = false; + + // Compute CascadedAttributes ... + A3DMiscCascadedAttributes* pAttr = NULL; + CHECK(stCreateAndPushCascadedAttributes(pBlock, pFatherAttr, &pAttr)); + + if(pParseData->m_pfBlockBasic.m_pfPreProcess != NULL) + { + CHECK(pParseData->m_pfBlockBasic.m_pfPreProcess(pBlock, pAttr, pParseData->m_pGlobalData, &pFunctionData, + uiFunctionBehavior)); + } + + if(!bExit) + { + //A3DDrawingBlockBasicData sBlockData; + //A3D_INITIALIZE_DATA(A3DDrawingBlockBasicData, sBlockData); + AutoCleanA3DDrawingBlockBasicData sBlockData; + CHECK(A3DDrawingBlockBasicGet(pBlock,&sBlockData)); + sBlockData.m_uiDrwEntitiesSize = 0; + if(bExit) + { + // No need to continue + stFreeCascadedAttributes(pAttr); + return iRet; + } + + A3DUns32 uiIndex; + + for(uiIndex = 0; uiIndex < sBlockData.m_uiDrwBlocksSize; uiIndex++) + { + CHECK(stA3DParse_Block(pParseData, uiParseBehavior, sBlockData.m_ppDrwBlocks[uiIndex], pAttr)); + if(bExit) + break; + } + + CHECK(A3DDrawingBlockBasicGet(NULL, &sBlockData)); + } + + if(pParseData->m_pfBlockBasic.m_pfPostProcess != NULL) + { + if(iRet != A3D_SUCCESS) + uiFunctionBehavior |= A3D_PARSE_ERROR; + CHECK(pParseData->m_pfBlockBasic.m_pfPostProcess(pBlock, pAttr, pParseData->m_pGlobalData, pFunctionData, + uiFunctionBehavior)); + } + + // Free local data + stFreeCascadedAttributes(pAttr); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stA3DParse_BlockOperator(A3DParseDrawingModelData const* const pParseData, A3DUns32 uiParseBehavior, + A3DDrawingBlockOperator* pBlock, A3DMiscCascadedAttributes const* pFatherAttr) +{ + if((uiParseBehavior & A3DDRAWING_PARSE_BLOCKBASIC)==0) + return A3D_SUCCESS; + + A3DStatus iRet = A3D_SUCCESS; + A3DVoid *pFunctionData = NULL; + A3DUns32 uiFunctionBehavior = 0; + bool bExit = false; + + + // Compute CascadedAttributes ... + A3DMiscCascadedAttributes* pAttr = NULL; + CHECK(stCreateAndPushCascadedAttributes(pBlock, pFatherAttr, &pAttr)); + + if(pParseData->m_pfBlockOperator.m_pfPreProcess != NULL) + { + CHECK(pParseData->m_pfBlockOperator.m_pfPreProcess(pBlock, pAttr, pParseData->m_pGlobalData, &pFunctionData, + uiFunctionBehavior)); + } + + if(!bExit) + { + A3DDrawingBlockOperatorData sBlockData; + A3D_INITIALIZE_DATA(A3DDrawingBlockOperatorData, sBlockData); + CHECK(A3DDrawingBlockOperatorGet(pBlock,&sBlockData)); + if(bExit) + { + // No need to continue + stFreeCascadedAttributes(pAttr); + return iRet; + } + + A3DUns32 uiIndex; + + for(uiIndex = 0; uiIndex < sBlockData.m_uiDrwBlocksSize; uiIndex++) + { + CHECK(stA3DParse_Block(pParseData, uiParseBehavior, sBlockData.m_ppDrwBlocks[uiIndex], pAttr)); + if(bExit) + break; + } + + CHECK(A3DDrawingBlockOperatorGet(NULL, &sBlockData)); + } + + if(pParseData->m_pfBlockOperator.m_pfPostProcess != NULL) + { + if(iRet != A3D_SUCCESS) + uiFunctionBehavior |= A3D_PARSE_ERROR; + CHECK(pParseData->m_pfBlockOperator.m_pfPostProcess(pBlock, pAttr, pParseData->m_pGlobalData, pFunctionData, + uiFunctionBehavior)); + } + + // Free local data + stFreeCascadedAttributes(pAttr); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stA3DParse_Block(A3DParseDrawingModelData const* const pParseData, A3DUns32 uiParseBehavior, + A3DDrawingBlock* pBlock, A3DMiscCascadedAttributes const* pFatherAttr) +{ + A3DStatus iRet = A3D_SUCCESS; + bool bExit = false; + + if((uiParseBehavior & A3DDRAWING_PARSE_BLOCK) != 0) + { + A3DEEntityType eType = kA3DTypeUnknown; + CHECK(A3DEntityGetType(pBlock, &eType)); + switch(eType) + { + case kA3DTypeDrawingBlockBasic: + CHECK(stA3DParse_BlockBasic(pParseData, uiParseBehavior, (A3DDrawingBlockBasic*) pBlock, pFatherAttr)); + break; + + case kA3DTypeDrawingBlockOperator: + CHECK(stA3DParse_BlockOperator(pParseData, uiParseBehavior, (A3DDrawingBlockOperator*) pBlock, pFatherAttr)); + break; + + default: + return A3D_INVALID_ENTITY_TYPE; + } + } + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stA3DParse_View(A3DParseDrawingModelData const* const pParseData, A3DUns32 uiParseBehavior, + A3DDrawingView* pView, A3DMiscCascadedAttributes const* pFatherAttr) +{ + if((uiParseBehavior & A3DDRAWING_PARSE_VIEW) == 0) + return A3D_SUCCESS; + + A3DStatus iRet = A3D_SUCCESS; + A3DVoid* pFunctionData = NULL; + A3DUns32 uiFunctionBehavior = 0; + bool bExit = false; + + + // Compute CascadedAttributes ... + A3DMiscCascadedAttributes* pAttr = NULL; + CHECK(stCreateAndPushCascadedAttributes(pView, pFatherAttr, &pAttr)); + + if(pParseData->m_pfView.m_pfPreProcess != NULL) + { + CHECK(pParseData->m_pfView.m_pfPreProcess(pView, pAttr, pParseData->m_pGlobalData, &pFunctionData, + uiFunctionBehavior)); + } + + if(!bExit) + { + // Getting A3DDrawingView Data + A3DDrawingViewData sViewData; + A3D_INITIALIZE_DATA(A3DDrawingViewData, sViewData); + CHECK(A3DDrawingViewGet(pView, &sViewData)); + if(bExit) + { + // No need to continue + stFreeCascadedAttributes(pAttr); + return iRet; + } + + // Parse sub-entities + { + if(sViewData.m_pLocalBlocks != NULL) + { + CHECK(stA3DParse_Block(pParseData, uiParseBehavior, sViewData.m_pLocalBlocks, pAttr)); + } + + A3DUns32 uiIndex; + for(uiIndex = 0; uiIndex < sViewData.m_uiDrwBlocksSize; uiIndex++) + { + CHECK(stA3DParse_Block(pParseData, uiParseBehavior, sViewData.m_ppDrwBlocks[uiIndex], pAttr)); + if(bExit) + break; + } + } + + CHECK(A3DDrawingViewGet(NULL, &sViewData)); + } + + if(pParseData->m_pfView.m_pfPostProcess != NULL) + { + if(iRet != A3D_SUCCESS) + uiFunctionBehavior |= A3D_PARSE_ERROR; + CHECK(pParseData->m_pfView.m_pfPostProcess(pView, pAttr, pParseData->m_pGlobalData, pFunctionData, + uiFunctionBehavior)); + } + + // Free local data + stFreeCascadedAttributes(pAttr); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stA3DParse_Sheet(A3DParseDrawingModelData const* const pParseData, A3DUns32 uiParseBehavior, + A3DDrawingSheet* pSheet, A3DMiscCascadedAttributes const* pFatherAttr) +{ + if((uiParseBehavior & A3DDRAWING_PARSE_SHEET) == 0) + return A3D_SUCCESS; + + A3DStatus iRet = A3D_SUCCESS; + A3DVoid* pFunctionData = NULL; + A3DUns32 uiFunctionBehavior = 0; + bool bExit = false; + + // Compute CascadedAttributes ... + A3DMiscCascadedAttributes* pAttr = NULL; + CHECK(stCreateAndPushCascadedAttributes(pSheet, pFatherAttr, &pAttr)); + + if(pParseData->m_pfSheet.m_pfPreProcess != NULL) + { + CHECK(pParseData->m_pfSheet.m_pfPreProcess(pSheet, pAttr, pParseData->m_pGlobalData, &pFunctionData, + uiFunctionBehavior)); + } + + A3DDrawingSheetData sSheetData; + A3D_INITIALIZE_DATA(A3DDrawingSheetData, sSheetData); + CHECK(A3DDrawingSheetGet(pSheet, &sSheetData)); + + if(sSheetData.m_pBackgroundBlocks != NULL) + { + CHECK(stA3DParse_Block(pParseData, uiParseBehavior, sSheetData.m_pBackgroundBlocks, pAttr)); + } + + A3DUns32 uiIndex; + for(uiIndex = 0; uiIndex < sSheetData.m_uiDrwBlocksSize; uiIndex++) + { + CHECK(stA3DParse_Block(pParseData, uiParseBehavior, sSheetData.m_ppDrwBlocks[uiIndex], pAttr)); + if(bExit) + break; + } + + for(uiIndex=0; uiIndexm_pfSheet.m_pfPostProcess != NULL) + { + if(iRet != A3D_SUCCESS) + uiFunctionBehavior |= A3D_PARSE_ERROR; + CHECK(pParseData->m_pfSheet.m_pfPostProcess(pSheet, pAttr, pParseData->m_pGlobalData, pFunctionData, + uiFunctionBehavior)); + } + + // Free local data + stFreeCascadedAttributes(pAttr); + CHECK(A3DDrawingSheetGet(nullptr, &sSheetData)); + + return iRet; +} + +//###################################################################################################################### +A3DStatus A3DParseDrawingModel(A3DParseDrawingModelData const* const pParseData) +{ + if(pParseData == NULL ||pParseData->m_pDrawingModel == NULL) + return A3D_ERROR; + + // Compute ParseBehavior + A3DUns32 uiLParseBehavior = pParseData->m_uiParseBehavior; + if(pParseData->m_pfSheet.m_pfPreProcess || pParseData->m_pfSheet.m_pfPostProcess) + uiLParseBehavior |= A3DDRAWING_SET_PARSE_VIEW; + + if(pParseData->m_pfView.m_pfPreProcess || pParseData->m_pfView.m_pfPostProcess) + uiLParseBehavior |= A3DDRAWING_SET_PARSE_SHEET; + + if(pParseData->m_pfBlockBasic.m_pfPreProcess || pParseData->m_pfBlockBasic.m_pfPostProcess) + uiLParseBehavior |= A3DDRAWING_SET_PARSE_BLOCKBASIC; + + if(pParseData->m_pfBlockOperator.m_pfPreProcess || pParseData->m_pfBlockOperator.m_pfPostProcess) + uiLParseBehavior |= A3DDRAWING_SET_PARSE_BLOCKOPERATOR; + + if(pParseData->m_pfEntity.m_pfPreProcess || pParseData->m_pfEntity.m_pfPostProcess) + uiLParseBehavior |= A3DDRAWING_SET_PARSE_ENTITY; + + A3DStatus iRet; + + A3DMiscCascadedAttributes* pCascadedAttr; + CHECK_RET(A3DMiscCascadedAttributesCreate(&pCascadedAttr)); + + A3DDrawingModelData sDrawingModelData; + A3D_INITIALIZE_DATA(A3DDrawingModelData, sDrawingModelData); + iRet = A3DDrawingModelGet(pParseData->m_pDrawingModel, &sDrawingModelData); + if(iRet == A3D_SUCCESS) + { + if((pParseData->m_uiParseBehavior & A3D_PARSE_DRAWING_ACTIVE_SHEET) != 0) + { + if(sDrawingModelData.m_uiActiveSheet < sDrawingModelData.m_uiDrwSheetsSize) + { + iRet = stA3DParse_Sheet(pParseData, uiLParseBehavior, + sDrawingModelData.m_ppDrwSheets[sDrawingModelData.m_uiActiveSheet], pCascadedAttr); + } + } + else + { + A3DUns32 uiSheet, uiNbSheet = sDrawingModelData.m_uiDrwSheetsSize; + for(uiSheet = 0; uiSheet < uiNbSheet; uiSheet++) + { + iRet = stA3DParse_Sheet(pParseData, uiLParseBehavior, + sDrawingModelData.m_ppDrwSheets[uiSheet], pCascadedAttr); + if((iRet != A3D_SUCCESS) && ((uiLParseBehavior & A3D_PARSE_CONTINUE_EVEN_IF_ERROR) == 0)) + break; + } + } + A3DDrawingModelGet(nullptr, &sDrawingModelData); + } + + + CHECK_RET(A3DMiscCascadedAttributesDelete(pCascadedAttr)); + + return iRet; +} diff --git a/exchange/exchangesource/DrawingViewer/drawing_parse.h b/exchange/exchangesource/DrawingViewer/drawing_parse.h new file mode 100644 index 0000000..817efe8 --- /dev/null +++ b/exchange/exchangesource/DrawingViewer/drawing_parse.h @@ -0,0 +1,67 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef __A3DPRCDRAWINGPARSE_H__ +#define __A3DPRCDRAWINGPARSE_H__ + +#include + +#define A3D_PARSE_ERROR 0x0200 +#define A3D_PARSE_CONTINUE_EVEN_IF_ERROR 0x0400 +#define A3D_PARSE_DRAWING_ACTIVE_SHEET 0x0800 + + + +//###################################################################################################################### +#define CHECK_RET(function_call) {\ + iRet = function_call; if(iRet != A3D_SUCCESS) { std::cout << "Error number=" << iRet << std::endl; return iRet; }\ +} + +//###################################################################################################################### +typedef A3DStatus (*A3DCallbackParsePreProcess) (A3DEntity* psEntity, + A3DMiscCascadedAttributes const* pAttribute, + A3DVoid* pGlobalData, + A3DVoid** pFunctionData, + A3DUns32 uiFctBehavior); // entity already parsed + +//###################################################################################################################### +typedef A3DStatus (*A3DCallbackParsePostProcess) (A3DEntity* psEntity, + A3DMiscCascadedAttributes const* pAttribute, + A3DVoid* pGlobalData, + A3DVoid* pFunctionData, + A3DUns32 uiFctBehavior); // error int process + +//###################################################################################################################### +typedef struct +{ + A3DCallbackParsePreProcess m_pfPreProcess; + A3DCallbackParsePostProcess m_pfPostProcess; +} A3DCallbackParse; + +//###################################################################################################################### +typedef struct +{ + A3DUns16 m_usStructSize; /*!< Reserved; must be initialized using the \ref A3D_INITIALIZE_DATA macro. */ + A3DDrawingModel* m_pDrawingModel; + A3DUns32 m_uiParseBehavior; + A3DVoid* m_pGlobalData; + + A3DCallbackParse m_pfSheet; + A3DCallbackParse m_pfView; + A3DCallbackParse m_pfBlockBasic; + A3DCallbackParse m_pfBlockOperator; + A3DCallbackParse m_pfEntity; +} A3DParseDrawingModelData; + +//###################################################################################################################### +A3DStatus A3DParseDrawingModel(A3DParseDrawingModelData const* const pParseData); + +#endif // __A3DPRCDRAWINGPARSE_H__ diff --git a/exchange/exchangesource/DumpFeatureTree/DumpFeatureTree.cpp b/exchange/exchangesource/DumpFeatureTree/DumpFeatureTree.cpp new file mode 100644 index 0000000..80ded0d --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/DumpFeatureTree.cpp @@ -0,0 +1,127 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* DumpFeatureTree.cpp : Defines the entry point for the console application. +* +***********************************************************************************************************************/ + +#define INITIALIZE_A3D_API +#include "DumpFeatureTree.h" + +#define TF_A3DLIBS + +#include +#include +#include +#include + +#include "TreeTraverse.h" +#include "VisitorContainer.h" +#include "VisitorTree.h" +#include "HXFeatureTreeReport.h" + + +A3DVoid _InitializeFontsArray(); +A3DVoid _TerminateFontsArray(); +static A3DStatus TraverseModel(const A3DAsmModelFile* pModelFile, const char * pcOutputFile); + +//=============================== TraverseModel function + +static A3DStatus TraverseModel(const A3DAsmModelFile* pModelFile, const char * pcOutputFile) +{ + // Creation of the ModelFile Connector + A3DModelFileConnector sModelFileConnector(pModelFile); + A3DVisitorContainer sCadVisitorContainer(CONNECT_FEATURE); + sCadVisitorContainer.SetTraverseInstance(true); + + HXFeatureTreeReport * pReport = new HXFeatureTreeReport(&sCadVisitorContainer); + sCadVisitorContainer.push(pReport); + + // Traverse the ModelFile Connector + sModelFileConnector.Traverse(&sCadVisitorContainer); + + pReport->SaveFile((const char *)pcOutputFile); + + return A3D_SUCCESS; +} + + +static MY_CHAR acSrcFileName[_MAX_PATH * 2]; +static MY_CHAR acDstFileName[_MAX_PATH * 2]; +static MY_CHAR acLogFileName[_MAX_PATH * 2]; + +//###################################################################################################################### +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, wchar_t** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + // + // ### COMMAND LINE ARGUMENTS + // + + if (iArgc > 4) + { + MY_PRINTF2("Usage:\n %s [input CAD file] [output XML file] [output LOG file]\n", ppcArgv[0]); + MY_PRINTF(" Default output XML file is [input CAD file].xml\n"); + MY_PRINTF(" Default output LOG file is [output XML file]_Log.txt\n\n"); + return A3D_ERROR; + } + + MY_PRINTF("This sample produces an XML file that is best viewed with a style sheet. \n"); + MY_PRINTF("Please copy FeatureHTML.xsl (found in \\samples\\exchange\\exchangesource\\DumpFeatureTree\\) in your XML output directory for better readability. \n"); + + if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]); + else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD); + + if (iArgc > 2) MY_STRCPY(acDstFileName, ppcArgv[2]); + else MY_SPRINTF(acDstFileName, "%s.xml", acSrcFileName); + + if (iArgc > 3) MY_STRCPY(acLogFileName, ppcArgv[3]); + else MY_SPRINTF(acLogFileName, "%s_Log.txt", acDstFileName); + GetLogFile(acLogFileName); // Initialize log file + + // + // ### INITIALIZE HOOPS EXCHANGE + // + + A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); + CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus); + + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + // + // ### PROCESS SAMPLE CODE + // + + A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + sImport.m_sLoadData.m_sGeneral.m_bReadFeature = TRUE; + sImport.m_sLoadData.m_sGeneral.m_bReadHiddenObjects = TRUE; + sImport.m_sLoadData.m_sGeneral.m_bReadConstructionAndReferences = TRUE; + + A3DStatus iRet = sHoopsExchangeLoader.Import(sImport); + if (iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS) + CHECK_RET(iRet); + + A3DUTF8Char sDstFileNameUTF8[_MAX_PATH]; +#ifdef _MSC_VER + A3DMiscUTF16ToUTF8(acDstFileName, sDstFileNameUTF8); +#else + MY_STRCPY(sDstFileNameUTF8, acDstFileName); +#endif + TraverseModel(sHoopsExchangeLoader.m_psModelFile, sDstFileNameUTF8); + + // + // ### TERMINATE HOOPS EXCHANGE + // + + // Check memory allocations + return (int)ListLeaks(); +} diff --git a/exchange/exchangesource/DumpFeatureTree/DumpFeatureTree.h b/exchange/exchangesource/DumpFeatureTree/DumpFeatureTree.h new file mode 100644 index 0000000..202d5d7 --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/DumpFeatureTree.h @@ -0,0 +1,35 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef __DUMPFEATURETREE_H__ +#define __DUMPFEATURETREE_H__ + +#include + +#ifdef WIN32 +# pragma warning (disable:4090) +# define _CRT_SECURE_NO_DEPRECATE 1 +# ifdef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES +# undef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES +# define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1 +# endif +#else +#define sprintf_s(buf, buf_size, ...) sprintf((buf), __VA_ARGS__) +#endif + +#include + +#include + +#include "../common.hpp" + + +#endif //__DUMPFEATURETREE_H__ diff --git a/exchange/exchangesource/DumpFeatureTree/DumpFeatureTree.vcxproj b/exchange/exchangesource/DumpFeatureTree/DumpFeatureTree.vcxproj new file mode 100644 index 0000000..1d0625c --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/DumpFeatureTree.vcxproj @@ -0,0 +1,173 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {693094D2-1470-4AB4-977E-8D82E5985618} + Win32Proj + DumpFeatureTree + 10.0 + + + + Application + true + v145 + + + Application + false + v145 + true + + + Application + true + v145 + + + Application + false + v145 + true + + + + + + + + + + + + + + + + + + + + + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + .\TinyXML;.\Visitor;%(AdditionalIncludeDirectories) + ProgramDatabase + + + Console + true + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + .\TinyXML;.\Visitor;%(AdditionalIncludeDirectories) + ProgramDatabase + + + Console + true + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + .\TinyXML;.\Visitor;%(AdditionalIncludeDirectories) + + + Console + true + true + true + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + .\TinyXML;.\Visitor;%(AdditionalIncludeDirectories) + + + Console + true + true + true + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/DumpFeatureTree/DumpFeatureTree.vcxproj.filters b/exchange/exchangesource/DumpFeatureTree/DumpFeatureTree.vcxproj.filters new file mode 100644 index 0000000..b36bb57 --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/DumpFeatureTree.vcxproj.filters @@ -0,0 +1,99 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {dddc9323-9971-410b-8d07-549bfd7e0b8d} + + + {b1e8e959-6116-4ed9-aef5-0667e7f234ff} + + + {af568580-5d33-4492-b589-d06c0aebf16c} + + + {2090204c-e091-4087-94ba-87fc4c177522} + + + + + Source Files + + + Source Files\xml + + + Source Files\xml + + + Source Files\xml + + + Source Files\xml + + + Source Files\xml + + + Source Files\xml + + + Source Files + + + Source Files\Visitor + + + Source Files\Visitor + + + Source Files\Visitor + + + + + Header Files + + + Header Files\xml + + + Header Files\xml + + + Header Files\xml + + + Header Files\xml + + + Header Files + + + Header Files\visitor + + + Header Files\visitor + + + Header Files\visitor + + + Header Files\visitor + + + Header Files\visitor + + + \ No newline at end of file diff --git a/exchange/exchangesource/DumpFeatureTree/FeatureHTML.xsl b/exchange/exchangesource/DumpFeatureTree/FeatureHTML.xsl new file mode 100644 index 0000000..b8ca882 --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/FeatureHTML.xsl @@ -0,0 +1,353 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +

+

+ + + +

+ + + +
Feature mode + +
CONTAINER + + + + +
+
CONTAINER_INTERNAL + + +
+
+

+
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + FALSE + + + TRUE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + instance status + + + + + + + + + + + + + + + + + +
+ + +
+
+
+ + + + + + + + + + + + +
+ + +
+ + + + + + + + + + + + +
+ + +
+
+
+
+ + + + + + Link + + + + + + + + + + + + error + + + + + + + + + DrawingBlock + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/exchange/exchangesource/DumpFeatureTree/HXFeatureTreeReport.cpp b/exchange/exchangesource/DumpFeatureTree/HXFeatureTreeReport.cpp new file mode 100644 index 0000000..c8d9083 --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/HXFeatureTreeReport.cpp @@ -0,0 +1,819 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include +#include + +#include "HXmlElement.h" +#include "HXFeatureTreeReport.h" + + +//###################################################################################################################### +int traverseIndexes(const A3DUTF8Char* name, const A3DUns32 uiSize, const A3DUns32* pui, TiXmlElement* setting) +{ + + A3DUns32 gnAllocatedStrings = 0; + A3DUTF8Char gbigstring[65536]; + + if (uiSize > 0) + { + A3DUns32 ui = 0; + TiXmlElement* uints = new TiXmlElement(name); + uints->SetAttribute("size", (int)uiSize); + + // max size of one uint: "%d " 14+1=15 + A3DUns32 uiFormat = 15; + A3DUTF8Char* pc = NULL; + size_t uiMaxSize = sizeof(gbigstring)-1; + if (uiFormat*uiSize > 65536) + { + uiMaxSize = size_t(uiSize * uiFormat); + pc = (A3DUTF8Char*)malloc((uiMaxSize +1) * sizeof(A3DUTF8Char)); + pc[0] = 0; + gnAllocatedStrings++; + } + else + pc = gbigstring; + + // store temporarily indexes in a set so it is stored in ascending order: useful for non regression tests + std::set setIndexes; + for (ui = 0; ui < uiSize; ++ui) + { + setIndexes.insert(pui[ui]); + } + + size_t uiNext = 0; + for (auto const& itSetIndexes : setIndexes) + { + int iwritten = sprintf_s(pc + uiNext, uiMaxSize - uiNext, "%u ", itSetIndexes); + uiNext += size_t(iwritten); + } + pc[uiNext] = 0; + + uints->SetAttribute("indexes", pc); + setting->LinkEndChild(uints); + + if (uiFormat*uiSize > 65536) + free(pc); + } + return A3D_SUCCESS; +} + +//###################################################################################################################### + + +A3DStatus HXFeatureTreeReport::visitEnter(const A3DFRMTreeConnector& /*sConnector*/) +{ + m_failed_count = 0; + m_non_implemented_node_count = 0; + m_non_implemented_subnode_count = 0; + m_mandatory_missing_count = 0; + m_hole_mandatory_missing_count = 0; + m_pattern_mandatory_missing_count = 0; + return A3D_SUCCESS; +} + +A3DStatus HXFeatureTreeReport::visitLeave(const A3DFRMTreeConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +void HXFeatureTreeReport::traverseFeatureStatus(const A3DFRMFeatureConnector& sConnector) +{ + if (sConnector.m_sData.m_sType.m_eStatus == kA3DFRMStatus_Failed) + { + m_sReport.setAttribute("status", "failed"); + + } + else if (sConnector.m_sData.m_sType.m_eStatus != kA3DFRMStatus_Success) + { + m_sReport.setAttribute("status", "non_implemented"); + } +} + + +void HXFeatureTreeReport::traverseFeatureData(const A3DFRMFeatureConnector& sConnector) +{ + A3DFRMIntegerData sIntegerData; + A3DFRMDoubleData sDoubleData; + A3DFRMStringData sStringData; + A3DInt32 iEnumValue; + A3DUTF8Char* pcValueAsString = NULL; + std::ostringstream s; + + switch (sConnector.m_sData.m_eDataType) + { + case kA3DFRMDataInteger: + A3D_INITIALIZE_DATA(A3DFRMIntegerData, sIntegerData); + A3DFRMIntegerDataGet(sConnector.GetA3DEntity(), &sIntegerData); + if (sIntegerData.m_uiValuesSize == 0) + { + m_sReport.setAttribute("data", "empty"); + A3DFRMIntegerDataGet(NULL, &sIntegerData); + return; + } + s << sIntegerData.m_piValues[0]; + for (A3DUns32 i = 1; i < sIntegerData.m_uiValuesSize; ++i) + { + s << ", "; + s << sIntegerData.m_piValues[i]; + if (((i + 1) % 4) == 0) + s << ","; + } + m_sReport.setAttribute("data", s.str().c_str()); + A3DFRMIntegerDataGet(NULL, &sIntegerData); + break; + case kA3DFRMDataDouble: + A3D_INITIALIZE_DATA(A3DFRMDoubleData, sDoubleData); + A3DFRMDoubleDataGet(sConnector.GetA3DEntity(), &sDoubleData); + if (sDoubleData.m_uiValuesSize == 0) + { + m_sReport.setAttribute("data", "empty"); + A3DFRMDoubleDataGet(NULL, &sDoubleData); + return; + } + s << sDoubleData.m_pdValues[0]; + for (A3DUns32 i = 1; i < sDoubleData.m_uiValuesSize; ++i) + { + s << ", "; + s << sDoubleData.m_pdValues[i]; + if (((i + 1) % 4) == 0) + s << ","; + } + m_sReport.setAttribute("data", s.str().c_str()); + A3DFRMDoubleDataGet(NULL, &sDoubleData); + break; + case kA3DFRMDataString: + A3D_INITIALIZE_DATA(A3DFRMStringData, sStringData); + A3DFRMStringDataGet(sConnector.GetA3DEntity(), &sStringData); + if (sStringData.m_uiValuesSize == 0) + { + m_sReport.setAttribute("data", "empty"); + A3DFRMStringDataGet(NULL, &sStringData); + return; + } + s << sStringData.m_ppcValues[0]; + for (A3DUns32 i =1; i < sStringData.m_uiValuesSize; ++i) + { + s << " xts3dx "; + if(sStringData.m_ppcValues[i] == nullptr) + s << "NULL"; + else + s << sStringData.m_ppcValues[i]; + } + m_sReport.setAttribute("data", s.str().c_str()); + A3DFRMStringDataGet(NULL, &sStringData); + break; + case kA3DFRMDataEnum: + A3DFRMEnumDataGet(sConnector.GetA3DEntity(), &iEnumValue, &pcValueAsString); + if (pcValueAsString) + m_sReport.setAttribute("Value", pcValueAsString); + else + m_sReport.setAttribute("Value", iEnumValue); + A3DFRMEnumDataGet(NULL, &iEnumValue, &pcValueAsString); + break; + default: + break; + } +} + + + +A3DStatus HXFeatureTreeReport::visitEnter(const A3DFRMFeatureConnector& sConnector) +{ + switch (sConnector.m_sData.m_sType.m_eFamily) { + case kA3DFamily_Root: + { + m_sReport.createSubNode("NODE"); + m_sReport.addNode(traverseRootBaseData(sConnector.GetA3DEntity())); + m_sReport.setAttribute("data_type", "root"); + switch (sConnector.m_sData.m_sType.m_uiType) { + case kA3DFRMRoot_Node: m_sReport.setAttribute("Root_type", "Node"); break; + case kA3DFRMRoot_Container: m_sReport.setAttribute("Root_type", "Container"); break; + case kA3DFRMRoot_None: + default: m_sReport.setAttribute("Root_type", "unknown"); break; + } + break; + } + case kA3DFamily_Information: + { + m_sReport.createSubNode("FEATURE"); + break; + } + case kA3DFamily_Type: + { + m_sReport.createSubNode("FEATURE"); + m_sReport.setAttribute("data_type", "type"); + switch (sConnector.m_sData.m_sType.m_uiType) { + case kA3DFRMEnumDataType_CAD: m_sReport.setAttribute("Type_type", "CAD_TYPE"); break; + case kA3DFRMEnumDataType_Mode: m_sReport.setAttribute("Type_type", "MODE_TYPE"); break; + case kA3DFRMEnumDataType_Depth: m_sReport.setAttribute("Type_type", "DEPTH_TYPE"); break; + case kA3DFRMEnumDataType_Pattern: m_sReport.setAttribute("Type_type", "PATTERN_TYPE"); break; + case kA3DFRMEnumDataType_HoleShape: m_sReport.setAttribute("Type_type", "HOLE_TYPE"); break; + case kA3DFRMEnumDataType_DepthLevel: m_sReport.setAttribute("Type_type", "DEPTH_LEVEL_TYPE"); break; + case kA3DFRMEnumDataType_Chamfer: m_sReport.setAttribute("Type_type", "CHAMFER_TYPE"); break; + case kA3DFRMEnumDataType_Fillet: m_sReport.setAttribute("Type_type", "FILLET_TYPE"); break; + case kA3DFRMEnumDataType_FilletLength: m_sReport.setAttribute("Type_type", "FILLET_LENGTH_TYPE"); break; + case kA3DFRMEnumDataType_FilletConic: m_sReport.setAttribute("Type_type", "FILLET_CONIC_TYPE"); break; + case kA3DFRMEnumDataType_LengthMode: m_sReport.setAttribute("Type_type", "LENGTH_MODE"); break; + case kA3DFRMEnumDataType_PatternMaster: m_sReport.setAttribute("Type_type", "PATTERN_MASTER_TYPE"); break; + case kA3DFRMEnumDataType_ReferenceMaster: m_sReport.setAttribute("Type_type", "REFERENCE_MASTER_TYPE"); break; + case kA3DFRMDoubleNone: + default: m_sReport.setAttribute("Type_type", "unknown"); break; + } + break; + } + case kA3DFamily_FeatureDefinition: + { + m_sReport.createSubNode("FEATURE"); + m_sReport.setAttribute("data_type", "feature_definition"); + switch (sConnector.m_sData.m_sType.m_uiType) { + case kA3DFRMFeatureDefinitionType_Hole: m_sReport.setAttribute("feature_definition_type", "Hole"); break; + case kA3DFRMFeatureDefinitionType_Pattern: m_sReport.setAttribute("feature_definition_type", "Pattern"); break; + case kA3DFRMFeatureDefinitionType_Sketch: m_sReport.setAttribute("feature_definition_type", "Sketch"); break; + case kA3DFRMFeatureDefinitionType_Thread: m_sReport.setAttribute("feature_definition_type", "Thread"); break; + case kA3DFRMFeatureDefinitionType_Extrude: m_sReport.setAttribute("feature_definition_type", "Extrude"); break; + case kA3DFRMFeatureDefinitionType_Revolve: m_sReport.setAttribute("feature_definition_type", "Revolve"); break; + case kA3DFRMFeatureDefinitionType_Cosmetic: m_sReport.setAttribute("feature_definition_type", "Cosmetic"); break; + case kA3DFRMFeatureDefinitionType_Chamfer: m_sReport.setAttribute("feature_definition_type", "Chamfer"); break; + case kA3DFRMFeatureDefinitionType_Fillet: m_sReport.setAttribute("feature_definition_type", "Fillet"); break; + case kA3DFRMFeatureDefinitionType_Mirror: m_sReport.setAttribute("feature_definition_type", "Mirror"); break; + case kA3DFRMFeatureDefinitionType_Symmetry: m_sReport.setAttribute("feature_definition_type", "Symmetry"); break; + case kA3DFRMFeatureDefinitionType_Translate: m_sReport.setAttribute("feature_definition_type", "Translate"); break; + case kA3DFRMFeatureDefinitionType_Rotate: m_sReport.setAttribute("feature_definition_type", "Rotate"); break; + case kA3DFRMFeatureDefinitionType_None: + default: m_sReport.setAttribute("definition_type", "unknown"); break; + } + break; + } + case kA3DFamily_DoubleData: + { + m_sReport.createSubNode("FEATURE"); + m_sReport.setAttribute("data_type", "double"); + switch (sConnector.m_sData.m_sType.m_uiType) { + case kA3DFRMDoubleValue: m_sReport.setAttribute("double_type", "value"); break; + case kA3DFRMDoubleUnit: m_sReport.setAttribute("double_type", "unit"); break; + case kA3DFRMDoubleOffset: m_sReport.setAttribute("double_type", "offset"); break; + case kA3DFRMDoubleDepth: m_sReport.setAttribute("double_type", "depth"); break; + case kA3DFRMDoubleDiameter: m_sReport.setAttribute("double_type", "diameter"); break; + case kA3DFRMDoubleAngle: m_sReport.setAttribute("double_type", "angle"); break; + case kA3DFRMDoublePitch: m_sReport.setAttribute("double_type", "pitch"); break; + case kA3DFRMDoubleDistance: m_sReport.setAttribute("double_type", "distance"); break; + case kA3DFRMDoubleExtensionAndStep: m_sReport.setAttribute("double_type", "extension_and_step"); break; + case kA3DFRMDoubleLinearParameter: m_sReport.setAttribute("double_type", "linear_parameter"); break; + case kA3DFRMDoubleUVParameter: m_sReport.setAttribute("double_type", "uv_parameter"); break; + case kA3DFRMDoubleRadius: m_sReport.setAttribute("double_type", "radius"); break; + case kA3DFRMDoubleNone: + default: m_sReport.setAttribute("double_type", "unknown"); break; + } + break; + } + case kA3DFamily_IntegerData: + { + m_sReport.createSubNode("FEATURE"); + m_sReport.setAttribute("data_type", "integer"); + switch (sConnector.m_sData.m_sType.m_uiType) { + case kA3DFRMIntegerDataValue: m_sReport.setAttribute("integer_type", "value"); break; + case kA3DFRMIntegerDataBoolean: m_sReport.setAttribute("integer_type", "boolean"); break; + case kA3DFRMIntegerDataIndex: m_sReport.setAttribute("integer_type", "index"); break; + case kA3DFRMIntegerDataKeepSpecification: m_sReport.setAttribute("integer_type", "KeepSpecification"); break; + case kA3DFRMIntegerDataRadialAlignment: m_sReport.setAttribute("integer_type", "RadialAlignment"); break; + case kA3DFRMIntegerDataClockwise: m_sReport.setAttribute("integer_type", "Clockwise"); break; + case kA3DFRMIntegerDataId: m_sReport.setAttribute("integer_type", "id"); break; + case kA3DFRMIntegerDataFlip: m_sReport.setAttribute("integer_type", "flip"); break; + case kA3DFRMIntegerDataType: m_sReport.setAttribute("integer_type", "type"); break; + case kA3DFRMIntegerDataCount: m_sReport.setAttribute("integer_type", "count"); break; + case kA3DFRMIntegerDataSize: m_sReport.setAttribute("integer_type", "size"); break; + case kA3DFRMIntegerDataNbStart: m_sReport.setAttribute("integer_type", "NbStart"); break; + case kA3DFRMIntegerDataNone: + default: m_sReport.setAttribute("integer_type", "unknown"); break; + } + break; + } + case kA3DFamily_StringData: + { + m_sReport.createSubNode("FEATURE"); + m_sReport.setAttribute("data_type", "string"); + switch (sConnector.m_sData.m_sType.m_uiType) { + case kA3DFRMStringDataName: m_sReport.setAttribute("string_type", "name"); break; + case kA3DFRMStringDataAttribute: m_sReport.setAttribute("string_type", "attribute"); break; + case kA3DFRMStringDataType: m_sReport.setAttribute("string_type", "type"); break; + case kA3DFRMStringDataValue: m_sReport.setAttribute("string_type", "value"); break; + case kA3DFRMStringDataNone: + default: m_sReport.setAttribute("double_type", "unknown"); break; + } + break; + } + case kA3DFamily_Value: + { + m_sReport.createSubNode("FEATURE"); + m_sReport.setAttribute("data_type", "value"); + switch (sConnector.m_sData.m_sType.m_uiType) { + case kA3DFRMValueType_Length: m_sReport.setAttribute("value_type", "Length"); break; + case kA3DFRMValueType_Angle: m_sReport.setAttribute("value_type", "Angle"); break; + case kA3DFRMValueType_Diameter: m_sReport.setAttribute("value_type", "Diameter"); break; + case kA3DFRMValueType_Radius: m_sReport.setAttribute("value_type", "Radius"); break; + case kA3DFRMValueType_Depth: m_sReport.setAttribute("value_type", "Depth"); break; + case kA3DFRMValueType_Thickness: m_sReport.setAttribute("value_type", "Thickness"); break; + case kA3DFRMValueType_Offset: m_sReport.setAttribute("value_type", "Offset"); break; + case kA3DFRMValueType_Distance: m_sReport.setAttribute("value_type", "Distance"); break; + case kA3DFRMValueType_Coords: m_sReport.setAttribute("value_type", "Coords"); break; + case kA3DFRMValueType_Vector: m_sReport.setAttribute("value_type", "Vector"); break; + case kA3DFRMValueType_Matrix: m_sReport.setAttribute("value_type", "Matrix"); break; + case kA3DFRMValueType_Area: m_sReport.setAttribute("value_type", "Area"); break; + case kA3DFRMValueType_Volume: m_sReport.setAttribute("value_type", "Volume"); break; + case kA3DFRMValueType_Mass: m_sReport.setAttribute("value_type", "Mass"); break; + case kA3DFRMValueType_Time: m_sReport.setAttribute("value_type", "Time"); break; + case kA3DFRMStringDataNone: + default: m_sReport.setAttribute("double_type", "unknown"); break; + } + break; + } + case kA3DFamily_Definition: + { + m_sReport.createSubNode("FEATURE"); + m_sReport.setAttribute("data_type", "definition"); + switch (sConnector.m_sData.m_sType.m_uiType) { + case kA3DFRMDefinitionType_Depth: m_sReport.setAttribute("definition_type", "Depth"); break; + case kA3DFRMDefinitionType_DepthFrom: m_sReport.setAttribute("definition_type", "DepthFrom"); break; + case kA3DFRMDefinitionType_Position: m_sReport.setAttribute("definition_type", "Position"); break; + case kA3DFRMDefinitionType_Direction: m_sReport.setAttribute("definition_type", "Direction"); break; + case kA3DFRMDefinitionType_Thread: m_sReport.setAttribute("definition_type", "Thread"); break; + case kA3DFRMDefinitionType_Shape: m_sReport.setAttribute("definition_type", "Shape"); break; + case kA3DFRMDefinitionType_Reference: m_sReport.setAttribute("definition_type", "Reference"); break; + case kA3DFRMDefinitionType_Sketch: m_sReport.setAttribute("definition_type", "Sketch"); break; + case kA3DFRMDefinitionType_RevolveAngle: m_sReport.setAttribute("definition_type", "RevolveAngle"); break; + case kA3DFRMDefinitionType_RevolveAngleFrom: m_sReport.setAttribute("definition_type", "RevolveAngleFrom"); break; + case kA3DFRMDefinitionType_Axis: m_sReport.setAttribute("definition_type", "Axis"); break; + case kA3DFRMDefinitionType_Chamfer: m_sReport.setAttribute("definition_type", "Values"); break; + case kA3DFRMDefinitionType_FilletLength: m_sReport.setAttribute("definition_type", "FilletLength"); break; + case kA3DFRMDefinitionType_ReferenceMaster: m_sReport.setAttribute("definition_type", "ReferenceMaster"); break; + case kA3DFRMDefinitionType_None: + default: m_sReport.setAttribute("definition_type", "unknown"); break; + } + break; + } + case kA3DFamily_Definition_Hole: + { + m_sReport.createSubNode("FEATURE"); + m_sReport.setAttribute("data_type", "definition_hole"); + switch (sConnector.m_sData.m_sType.m_uiType) { + case kA3DFRMDefinitionHoleType_RectangularDefinition: m_sReport.setAttribute("definition_hole_type", "RectangularDefinition"); break; + case kA3DFRMDefinitionHoleType_ChamferDefinition: m_sReport.setAttribute("definition_hole_type", "ChamferDefinition"); break; + case kA3DFRMDefinitionHoleType_CboreDefinition: m_sReport.setAttribute("definition_hole_type", "CboreDefinition"); break; + case kA3DFRMDefinitionHoleType_SunkDefinition: m_sReport.setAttribute("definition_hole_type", "SunkDefinition"); break; + case kA3DFRMDefinitionHoleType_TaperedDefinition: m_sReport.setAttribute("definition_hole_type", "TaperedDefinition"); break; + case kA3DFRMDefinitionHoleType_StandardDefinition: m_sReport.setAttribute("definition_hole_type", "StandardDefinition"); break; + case kA3DFRMDefinitionHoleType_ElementDefinition: m_sReport.setAttribute("definition_hole_type", "ElementDefinition"); break; + case kA3DFRMDefinitionHoleType_None: + default: m_sReport.setAttribute("definition_hole_type", "unknown"); break; + break; + } + + break; + } + case kA3DFamily_Definition_Pattern: + { + m_sReport.createSubNode("FEATURE"); + m_sReport.setAttribute("data_type", "definition_pattern"); + switch (sConnector.m_sData.m_sType.m_uiType) { + case kA3DFRMDefinitionPatternType_PatternMaster: m_sReport.setAttribute("definition_pattern_type", "PatternMaster"); break; + case kA3DFRMDefinitionPatternType_PolygonalShape: m_sReport.setAttribute("definition_pattern_type", "PolygonalShape"); break; + case kA3DFRMDefinitionPatternType_SpiralShape: m_sReport.setAttribute("definition_pattern_type", "SpiralShape"); break; + case kA3DFRMDefinitionPatternType_DirectionSpacing: m_sReport.setAttribute("definition_pattern_type", "DirectionSpacing"); break; + case kA3DFRMDefinitionPatternType_AxialSpacing: m_sReport.setAttribute("definition_pattern_type", "AxialSpacing"); break; + case kA3DFRMDefinitionPatternType_RadialSpacing: m_sReport.setAttribute("definition_pattern_type", "RadialSpacing"); break; + case kA3DFRMDefinitionPatternType_PolygonalSpacing: m_sReport.setAttribute("definition_pattern_type", "PolygonalSpacing"); break; + case kA3DFRMDefinitionPatternType_SpiralSpacing: m_sReport.setAttribute("definition_pattern_type", "SpiralSpacing"); break; + case kA3DFRMDefinitionPatternType_InstanceStatus: m_sReport.setAttribute("definition_pattern_type", "InstanceStatus"); break; + case kA3DFRMDefinitionPatternType_InstanceInformation:m_sReport.setAttribute("definition_pattern_type", "InstanceInformation"); break; + case kA3DFRMDefinitionPatternType_None: + default: m_sReport.setAttribute("definition_pattern_type", "unknown"); break; + break; + } + break; + } + case kA3DFamily_Definition_Thread: + { + m_sReport.createSubNode("FEATURE"); + m_sReport.setAttribute("data_type", "definition_thread"); + switch (sConnector.m_sData.m_sType.m_uiType) { + case kA3DFRMDefinitionThreadType_Undercut: m_sReport.setAttribute("definition_thread_type", "Undercut"); break; + case kA3DFRMDefinitionThreadType_Shaft: m_sReport.setAttribute("definition_thread_type", "Shaft"); break; + case kA3DFRMDefinitionThreadType_None: + default: m_sReport.setAttribute("definition_thread_type", "unknown"); break; + break; + } + break; + } + default: + { + m_sReport.createSubNode("FEATURE"); + m_sReport.setAttribute("data_type", "unknown"); + } + } + traverseFeatureStatus(sConnector); + traverseFeatureData(sConnector); + + + return A3D_SUCCESS; +} + +A3DStatus HXFeatureTreeReport::visitLeave(const A3DFRMFeatureConnector& /*sConnector*/) +{ + m_sReport.closeSubNode(); + return A3D_SUCCESS; +} + +HXmlElement* HXFeatureTreeReport::traverseA3DMiscReferenceOnTessData(const A3DMiscEntityReference* pEntityReference) +{ + A3DMiscReferenceOnTessData sReferenceOnTessData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnTessData, sReferenceOnTessData); + if (A3DMiscReferenceOnTessGet(pEntityReference, &sReferenceOnTessData) != A3D_SUCCESS) + return NULL; + + HXmlElement* pXmlReferenceOnTess = new HXmlElement("ReferenceOnTess"); + + pXmlReferenceOnTess->SetAttribute("topotype", "Face"); + if (sReferenceOnTessData.m_uiSize == 0) + pXmlReferenceOnTess->SetAttribute("ref_count", "error"); + + for (A3DUns32 iFace = 0; iFace < sReferenceOnTessData.m_uiSize; iFace++) + pXmlReferenceOnTess->SetAttribute("face_indice", sReferenceOnTessData.m_puiAdditionalIndexes[iFace]); + + A3DMiscReferenceOnTessGet(NULL, &sReferenceOnTessData); + + return pXmlReferenceOnTess; +} + + +HXmlElement* HXFeatureTreeReport::traverseA3DMiscReferenceOnCsysItem(const A3DMiscReferenceOnCsysItem* pEntityReference) +{ + HXmlElement* pXmlReferenceOnCsysItem = new HXmlElement("ReferenceOnCsysItem"); + + A3DMiscReferenceOnCsysItemData sA3DMiscReferenceOnCSYSITemData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnCsysItemData, sA3DMiscReferenceOnCSYSITemData); + A3DStatus iRet = A3DMiscReferenceOnCsysItemGet(pEntityReference, &sA3DMiscReferenceOnCSYSITemData); + if (iRet != A3D_SUCCESS || !sA3DMiscReferenceOnCSYSITemData.m_pCoordinateSystem) + { + pXmlReferenceOnCsysItem->SetAttribute("error_A3DMiscReferenceOnCsysItemGet", iRet); + return pXmlReferenceOnCsysItem; + } + A3DRootBaseData sCSYSRootData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sCSYSRootData); + if (A3DRootBaseGet(sA3DMiscReferenceOnCSYSITemData.m_pCoordinateSystem, &sCSYSRootData) == A3D_SUCCESS) + { + pXmlReferenceOnCsysItem->SetAttribute("cys_name", (sCSYSRootData.m_pcName && sCSYSRootData.m_pcName[0] != '\0') ? sCSYSRootData.m_pcName : "NULL"); + pXmlReferenceOnCsysItem->SetAttribute("index", sA3DMiscReferenceOnCSYSITemData.m_uiIndex); + A3DRootBaseGet(NULL,&sCSYSRootData); + } + return pXmlReferenceOnCsysItem; +} + +HXmlElement* HXFeatureTreeReport::traverseReferenceOnTopology(const A3DMiscReferenceOnTopology* pEntityReference) +{ + A3DMiscReferenceOnTopologyData sReferenceOnTopologyData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnTopologyData, sReferenceOnTopologyData); + HXmlElement* pXmReferenceOnTopology = new HXmlElement("ReferenceOnTopology"); + if (A3DMiscReferenceOnTopologyGet((A3DMiscReferenceOnTopology*)pEntityReference, &sReferenceOnTopologyData) != A3D_SUCCESS) + { + pXmReferenceOnTopology->SetAttribute("error", "A3DMiscReferenceOnTopologyGet"); + return pXmReferenceOnTopology; + } + A3DUns32 i = 0; + char acName[255]; + switch (sReferenceOnTopologyData.m_eTopoItemType) + { + case kA3DTypeTopoEdge: + pXmReferenceOnTopology->SetAttribute("topo_type", "Edge"); + if (!(sReferenceOnTopologyData.m_uiSize != 3)) + { + pXmReferenceOnTopology->SetAttribute("ref_count", "error"); + break; + } + while (i + 2 < sReferenceOnTopologyData.m_uiSize) + { + sprintf_s(acName, sizeof(acName)-1,"%d %d %d", + sReferenceOnTopologyData.m_puiAdditionalIndexes[i], + sReferenceOnTopologyData.m_puiAdditionalIndexes[i+1], + sReferenceOnTopologyData.m_puiAdditionalIndexes[i+2]); + pXmReferenceOnTopology->SetAttribute("face/loop/edge indexes", acName); + i+=3; + } + break; + case kA3DTypeTopoCoEdge: + pXmReferenceOnTopology->SetAttribute("topotype", "CoEdge"); + if (!(sReferenceOnTopologyData.m_uiSize % 3)) + { + pXmReferenceOnTopology->SetAttribute("ref_count", "error"); + break; + } + while (i + 2 < sReferenceOnTopologyData.m_uiSize) + { + sprintf_s(acName, sizeof(acName) - 1, "%d %d %d", + sReferenceOnTopologyData.m_puiAdditionalIndexes[i], + sReferenceOnTopologyData.m_puiAdditionalIndexes[i+1], + sReferenceOnTopologyData.m_puiAdditionalIndexes[i+2]); + pXmReferenceOnTopology->SetAttribute("face/loop/coedge indexes", acName); + i+=3; + } + break; + case kA3DTypeTopoFace: + pXmReferenceOnTopology->SetAttribute("topotype", "Face"); + traverseIndexes("face_indexes", sReferenceOnTopologyData.m_uiSize, sReferenceOnTopologyData.m_puiAdditionalIndexes, pXmReferenceOnTopology); + break; + case kA3DTypeTopoUniqueVertex: + pXmReferenceOnTopology->SetAttribute("topotype", "Unique Vertex"); + if (!(sReferenceOnTopologyData.m_uiSize %= 4)) + { + pXmReferenceOnTopology->SetAttribute("ref_count", "error"); + break; + } + while (i + 3 < sReferenceOnTopologyData.m_uiSize) + { + sprintf_s(acName, sizeof(acName) - 1, "%d %d %d %d", + sReferenceOnTopologyData.m_puiAdditionalIndexes[i], + sReferenceOnTopologyData.m_puiAdditionalIndexes[i+1], + sReferenceOnTopologyData.m_puiAdditionalIndexes[i+2], + sReferenceOnTopologyData.m_puiAdditionalIndexes[i+3]); + pXmReferenceOnTopology->SetAttribute("face/loop/edge/vertex indexes", acName); + i+=4; + } + break; + case kA3DTypeTopoMultipleVertex: + pXmReferenceOnTopology->SetAttribute("topotype", "Multiple Vertex"); + if (!(sReferenceOnTopologyData.m_uiSize % 4 != 0)) + { + pXmReferenceOnTopology->SetAttribute("ref_count", "error"); + break; + } + while (i + 3 < sReferenceOnTopologyData.m_uiSize) + { + sprintf_s(acName, sizeof(acName) - 1, "%d %d %d %d", + sReferenceOnTopologyData.m_puiAdditionalIndexes[i], + sReferenceOnTopologyData.m_puiAdditionalIndexes[i+1], + sReferenceOnTopologyData.m_puiAdditionalIndexes[i+2], + sReferenceOnTopologyData.m_puiAdditionalIndexes[i+3]); + pXmReferenceOnTopology->SetAttribute("face/loop/edge/vertex indexes", acName); + i+=4; + } + break; + default: + pXmReferenceOnTopology->SetAttribute("linked_item_topo_reference", "unexpected"); + break; + } + A3DMiscReferenceOnTopologyGet(NULL,&sReferenceOnTopologyData); + return pXmReferenceOnTopology; +} + + +void HXFeatureTreeReport::traverseDrawingBlock(const A3DDrawingBlockBasic *pDrwBlock) +{ + A3DInt32 iRet = A3D_SUCCESS; + + A3DDrawingBlockBasicData sDrwBlockData; + A3D_INITIALIZE_DATA(A3DDrawingBlockBasicData, sDrwBlockData); + + m_sReport.createSubNode("DrawingBlock"); + + if ((iRet = A3DDrawingBlockBasicGet((A3DDrawingBlockBasic const*)pDrwBlock, &sDrwBlockData)) == A3D_SUCCESS) + { + m_sReport.addNode(traverseRootBaseData(pDrwBlock)); + m_sReport.setAttribute("Entity_count", (int)sDrwBlockData.m_uiDrwEntitiesSize); + m_sReport.setAttribute("Markup_count", (int)sDrwBlockData.m_uiMarkupsSize); + m_sReport.setAttribute("SubBlock_count", (int)sDrwBlockData.m_uiDrwBlocksSize); + + m_sReport.createSubNode("Subblock"); + { + for (A3DUns32 ui = 0; ui < sDrwBlockData.m_uiDrwBlocksSize; ++ui) + traverseDrawingBlock(sDrwBlockData.m_ppDrwBlocks[ui]); + } + m_sReport.closeSubNode(); + A3DDrawingBlockBasicGet(NULL,&sDrwBlockData); + } + m_sReport.closeSubNode(); +} + +void HXFeatureTreeReport::traverseEntityReference(const A3DEntity* pEntityReference) +{ + A3DInt32 iRet = A3D_SUCCESS; + A3DMiscEntityReferenceData sData; + A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sData); + + A3DEEntityType eType = kA3DTypeUnknown; + iRet = A3DEntityGetType(pEntityReference, &eType); + if (iRet != A3D_SUCCESS) + { + HXmlElement* entityreference = new HXmlElement("A3DEntityGetType"); + entityreference->SetAttribute("error", iRet); + m_sReport.addNode(entityreference); + } + + if (eType == kA3DTypeMiscReferenceOnTopology) + { + m_sReport.addNode(traverseReferenceOnTopology(pEntityReference)); + } + else if (eType == kA3DTypeMiscReferenceOnCsysItem) + { + m_sReport.addNode(traverseA3DMiscReferenceOnCsysItem(pEntityReference)); + } + else if (eType == kA3DTypeFRMFeature) + { + m_sReport.addNode(traverseRootBaseData(pEntityReference)); + } + else if (eType == kA3DTypeDrawingBlockBasic) + { + traverseDrawingBlock((const A3DDrawingBlockBasic *)pEntityReference); + } + else + { + m_sReport.addNode(traverseRootBaseData(pEntityReference)); + + if (eType == kA3DTypeRiPolyBrepModel) + { + m_sReport.addNode(traverseA3DMiscReferenceOnTessData(pEntityReference)); + } + else if (eType == kA3DTypeRiPlane) + { + A3DMiscMarkupLinkedItem* pLinkedItem = NULL; + A3DRiPlaneSupportGet((const A3DRiPlane*)pEntityReference, &pLinkedItem); + if (pLinkedItem) + { + m_sReport.createSubNode("SUPPORT"); + { + iRet = A3DMiscEntityReferenceGet(pLinkedItem, &sData); + if (iRet != A3D_SUCCESS || sData.m_pEntity == NULL) + { + HXmlElement* entityreference = new HXmlElement("A3DMiscEntityReferenceGet"); + entityreference->SetAttribute("error", iRet); + m_sReport.addNode(entityreference); + } + traverseEntityReference(sData.m_pEntity); + m_sReport.closeSubNode(); + } + } + + } + else if (eType == kA3DTypeRiCurve) + { + A3DMiscMarkupLinkedItem* pLinkedItem = NULL; + A3DRiCurveSupportGet((const A3DRiCurve*)pEntityReference, &pLinkedItem); + if (pLinkedItem) + { + m_sReport.createSubNode("SUPPORT"); + { + iRet = A3DMiscEntityReferenceGet(pLinkedItem, &sData); + if (iRet != A3D_SUCCESS || sData.m_pEntity == NULL) + { + HXmlElement* entityreference = new HXmlElement("A3DMiscEntityReferenceGet"); + entityreference->SetAttribute("error", iRet); + m_sReport.addNode(entityreference); + } + traverseEntityReference(sData.m_pEntity); + m_sReport.closeSubNode(); + } + } + } + } + A3DMiscEntityReferenceGet(NULL, &sData); + + +} + +A3DStatus HXFeatureTreeReport::visitEnter(const A3DFRMLinkedItemConnector& sConnector) +{ + m_sReport.createSubNode("Connection"); + switch (sConnector.m_sData.m_eType) + { + case kA3DFRMLink_Outcome: + m_sReport.setAttribute("Type", "Outcome"); + break; + case kA3DFRMLink_Construction: + m_sReport.setAttribute("Type", "Construction"); + break; + case kA3DFRMLink_Position: + m_sReport.setAttribute("Type", "Position"); + break; + case kA3DFRMLink_Support: + m_sReport.setAttribute("Type", "Support"); + break; + default: + m_sReport.setAttribute("Type", "Unknown"); + break; + } + if (sConnector.m_sData.m_pReference) + traverseEntityReference(sConnector.m_sData.m_pReference); + else + { + HXmlElement* entityreference = new HXmlElement("A3DFRMFeatureLinkedItemConnector"); + entityreference->SetAttribute("error", "no reference"); + m_sReport.addNode(entityreference); + } + + return A3D_SUCCESS; +} +A3DStatus HXFeatureTreeReport::visitLeave(const A3DFRMLinkedItemConnector& /*sConnector*/) +{ + m_sReport.closeSubNode(); + return A3D_SUCCESS; +} + +A3DStatus HXFeatureTreeReport::visitEnter(const A3DFRMParameterConnector& sConnector) +{ + switch (sConnector.m_sData.m_eType) + { + case kA3DParameterType_None: + { + m_sReport.createSubNode("ROOT"); + break; + } + case kA3DParameterType_Information: + { + m_sReport.createSubNode("INFORMATION"); + break; + } + case kA3DParameterType_Type: + { + m_sReport.createSubNode("TYPE"); + break; + } + case kA3DParameterType_Specification: + { + m_sReport.createSubNode("SPECIFICATION"); + break; + } + case kA3DParameterType_FeatureDefinition: + { + m_sReport.createSubNode("FEATURE_DEFINITION"); + break; + } + case kA3DParameterType_Definition: + { + m_sReport.createSubNode("DEFINITION"); + break; + } + case kA3DParameterType_Container: + { + m_sReport.createSubNode("CONTAINER"); + break; + } + case kA3DParameterType_ContainerInternal: + { + m_sReport.createSubNode("CONTAINER_INTERNAL"); + break; + } + case kA3DParameterType_Data: + { + m_sReport.createSubNode("DATA"); + break; + } + default: + m_sReport.createSubNode("PARAMETER"); + break; + } + return A3D_SUCCESS; +} + +A3DStatus HXFeatureTreeReport::visitLeave(const A3DFRMParameterConnector& /*sConnector*/) +{ + m_sReport.closeSubNode(); + return A3D_SUCCESS; +} + +HXmlElement* HXFeatureTreeReport::traverseRootBaseData(const A3DEntity* pEntity) +{ + A3DRootBaseData sRBData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sRBData); + A3DStatus iRet2 = A3DRootBaseGet(pEntity, &sRBData); + if (iRet2 != A3D_SUCCESS) + return NULL; + HXmlElement* pXmlRootBaseData = new HXmlElement("RootBaseData"); + if (sRBData.m_pcName && sRBData.m_pcName[0] != '\0') + pXmlRootBaseData->SetAttribute("m_pcName", sRBData.m_pcName); + + pXmlRootBaseData->SetAttribute("m_uiPersistentId", sRBData.m_uiPersistentId); + pXmlRootBaseData->SetAttribute("m_uiNonPersistentId", sRBData.m_uiNonPersistentId); + A3DRootBaseGet(NULL, &sRBData); + return pXmlRootBaseData; +} + + +bool HXFeatureTreeReport::isAlreadyTreadted(const A3DFRMFeatureConnector& sFeature) +{ + std::vector::iterator feature = m_apAlreadyparsedFeatures.begin(); + for (; feature != m_apAlreadyparsedFeatures.end(); ++feature) { + if (*feature == sFeature.GetA3DEntity()) + return FALSE; + } + m_apAlreadyparsedFeatures.push_back(sFeature.GetA3DEntity()); + return TRUE; +} \ No newline at end of file diff --git a/exchange/exchangesource/DumpFeatureTree/HXFeatureTreeReport.h b/exchange/exchangesource/DumpFeatureTree/HXFeatureTreeReport.h new file mode 100644 index 0000000..2d5b6cf --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/HXFeatureTreeReport.h @@ -0,0 +1,70 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +#pragma once +#ifndef __HTREEDUMP_H__ +#define __HTREEDUMP_H__ + +#include "Visitors.h" +#include "tinyxml.h" +#include "HXmlReport.h" + +class HXFeatureTreeReport: public A3DVisitor +{ +public: + HXFeatureTreeReport(A3DVisitorContainer* pContainer): + A3DVisitor("FeatureTreeReport", pContainer), + m_failed_count(0), + m_non_implemented_node_count(0), + m_non_implemented_subnode_count(0), + m_mandatory_missing_count(0), + m_hole_mandatory_missing_count(0), + m_pattern_mandatory_missing_count(0) + {} + virtual ~HXFeatureTreeReport() {} + + inline void SaveFile(const A3DUTF8Char* pcReportPath) { m_sReport.SaveFile(pcReportPath, "FeatureHTML.xsl"); } + + virtual A3DStatus visitEnter(const A3DFRMTreeConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFRMTreeConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DFRMParameterConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFRMParameterConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DFRMFeatureConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFRMFeatureConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DFRMLinkedItemConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFRMLinkedItemConnector& sConnector); + +private: + int m_failed_count; + int m_non_implemented_node_count; + int m_non_implemented_subnode_count; + int m_mandatory_missing_count; + int m_hole_mandatory_missing_count; + int m_pattern_mandatory_missing_count; + HXmlReport m_sReport; + std::vector m_apAlreadyparsedFeatures; + + bool isAlreadyTreadted(const A3DFRMFeatureConnector& sFeature); + + HXmlElement* traverseRootBaseData(const A3DEntity* pEntity); + HXmlElement* traverseReferenceOnTopology(const A3DMiscReferenceOnTopology* pEntityReference); + HXmlElement* traverseA3DMiscReferenceOnCsysItem(const A3DMiscReferenceOnCsysItem* pEntityReference); + HXmlElement* traverseA3DMiscReferenceOnTessData(const A3DMiscEntityReference* pEntityReference); + + void traverseEntityReference(const A3DEntity* pEntityReference); + void traverseDrawingBlock(const A3DDrawingBlockBasic* pEntityReference); + void traverseFeatureStatus(const A3DFRMFeatureConnector& sFeature); + void traverseFeatureData(const A3DFRMFeatureConnector& sFeature); +}; + +#endif // __HTREEDUMP_H__ diff --git a/exchange/exchangesource/DumpFeatureTree/HXmlElement.cpp b/exchange/exchangesource/DumpFeatureTree/HXmlElement.cpp new file mode 100644 index 0000000..0ab8fe7 --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/HXmlElement.cpp @@ -0,0 +1,164 @@ +#include "HXmlElement.h" + +#ifdef COMPUTE_RTF_STRING +#include +#endif + +HXmlElement* HXmlElement::add_element( const char* pcText) +{ + HXmlElement* psElement = new HXmlElement(pcText); + this->LinkEndChild( psElement); + return psElement; +} +HXmlElement* HXmlElement::add_element_with_id( const char* pcText, const char* pcTextId) +{ + HXmlElement* psElement = new HXmlElement(pcText); + this->LinkEndChild( psElement); + psElement->SetAttribute("id", pcTextId); + return psElement; +} +HXmlElement* HXmlElement::add_header( const char* pcText) +{ + HXmlElement* psElementHeader = this->add_element("h2"); + psElementHeader->LinkEndChild( new TiXmlText(pcText)); + return psElementHeader; +} +#ifdef COMPUTE_RTF_STRING +void HXmlElement::add_value( const char* pcValue, bool bRTF) +{ + if(bRTF == false) + { + this->LinkEndChild( new TiXmlText(pcValue)); + } + char acAttributValue[1024]; + //A3DVoid* pRTFData = NULL; + A3DUTF8Char* pRTFString = (A3DUTF8Char*)pcValue; + A3DMkpRTFField* pRTF = NULL; + + if (A3DMkpRTFFieldCreate(pRTFString, &pRTF) == A3D_SUCCESS) + { + A3DMkpRTFFieldData sRTFFieldData; + A3D_INITIALIZE_DATA(A3DRTFFieldData, sRTFFieldData); + + //add_element( "rtf - "); + while (A3DMkpRTFFieldGet(pRTF, &sRTFFieldData) == A3D_SUCCESS) + { + if(sRTFFieldData.m_pcFamilyName) + sprintf(acAttributValue, "font-family:%s;", sRTFFieldData.m_pcFamilyName); + this->SetAttribute("style", acAttributValue); + this->LinkEndChild(new TiXmlText(sRTFFieldData.m_pcText)); + + A3DMkpRTFFieldGet(NULL, &sRTFFieldData); + } + //add_element( " -"); + + A3DMkpRTFFieldDelete(pRTF); + } +} +#else +void HXmlElement::add_value( const char* pcValue, bool /*bRTF*/) +{ + this->LinkEndChild( new TiXmlText(pcValue)); +} +#endif + +void HXmlElement::add_value(double dValue, int idecimal) +{ + char acValue[1024]; + snprintf(acValue,sizeof(acValue), "%.*f", idecimal, dValue); + return add_value(acValue); +} +void HXmlElement::add_value(int iValue) +{ + char acValue[1024]; + snprintf(acValue, sizeof(acValue), " %d", iValue); + return add_value(acValue); +} +HXmlElement* HXmlElement::add_element_and_value( char* pcText, const char* pcValue, bool bRTF) +{ + HXmlElement* psElement = new HXmlElement(pcText); + psElement->add_value( pcValue, bRTF); + //psElement->LinkEndChild( new TiXmlText(pcValue)); + this->LinkEndChild( psElement); + return psElement; +} + +HXmlElement* HXmlElement::add_element_and_value( char* pcText, double dValue) +{ + char acValue[1024]; + snprintf(acValue, sizeof(acValue), "%f", dValue); + return add_element_and_value( pcText, acValue); +} + +HXmlElement* HXmlElement::add_element_and_value( char* pcText, int iValue) +{ + char acValue[1024]; + snprintf(acValue, sizeof(acValue), "%d", iValue); + return add_element_and_value( pcText, acValue); +} + +HXmlElement* HXmlElement::add_element_and_value( char* pcText, double dValue, int idecimal) +{ + char acValue[1024]; + snprintf(acValue, sizeof(acValue), "%.*f", idecimal, dValue); + return add_element_and_value( pcText, acValue); +} + + + +void HXmlTableRow::add_cell( char* pcText, int span_count) +{ + TiXmlElement* psCell = add_element( "TD"); + psCell->LinkEndChild( new TiXmlText(pcText)); + char acValue[1024]; + if(span_count>0) + { + snprintf(acValue, sizeof(acValue), "%d", span_count); + psCell->SetAttribute("rowspan", acValue); + } + else if(span_count<0) + { + snprintf(acValue, sizeof(acValue), "%d", -1*span_count); + psCell->SetAttribute("colspan", acValue); + } +} + + +void HXmlTableRow::add_cell( char* pcText, int row_span, int col_span) +{ + TiXmlElement* psCell = add_element( "TD"); + psCell->LinkEndChild( new TiXmlText(pcText)); + char acValue[1024]; + snprintf(acValue, sizeof(acValue), "%d", row_span); + psCell->SetAttribute("rowspan", acValue); + snprintf(acValue, sizeof(acValue), "%d", col_span); + psCell->SetAttribute("colspan", acValue); +} + +void HXmlTableRow::add_cell_double( double dValue, int span_count) +{ + char acValue[1024]; + snprintf(acValue, sizeof(acValue), "%f", dValue); + add_cell( acValue, span_count); +} +void HXmlTableRow::add_cell_int( int iValue, int span_count) +{ + char acValue[1024]; + snprintf(acValue, sizeof(acValue), "%d", iValue); + add_cell( acValue, span_count); +} + +void HXmlTableRow::add_cell_double_formated( double dValue, int idecimal, int span_count) +{ + char acValue[1024]; + snprintf(acValue, sizeof(acValue), "%.*f", idecimal, dValue); + add_cell( acValue, span_count); +} + + + +void HXmlTableRow::add_rtf_cell( char* /*pcText*/, int span_count) +{ + add_cell( "rtf", span_count); +} + diff --git a/exchange/exchangesource/DumpFeatureTree/HXmlElement.h b/exchange/exchangesource/DumpFeatureTree/HXmlElement.h new file mode 100644 index 0000000..3462829 --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/HXmlElement.h @@ -0,0 +1,54 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef __XMLELEMENT__ +#define __XMLELEMENT__ + +#ifndef WIN32 +#define sprintf_s(buf, buf_size, ...) sprintf((buf), __VA_ARGS__) +#endif +#include "tinyxml.h" +class HXmlElement : public TiXmlElement +{ +public: + HXmlElement (const char * in_value):TiXmlElement(in_value){} + virtual ~HXmlElement() {} + HXmlElement* add_element( const char* pcText); + //html + HXmlElement* add_element_with_id( const char* pcText, const char* pcTextId); + void add_value( const char* pcValue, bool bRTF = false); + void add_value(double dValue, int idecimal); + void add_value(int iValue); + HXmlElement* add_header( const char* pcText); + + HXmlElement* add_element_and_value( char* pcText, const char* pcValue, bool bRTF = false); + HXmlElement* add_element_and_value( char* pcText, int iValue); + HXmlElement* add_element_and_value( char* pcText, double dValue); + HXmlElement* add_element_and_value( char* pcText, double dValue, int idecimal); +}; + +class HXmlTableRow : public HXmlElement +{ +public: + HXmlTableRow ():HXmlElement("TR"){} + ~HXmlTableRow() {} + +public: + void add_cell( char* pcText, int span_count = 0); + void add_cell( char* pcText, int row_span, int col_span); + void add_cell_double( double dValue, int span_count = 0); + void add_cell_double_formated( double dValue, int idecimal, int span_count); + void add_cell_int( int iValue, int span_count = 0); + void add_rtf_cell( char* pcText, int span_count = 0); +}; + + +#endif //__XMLELEMENT__ diff --git a/exchange/exchangesource/DumpFeatureTree/HXmlReport.cpp b/exchange/exchangesource/DumpFeatureTree/HXmlReport.cpp new file mode 100644 index 0000000..3fa781f --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/HXmlReport.cpp @@ -0,0 +1,84 @@ +#include "HXmlReport.h" + +#include + +HXmlReport::HXmlReport() +{ + HXmlElement* psXmlElement = new HXmlElement("Root"); + m_apPath.push_back(psXmlElement); + psXmlElement->SetAttribute("rel", "stylesheet"); + m_sDocument.LinkEndChild(psXmlElement); +} +HXmlReport::~HXmlReport() +{ +} + +void HXmlReport::SaveFile(const char* pcReportPath, const char* pcXslFile) +{ + m_sDocument.SetCondenseWhiteSpace(false); + + if (pcXslFile) + { + // stylesheet metadata are not supported by tinyXML + // => we have to add xsl link manually at the beginning of the xml file + + // Instead of directly write into file, plug a printer to XML document, to "write" xml in a std::string + TiXmlPrinter printer; + m_sDocument.Accept(&printer); + + // Write xst information + printer string into file + std::ofstream ofs; + ofs.open(pcReportPath, std::ofstream::out); + ofs << "" << std::endl; + ofs << "" << std::endl; + ofs << printer.CStr(); + ofs.close(); + } + else + { + if (m_sDocument.SaveFile(pcReportPath)) + fprintf(stdout, "XML file saved as %s\n", pcReportPath); + else + fprintf(stdout, "Cannot create XML file %s\n", pcReportPath); + fflush(stdout); + } +} + +void HXmlReport::closeSubNode() +{ + if (m_apPath.empty()) + { + //can remove root note + return; + } + m_apPath.pop_back(); +} + +void HXmlReport::addNode(HXmlElement* psNewNode) +{ + if(psNewNode == NULL) + return; + if (m_apPath.empty()) + { + //no tree create + return; + } + + m_apPath.back()->LinkEndChild(psNewNode); +} + +void HXmlReport::createSubNode(const char* pcNameNode) +{ + HXmlElement*psNewNode = new HXmlElement(pcNameNode); + if (psNewNode == NULL) + return; + if (m_apPath.empty()) + { + //no tree create + return; + } + + m_apPath.back()->LinkEndChild(psNewNode); + m_apPath.push_back(psNewNode); + +} \ No newline at end of file diff --git a/exchange/exchangesource/DumpFeatureTree/HXmlReport.h b/exchange/exchangesource/DumpFeatureTree/HXmlReport.h new file mode 100644 index 0000000..a8e2f25 --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/HXmlReport.h @@ -0,0 +1,44 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +#pragma once +#ifndef __HECXMLREPORT_H__ +#define __HECXMLREPORT_H__ + +#include "HXmlElement.h" +#include + +class HXmlReport +{ + TiXmlDocument m_sDocument; + std::vector< HXmlElement*> m_apPath; + +public: + HXmlReport(); + ~HXmlReport(); + +public: + //==================================tree manipulation======================== + + inline HXmlElement* currentNode() const { return m_apPath.back(); } + void closeSubNode(); + void addNode(HXmlElement* psNewNode); + void createSubNode(const char* pcNameNode); + void SaveFile(const char* pcReportPath, const char* pcXslFile = NULL); + //==================================populate current node======================== + +public: + inline void setAttribute(const char* name, const char * _value) { currentNode()->SetAttribute(name, _value); } + inline void setAttribute(const char * name, int value) { currentNode()->SetAttribute(name, value); } + inline void setAttribute(const char * name, double value) { currentNode()->SetDoubleAttribute(name, value); } +}; + + +#endif \ No newline at end of file diff --git a/exchange/exchangesource/DumpFeatureTree/TinyXML/tinystr.cpp b/exchange/exchangesource/DumpFeatureTree/TinyXML/tinystr.cpp new file mode 100644 index 0000000..0665768 --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/TinyXML/tinystr.cpp @@ -0,0 +1,111 @@ +/* +www.sourceforge.net/projects/tinyxml + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + + +#ifndef TIXML_USE_STL + +#include "tinystr.h" + +// Error value for find primitive +const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type >(-1); + + +// Null rep. +TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } }; + + +void TiXmlString::reserve (size_type cap) +{ + if (cap > capacity()) + { + TiXmlString tmp; + tmp.init(length(), cap); + memcpy(tmp.start(), data(), length()); + swap(tmp); + } +} + + +TiXmlString& TiXmlString::assign(const char* str, size_type len) +{ + size_type cap = capacity(); + if (len > cap || cap > 3*(len + 8)) + { + TiXmlString tmp; + tmp.init(len); + memcpy(tmp.start(), str, len); + swap(tmp); + } + else + { + memmove(start(), str, len); + set_size(len); + } + return *this; +} + + +TiXmlString& TiXmlString::append(const char* str, size_type len) +{ + size_type newsize = length() + len; + if (newsize > capacity()) + { + reserve (newsize + capacity()); + } + memmove(finish(), str, len); + set_size(newsize); + return *this; +} + + +TiXmlString operator + (const TiXmlString & a, const TiXmlString & b) +{ + TiXmlString tmp; + tmp.reserve(a.length() + b.length()); + tmp += a; + tmp += b; + return tmp; +} + +TiXmlString operator + (const TiXmlString & a, const char* b) +{ + TiXmlString tmp; + TiXmlString::size_type b_len = static_cast( strlen(b) ); + tmp.reserve(a.length() + b_len); + tmp += a; + tmp.append(b, b_len); + return tmp; +} + +TiXmlString operator + (const char* a, const TiXmlString & b) +{ + TiXmlString tmp; + TiXmlString::size_type a_len = static_cast( strlen(a) ); + tmp.reserve(a_len + b.length()); + tmp.append(a, a_len); + tmp += b; + return tmp; +} + + +#endif // TIXML_USE_STL diff --git a/exchange/exchangesource/DumpFeatureTree/TinyXML/tinystr.h b/exchange/exchangesource/DumpFeatureTree/TinyXML/tinystr.h new file mode 100644 index 0000000..89cca33 --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/TinyXML/tinystr.h @@ -0,0 +1,305 @@ +/* +www.sourceforge.net/projects/tinyxml + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + + +#ifndef TIXML_USE_STL + +#ifndef TIXML_STRING_INCLUDED +#define TIXML_STRING_INCLUDED + +#include +#include + +/* The support for explicit isn't that universal, and it isn't really + required - it is used to check that the TiXmlString class isn't incorrectly + used. Be nice to old compilers and macro it here: +*/ +#if defined(_MSC_VER) && (_MSC_VER >= 1200 ) + // Microsoft visual studio, version 6 and higher. + #define TIXML_EXPLICIT explicit +#elif defined(__GNUC__) && (__GNUC__ >= 3 ) + // GCC version 3 and higher.s + #define TIXML_EXPLICIT explicit +#else + #define TIXML_EXPLICIT +#endif + + +/* + TiXmlString is an emulation of a subset of the std::string template. + Its purpose is to allow compiling TinyXML on compilers with no or poor STL support. + Only the member functions relevant to the TinyXML project have been implemented. + The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase + a string and there's no more room, we allocate a buffer twice as big as we need. +*/ +class TiXmlString +{ + public : + // The size type used + typedef size_t size_type; + + // Error value for find primitive + static const size_type npos; // = -1; + + + // TiXmlString empty constructor + TiXmlString () : rep_(&nullrep_) + { + } + + // TiXmlString copy constructor + TiXmlString ( const TiXmlString & copy) : rep_(0) + { + init(copy.length()); + memcpy(start(), copy.data(), length()); + } + + // TiXmlString constructor, based on a string + TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0) + { + init( static_cast( strlen(copy) )); + memcpy(start(), copy, length()); + } + + // TiXmlString constructor, based on a string + TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0) + { + init(len); + memcpy(start(), str, len); + } + + // TiXmlString destructor + ~TiXmlString () + { + quit(); + } + + TiXmlString& operator = (const char * copy) + { + return assign( copy, (size_type)strlen(copy)); + } + + TiXmlString& operator = (const TiXmlString & copy) + { + return assign(copy.start(), copy.length()); + } + + + // += operator. Maps to append + TiXmlString& operator += (const char * suffix) + { + return append(suffix, static_cast( strlen(suffix) )); + } + + // += operator. Maps to append + TiXmlString& operator += (char single) + { + return append(&single, 1); + } + + // += operator. Maps to append + TiXmlString& operator += (const TiXmlString & suffix) + { + return append(suffix.data(), suffix.length()); + } + + + // Convert a TiXmlString into a null-terminated char * + const char * c_str () const { return rep_->str; } + + // Convert a TiXmlString into a char * (need not be null terminated). + const char * data () const { return rep_->str; } + + // Return the length of a TiXmlString + size_type length () const { return rep_->size; } + + // Alias for length() + size_type size () const { return rep_->size; } + + // Checks if a TiXmlString is empty + bool empty () const { return rep_->size == 0; } + + // Return capacity of string + size_type capacity () const { return rep_->capacity; } + + + // single char extraction + const char& at (size_type index) const + { + assert( index < length() ); + return rep_->str[ index ]; + } + + // [] operator + char& operator [] (size_type index) const + { + assert( index < length() ); + return rep_->str[ index ]; + } + + // find a char in a string. Return TiXmlString::npos if not found + size_type find (char lookup) const + { + return find(lookup, 0); + } + + // find a char in a string from an offset. Return TiXmlString::npos if not found + size_type find (char tofind, size_type offset) const + { + if (offset >= length()) return npos; + + for (const char* p = c_str() + offset; *p != '\0'; ++p) + { + if (*p == tofind) return static_cast< size_type >( p - c_str() ); + } + return npos; + } + + void clear () + { + //Lee: + //The original was just too strange, though correct: + // TiXmlString().swap(*this); + //Instead use the quit & re-init: + quit(); + init(0,0); + } + + /* Function to reserve a big amount of data when we know we'll need it. Be aware that this + function DOES NOT clear the content of the TiXmlString if any exists. + */ + void reserve (size_type cap); + + TiXmlString& assign (const char* str, size_type len); + + TiXmlString& append (const char* str, size_type len); + + void swap (TiXmlString& other) + { + Rep* r = rep_; + rep_ = other.rep_; + other.rep_ = r; + } + + private: + + void init(size_type sz) { init(sz, sz); } + void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; } + char* start() const { return rep_->str; } + char* finish() const { return rep_->str + rep_->size; } + + struct Rep + { + size_type size, capacity; + char str[1]; + }; + + void init(size_type sz, size_type cap) + { + if (cap) + { + // Lee: the original form: + // rep_ = static_cast(operator new(sizeof(Rep) + cap)); + // doesn't work in some cases of new being overloaded. Switching + // to the normal allocation, although use an 'int' for systems + // that are overly picky about structure alignment. + const size_type bytesNeeded = sizeof(Rep) + cap; + const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int ); + rep_ = reinterpret_cast( new int[ intsNeeded ] ); + + rep_->str[ rep_->size = sz ] = '\0'; + rep_->capacity = cap; + } + else + { + rep_ = &nullrep_; + } + } + + void quit() + { + if (rep_ != &nullrep_) + { + // The rep_ is really an array of ints. (see the allocator, above). + // Cast it back before delete, so the compiler won't incorrectly call destructors. + delete [] ( reinterpret_cast( rep_ ) ); + } + } + + Rep * rep_; + static Rep nullrep_; + +} ; + + +inline bool operator == (const TiXmlString & a, const TiXmlString & b) +{ + return ( a.length() == b.length() ) // optimization on some platforms + && ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare +} +inline bool operator < (const TiXmlString & a, const TiXmlString & b) +{ + return strcmp(a.c_str(), b.c_str()) < 0; +} + +inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); } +inline bool operator > (const TiXmlString & a, const TiXmlString & b) { return b < a; } +inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); } +inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); } + +inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; } +inline bool operator == (const char* a, const TiXmlString & b) { return b == a; } +inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); } +inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); } + +TiXmlString operator + (const TiXmlString & a, const TiXmlString & b); +TiXmlString operator + (const TiXmlString & a, const char* b); +TiXmlString operator + (const char* a, const TiXmlString & b); + + +/* + TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString. + Only the operators that we need for TinyXML have been developped. +*/ +class TiXmlOutStream : public TiXmlString +{ +public : + + // TiXmlOutStream << operator. + TiXmlOutStream & operator << (const TiXmlString & in) + { + *this += in; + return *this; + } + + // TiXmlOutStream << operator. + TiXmlOutStream & operator << (const char * in) + { + *this += in; + return *this; + } + +} ; + +#endif // TIXML_STRING_INCLUDED +#endif // TIXML_USE_STL diff --git a/exchange/exchangesource/DumpFeatureTree/TinyXML/tinyxml.cpp b/exchange/exchangesource/DumpFeatureTree/TinyXML/tinyxml.cpp new file mode 100644 index 0000000..606d089 --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/TinyXML/tinyxml.cpp @@ -0,0 +1,1886 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code by Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include + +#ifdef TIXML_USE_STL +#include +#include +#endif + +#include "tinyxml.h" + +FILE* TiXmlFOpen( const char* filename, const char* mode ); + +bool TiXmlBase::condenseWhiteSpace = true; + +// Microsoft compiler security +FILE* TiXmlFOpen( const char* filename, const char* mode ) +{ + #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) + FILE* fp = 0; + errno_t err = fopen_s( &fp, filename, mode ); + if ( !err && fp ) + return fp; + return 0; + #else + return fopen( filename, mode ); + #endif +} + +void TiXmlBase::EncodeString( const TIXML_STRING& str, TIXML_STRING* outString ) +{ + int i=0; + + while( i<(int)str.length() ) + { + unsigned char c = (unsigned char) str[i]; + + if ( c == '&' + && i < ( (int)str.length() - 2 ) + && str[i+1] == '#' + && str[i+2] == 'x' ) + { + // Hexadecimal character reference. + // Pass through unchanged. + // © -- copyright symbol, for example. + // + // The -1 is a bug fix from Rob Laveaux. It keeps + // an overflow from happening if there is no ';'. + // There are actually 2 ways to exit this loop - + // while fails (error case) and break (semicolon found). + // However, there is no mechanism (currently) for + // this function to return an error. + while ( i<(int)str.length()-1 ) + { + outString->append( str.c_str() + i, 1 ); + ++i; + if ( str[i] == ';' ) + break; + } + } + else if ( c == '&' ) + { + outString->append( entity[0].str, entity[0].strLength ); + ++i; + } + else if ( c == '<' ) + { + outString->append( entity[1].str, entity[1].strLength ); + ++i; + } + else if ( c == '>' ) + { + outString->append( entity[2].str, entity[2].strLength ); + ++i; + } + else if ( c == '\"' ) + { + outString->append( entity[3].str, entity[3].strLength ); + ++i; + } + else if ( c == '\'' ) + { + outString->append( entity[4].str, entity[4].strLength ); + ++i; + } + else if ( c < 32 ) + { + // Easy pass at non-alpha/numeric/symbol + // Below 32 is symbolic. + char buf[ 32 ]; + + #if defined(TIXML_SNPRINTF) + TIXML_SNPRINTF( buf, sizeof(buf), "&#x%02X;", (unsigned) ( c & 0xff ) ); + #else + sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) ); + #endif + + //*ME: warning C4267: convert 'size_t' to 'int' + //*ME: Int-Cast to make compiler happy ... + outString->append( buf, (int)strlen( buf ) ); + ++i; + } + else + { + //char realc = (char) c; + //outString->append( &realc, 1 ); + *outString += (char) c; // somewhat more efficient function call. + ++i; + } + } +} + + +TiXmlNode::TiXmlNode( NodeType _type ) : TiXmlBase() +{ + parent = 0; + type = _type; + firstChild = 0; + lastChild = 0; + prev = 0; + next = 0; +} + + +TiXmlNode::~TiXmlNode() +{ + TiXmlNode* node = firstChild; + TiXmlNode* temp = 0; + + while ( node ) + { + temp = node; + node = node->next; + delete temp; + } +} + + +void TiXmlNode::CopyTo( TiXmlNode* target ) const +{ + target->SetValue (value.c_str() ); + target->userData = userData; + target->location = location; +} + + +void TiXmlNode::Clear() +{ + TiXmlNode* node = firstChild; + TiXmlNode* temp = 0; + + while ( node ) + { + temp = node; + node = node->next; + delete temp; + } + + firstChild = 0; + lastChild = 0; +} + + +TiXmlNode* TiXmlNode::LinkEndChild( TiXmlNode* node ) +{ + assert( node->parent == 0 || node->parent == this ); + assert( node->GetDocument() == 0 || node->GetDocument() == this->GetDocument() ); + + if ( node->Type() == TiXmlNode::TINYXML_DOCUMENT ) + { + delete node; + if ( GetDocument() ) + GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + node->parent = this; + + node->prev = lastChild; + node->next = 0; + + if ( lastChild ) + lastChild->next = node; + else + firstChild = node; // it was an empty list. + + lastChild = node; + return node; +} + + +TiXmlNode* TiXmlNode::InsertEndChild( const TiXmlNode& addThis ) +{ + if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT ) + { + if ( GetDocument() ) + GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + + return LinkEndChild( node ); +} + + +TiXmlNode* TiXmlNode::InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ) +{ + if ( !beforeThis || beforeThis->parent != this ) { + return 0; + } + if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT ) + { + if ( GetDocument() ) + GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + node->parent = this; + + node->next = beforeThis; + node->prev = beforeThis->prev; + if ( beforeThis->prev ) + { + beforeThis->prev->next = node; + } + else + { + assert( firstChild == beforeThis ); + firstChild = node; + } + beforeThis->prev = node; + return node; +} + + +TiXmlNode* TiXmlNode::InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ) +{ + if ( !afterThis || afterThis->parent != this ) { + return 0; + } + if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT ) + { + if ( GetDocument() ) + GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + node->parent = this; + + node->prev = afterThis; + node->next = afterThis->next; + if ( afterThis->next ) + { + afterThis->next->prev = node; + } + else + { + assert( lastChild == afterThis ); + lastChild = node; + } + afterThis->next = node; + return node; +} + + +TiXmlNode* TiXmlNode::ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ) +{ + if ( !replaceThis ) + return 0; + + if ( replaceThis->parent != this ) + return 0; + + if ( withThis.ToDocument() ) { + // A document can never be a child. Thanks to Noam. + TiXmlDocument* document = GetDocument(); + if ( document ) + document->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + TiXmlNode* node = withThis.Clone(); + if ( !node ) + return 0; + + node->next = replaceThis->next; + node->prev = replaceThis->prev; + + if ( replaceThis->next ) + replaceThis->next->prev = node; + else + lastChild = node; + + if ( replaceThis->prev ) + replaceThis->prev->next = node; + else + firstChild = node; + + delete replaceThis; + node->parent = this; + return node; +} + + +bool TiXmlNode::RemoveChild( TiXmlNode* removeThis ) +{ + if ( !removeThis ) { + return false; + } + + if ( removeThis->parent != this ) + { + assert( 0 ); + return false; + } + + if ( removeThis->next ) + removeThis->next->prev = removeThis->prev; + else + lastChild = removeThis->prev; + + if ( removeThis->prev ) + removeThis->prev->next = removeThis->next; + else + firstChild = removeThis->next; + + delete removeThis; + return true; +} + +const TiXmlNode* TiXmlNode::FirstChild( const char * _value ) const +{ + const TiXmlNode* node; + for ( node = firstChild; node; node = node->next ) + { + if ( strcmp( node->Value(), _value ) == 0 ) + return node; + } + return 0; +} + + +const TiXmlNode* TiXmlNode::LastChild( const char * _value ) const +{ + const TiXmlNode* node; + for ( node = lastChild; node; node = node->prev ) + { + if ( strcmp( node->Value(), _value ) == 0 ) + return node; + } + return 0; +} + + +const TiXmlNode* TiXmlNode::IterateChildren( const TiXmlNode* previous ) const +{ + if ( !previous ) + { + return FirstChild(); + } + else + { + assert( previous->parent == this ); + return previous->NextSibling(); + } +} + + +const TiXmlNode* TiXmlNode::IterateChildren( const char * val, const TiXmlNode* previous ) const +{ + if ( !previous ) + { + return FirstChild( val ); + } + else + { + assert( previous->parent == this ); + return previous->NextSibling( val ); + } +} + + +const TiXmlNode* TiXmlNode::NextSibling( const char * _value ) const +{ + const TiXmlNode* node; + for ( node = next; node; node = node->next ) + { + if ( strcmp( node->Value(), _value ) == 0 ) + return node; + } + return 0; +} + + +const TiXmlNode* TiXmlNode::PreviousSibling( const char * _value ) const +{ + const TiXmlNode* node; + for ( node = prev; node; node = node->prev ) + { + if ( strcmp( node->Value(), _value ) == 0 ) + return node; + } + return 0; +} + + +void TiXmlElement::RemoveAttribute( const char * name ) +{ + #ifdef TIXML_USE_STL + TIXML_STRING str( name ); + TiXmlAttribute* node = attributeSet.Find( str ); + #else + TiXmlAttribute* node = attributeSet.Find( name ); + #endif + if ( node ) + { + attributeSet.Remove( node ); + delete node; + } +} + +const TiXmlElement* TiXmlNode::FirstChildElement() const +{ + const TiXmlNode* node; + + for ( node = FirstChild(); + node; + node = node->NextSibling() ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +const TiXmlElement* TiXmlNode::FirstChildElement( const char * _value ) const +{ + const TiXmlNode* node; + + for ( node = FirstChild( _value ); + node; + node = node->NextSibling( _value ) ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +const TiXmlElement* TiXmlNode::NextSiblingElement() const +{ + const TiXmlNode* node; + + for ( node = NextSibling(); + node; + node = node->NextSibling() ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +const TiXmlElement* TiXmlNode::NextSiblingElement( const char * _value ) const +{ + const TiXmlNode* node; + + for ( node = NextSibling( _value ); + node; + node = node->NextSibling( _value ) ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +const TiXmlDocument* TiXmlNode::GetDocument() const +{ + const TiXmlNode* node; + + for( node = this; node; node = node->parent ) + { + if ( node->ToDocument() ) + return node->ToDocument(); + } + return 0; +} + + +TiXmlElement::TiXmlElement (const char * _value) + : TiXmlNode( TiXmlNode::TINYXML_ELEMENT ) +{ + firstChild = lastChild = 0; + value = _value; +} + + +#ifdef TIXML_USE_STL +TiXmlElement::TiXmlElement( const std::string& _value ) + : TiXmlNode( TiXmlNode::TINYXML_ELEMENT ) +{ + firstChild = lastChild = 0; + value = _value; +} +#endif + + +TiXmlElement::TiXmlElement( const TiXmlElement& copy) + : TiXmlNode( TiXmlNode::TINYXML_ELEMENT ) +{ + firstChild = lastChild = 0; + copy.CopyTo( this ); +} + + +TiXmlElement& TiXmlElement::operator=( const TiXmlElement& base ) +{ + ClearThis(); + base.CopyTo( this ); + return *this; +} + + +TiXmlElement::~TiXmlElement() +{ + ClearThis(); +} + + +void TiXmlElement::ClearThis() +{ + Clear(); + while( attributeSet.First() ) + { + TiXmlAttribute* node = attributeSet.First(); + attributeSet.Remove( node ); + delete node; + } +} + + +const char* TiXmlElement::Attribute( const char* name ) const +{ + const TiXmlAttribute* node = attributeSet.Find( name ); + if ( node ) + return node->Value(); + return 0; +} + + +#ifdef TIXML_USE_STL +const std::string* TiXmlElement::Attribute( const std::string& name ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + if ( attrib ) + return &attrib->ValueStr(); + return 0; +} +#endif + + +const char* TiXmlElement::Attribute( const char* name, int* i ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + const char* result = 0; + + if ( attrib ) { + result = attrib->Value(); + if ( i ) { + attrib->QueryIntValue( i ); + } + } + return result; +} + + +#ifdef TIXML_USE_STL +const std::string* TiXmlElement::Attribute( const std::string& name, int* i ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + const std::string* result = 0; + + if ( attrib ) { + result = &attrib->ValueStr(); + if ( i ) { + attrib->QueryIntValue( i ); + } + } + return result; +} +#endif + + +const char* TiXmlElement::Attribute( const char* name, double* d ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + const char* result = 0; + + if ( attrib ) { + result = attrib->Value(); + if ( d ) { + attrib->QueryDoubleValue( d ); + } + } + return result; +} + + +#ifdef TIXML_USE_STL +const std::string* TiXmlElement::Attribute( const std::string& name, double* d ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + const std::string* result = 0; + + if ( attrib ) { + result = &attrib->ValueStr(); + if ( d ) { + attrib->QueryDoubleValue( d ); + } + } + return result; +} +#endif + + +int TiXmlElement::QueryIntAttribute( const char* name, int* ival ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + if ( !attrib ) + return TIXML_NO_ATTRIBUTE; + return attrib->QueryIntValue( ival ); +} + + +int TiXmlElement::QueryUnsignedAttribute( const char* name, unsigned* pvalue ) const +{ + const TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + + int ival = 0; + int result = node->QueryIntValue( &ival ); + *pvalue = (unsigned)ival; + return result; +} + + +int TiXmlElement::QueryBoolAttribute( const char* name, bool* bval ) const +{ + const TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + + int result = TIXML_WRONG_TYPE; + if ( StringEqual( node->Value(), "true", true, TIXML_ENCODING_UNKNOWN ) + || StringEqual( node->Value(), "yes", true, TIXML_ENCODING_UNKNOWN ) + || StringEqual( node->Value(), "1", true, TIXML_ENCODING_UNKNOWN ) ) + { + *bval = true; + result = TIXML_SUCCESS; + } + else if ( StringEqual( node->Value(), "false", true, TIXML_ENCODING_UNKNOWN ) + || StringEqual( node->Value(), "no", true, TIXML_ENCODING_UNKNOWN ) + || StringEqual( node->Value(), "0", true, TIXML_ENCODING_UNKNOWN ) ) + { + *bval = false; + result = TIXML_SUCCESS; + } + return result; +} + + + +#ifdef TIXML_USE_STL +int TiXmlElement::QueryIntAttribute( const std::string& name, int* ival ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + if ( !attrib ) + return TIXML_NO_ATTRIBUTE; + return attrib->QueryIntValue( ival ); +} +#endif + + +int TiXmlElement::QueryDoubleAttribute( const char* name, double* dval ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + if ( !attrib ) + return TIXML_NO_ATTRIBUTE; + return attrib->QueryDoubleValue( dval ); +} + + +#ifdef TIXML_USE_STL +int TiXmlElement::QueryDoubleAttribute( const std::string& name, double* dval ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + if ( !attrib ) + return TIXML_NO_ATTRIBUTE; + return attrib->QueryDoubleValue( dval ); +} +#endif + + +void TiXmlElement::SetAttribute( const char * name, int val ) +{ + TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); + if ( attrib ) { + attrib->SetIntValue( val ); + } +} + + +#ifdef TIXML_USE_STL +void TiXmlElement::SetAttribute( const std::string& name, int val ) +{ + TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); + if ( attrib ) { + attrib->SetIntValue( val ); + } +} +#endif + + +void TiXmlElement::SetDoubleAttribute( const char * name, double val ) +{ + TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); + if ( attrib ) { + attrib->SetDoubleValue( val ); + } +} + + +#ifdef TIXML_USE_STL +void TiXmlElement::SetDoubleAttribute( const std::string& name, double val ) +{ + TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); + if ( attrib ) { + attrib->SetDoubleValue( val ); + } +} +#endif + + +void TiXmlElement::SetAttribute( const char * cname, const char * cvalue ) +{ + TiXmlAttribute* attrib = attributeSet.FindOrCreate( cname ); + if ( attrib ) { + attrib->SetValue( cvalue ); + } +} + + +#ifdef TIXML_USE_STL +void TiXmlElement::SetAttribute( const std::string& _name, const std::string& _value ) +{ + TiXmlAttribute* attrib = attributeSet.FindOrCreate( _name ); + if ( attrib ) { + attrib->SetValue( _value ); + } +} +#endif + + +void TiXmlElement::Print( FILE* cfile, int depth ) const +{ + int i; + assert( cfile ); + for ( i=0; iNext() ) + { + fprintf( cfile, " " ); + attrib->Print( cfile, depth ); + } + + // There are 3 different formatting approaches: + // 1) An element without children is printed as a node + // 2) An element with only a text child is printed as text + // 3) An element with children is printed on multiple lines. + TiXmlNode* node; + if ( !firstChild ) + { + fprintf( cfile, " />" ); + } + else if ( firstChild == lastChild && firstChild->ToText() ) + { + fprintf( cfile, ">" ); + firstChild->Print( cfile, depth + 1 ); + fprintf( cfile, "", value.c_str() ); + } + else + { + fprintf( cfile, ">" ); + + for ( node = firstChild; node; node=node->NextSibling() ) + { + if ( !node->ToText() ) + { + fprintf( cfile, "\n" ); + } + node->Print( cfile, depth+1 ); + } + fprintf( cfile, "\n" ); + for( i=0; i", value.c_str() ); + } +} + + +void TiXmlElement::CopyTo( TiXmlElement* target ) const +{ + // superclass: + TiXmlNode::CopyTo( target ); + + // Element class: + // Clone the attributes, then clone the children. + const TiXmlAttribute* attribute = 0; + for( attribute = attributeSet.First(); + attribute; + attribute = attribute->Next() ) + { + target->SetAttribute( attribute->Name(), attribute->Value() ); + } + + TiXmlNode* node = 0; + for ( node = firstChild; node; node = node->NextSibling() ) + { + target->LinkEndChild( node->Clone() ); + } +} + +bool TiXmlElement::Accept( TiXmlVisitor* visitor ) const +{ + if ( visitor->VisitEnter( *this, attributeSet.First() ) ) + { + for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) + { + if ( !node->Accept( visitor ) ) + break; + } + } + return visitor->VisitExit( *this ); +} + + +TiXmlNode* TiXmlElement::Clone() const +{ + TiXmlElement* clone = new TiXmlElement( Value() ); + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +const char* TiXmlElement::GetText() const +{ + const TiXmlNode* child = this->FirstChild(); + if ( child ) { + const TiXmlText* childText = child->ToText(); + if ( childText ) { + return childText->Value(); + } + } + return 0; +} + + +TiXmlDocument::TiXmlDocument() : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT ) +{ + tabsize = 4; + useMicrosoftBOM = false; + ClearError(); +} + +TiXmlDocument::TiXmlDocument( const char * documentName ) : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT ) +{ + tabsize = 4; + useMicrosoftBOM = false; + value = documentName; + ClearError(); +} + + +#ifdef TIXML_USE_STL +TiXmlDocument::TiXmlDocument( const std::string& documentName ) : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT ) +{ + tabsize = 4; + useMicrosoftBOM = false; + value = documentName; + ClearError(); +} +#endif + + +TiXmlDocument::TiXmlDocument( const TiXmlDocument& copy ) : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT ) +{ + copy.CopyTo( this ); +} + + +TiXmlDocument& TiXmlDocument::operator=( const TiXmlDocument& copy ) +{ + Clear(); + copy.CopyTo( this ); + return *this; +} + + +bool TiXmlDocument::LoadFile( TiXmlEncoding encoding ) +{ + return LoadFile( Value(), encoding ); +} + + +bool TiXmlDocument::SaveFile() const +{ + return SaveFile( Value() ); +} + +bool TiXmlDocument::LoadFile( const char* _filename, TiXmlEncoding encoding ) +{ + TIXML_STRING filename( _filename ); + value = filename; + + // reading in binary mode so that tinyxml can normalize the EOL + FILE* file = TiXmlFOpen( value.c_str (), "rb" ); + + if ( file ) + { + bool result = LoadFile( file, encoding ); + fclose( file ); + return result; + } + else + { + SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); + return false; + } +} + +bool TiXmlDocument::LoadFile( FILE* file, TiXmlEncoding encoding ) +{ + if ( !file ) + { + SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); + return false; + } + + // Delete the existing data: + Clear(); + location.Clear(); + + // Get the file size, so we can pre-allocate the string. HUGE speed impact. + long length = 0; + fseek( file, 0, SEEK_END ); + length = ftell( file ); + fseek( file, 0, SEEK_SET ); + + // Strange case, but good to handle up front. + if ( length <= 0 ) + { + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return false; + } + + // Subtle bug here. TinyXml did use fgets. But from the XML spec: + // 2.11 End-of-Line Handling + // + // + // ...the XML processor MUST behave as if it normalized all line breaks in external + // parsed entities (including the document entity) on input, before parsing, by translating + // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to + // a single #xA character. + // + // + // It is not clear fgets does that, and certainly isn't clear it works cross platform. + // Generally, you expect fgets to translate from the convention of the OS to the c/unix + // convention, and not work generally. + + /* + while( fgets( buf, sizeof(buf), file ) ) + { + data += buf; + } + */ + + char* buf = new char[ length+1 ]; + buf[0] = 0; + + if ( fread( buf, length, 1, file ) != 1 ) { + delete [] buf; + SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); + return false; + } + + // Process the buffer in place to normalize new lines. (See comment above.) + // Copies from the 'p' to 'q' pointer, where p can advance faster if + // a newline-carriage return is hit. + // + // Wikipedia: + // Systems based on ASCII or a compatible character set use either LF (Line feed, '\n', 0x0A, 10 in decimal) or + // CR (Carriage return, '\r', 0x0D, 13 in decimal) individually, or CR followed by LF (CR+LF, 0x0D 0x0A)... + // * LF: Multics, Unix and Unix-like systems (GNU/Linux, AIX, Xenix, Mac OS X, FreeBSD, etc.), BeOS, Amiga, RISC OS, and others + // * CR+LF: DEC RT-11 and most other early non-Unix, non-IBM OSes, CP/M, MP/M, DOS, OS/2, Microsoft Windows, Symbian OS + // * CR: Commodore 8-bit machines, Apple II family, Mac OS up to version 9 and OS-9 + + const char* p = buf; // the read head + char* q = buf; // the write head + const char CR = 0x0d; + const char LF = 0x0a; + + buf[length] = 0; + while( *p ) { + assert( p < (buf+length) ); + assert( q <= (buf+length) ); + assert( q <= p ); + + if ( *p == CR ) { + *q++ = LF; + p++; + if ( *p == LF ) { // check for CR+LF (and skip LF) + p++; + } + } + else { + *q++ = *p++; + } + } + assert( q <= (buf+length) ); + *q = 0; + + Parse( buf, 0, encoding ); + + delete [] buf; + return !Error(); +} + + +bool TiXmlDocument::SaveFile( const char * filename ) const +{ + // The old c stuff lives on... + FILE* fp = TiXmlFOpen( filename, "w" ); + if ( fp ) + { + bool result = SaveFile( fp ); + fclose( fp ); + return result; + } + return false; +} + + +bool TiXmlDocument::SaveFile( FILE* fp ) const +{ + if ( useMicrosoftBOM ) + { + const unsigned char TIXML_UTF_LEAD_0 = 0xefU; + const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; + const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; + + fputc( TIXML_UTF_LEAD_0, fp ); + fputc( TIXML_UTF_LEAD_1, fp ); + fputc( TIXML_UTF_LEAD_2, fp ); + } + Print( fp, 0 ); + return (ferror(fp) == 0); +} + + +void TiXmlDocument::CopyTo( TiXmlDocument* target ) const +{ + TiXmlNode::CopyTo( target ); + + target->error = error; + target->errorId = errorId; + target->errorDesc = errorDesc; + target->tabsize = tabsize; + target->errorLocation = errorLocation; + target->useMicrosoftBOM = useMicrosoftBOM; + + TiXmlNode* node = 0; + for ( node = firstChild; node; node = node->NextSibling() ) + { + target->LinkEndChild( node->Clone() ); + } +} + + +TiXmlNode* TiXmlDocument::Clone() const +{ + TiXmlDocument* clone = new TiXmlDocument(); + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +void TiXmlDocument::Print( FILE* cfile, int depth ) const +{ + assert( cfile ); + for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) + { + node->Print( cfile, depth ); + fprintf( cfile, "\n" ); + } +} + + +bool TiXmlDocument::Accept( TiXmlVisitor* visitor ) const +{ + if ( visitor->VisitEnter( *this ) ) + { + for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) + { + if ( !node->Accept( visitor ) ) + break; + } + } + return visitor->VisitExit( *this ); +} + + +const TiXmlAttribute* TiXmlAttribute::Next() const +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( next->value.empty() && next->name.empty() ) + return 0; + return next; +} + +/* +TiXmlAttribute* TiXmlAttribute::Next() +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( next->value.empty() && next->name.empty() ) + return 0; + return next; +} +*/ + +const TiXmlAttribute* TiXmlAttribute::Previous() const +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( prev->value.empty() && prev->name.empty() ) + return 0; + return prev; +} + +/* +TiXmlAttribute* TiXmlAttribute::Previous() +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( prev->value.empty() && prev->name.empty() ) + return 0; + return prev; +} +*/ + +void TiXmlAttribute::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const +{ + TIXML_STRING n, v; + + EncodeString( name, &n ); + EncodeString( value, &v ); + + if (value.find ('\"') == TIXML_STRING::npos) { + if ( cfile ) { + fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() ); + } + if ( str ) { + (*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\""; + } + } + else { + if ( cfile ) { + fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() ); + } + if ( str ) { + (*str) += n; (*str) += "='"; (*str) += v; (*str) += "'"; + } + } +} + + +int TiXmlAttribute::QueryIntValue( int* ival ) const +{ + if ( TIXML_SSCANF( value.c_str(), "%d", ival ) == 1 ) + return TIXML_SUCCESS; + return TIXML_WRONG_TYPE; +} + +int TiXmlAttribute::QueryDoubleValue( double* dval ) const +{ + if ( TIXML_SSCANF( value.c_str(), "%lf", dval ) == 1 ) + return TIXML_SUCCESS; + return TIXML_WRONG_TYPE; +} + +void TiXmlAttribute::SetIntValue( int _value ) +{ + char buf [64]; + #if defined(TIXML_SNPRINTF) + TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value); + #else + sprintf (buf, "%d", _value); + #endif + SetValue (buf); +} + +void TiXmlAttribute::SetDoubleValue( double _value ) +{ + char buf [256]; + #if defined(TIXML_SNPRINTF) + TIXML_SNPRINTF( buf, sizeof(buf), "%g", _value); + #else + sprintf (buf, "%g", _value); + #endif + SetValue (buf); +} + +int TiXmlAttribute::IntValue() const +{ + return atoi (value.c_str ()); +} + +double TiXmlAttribute::DoubleValue() const +{ + return atof (value.c_str ()); +} + + +TiXmlComment::TiXmlComment( const TiXmlComment& copy ) : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) +{ + copy.CopyTo( this ); +} + + +TiXmlComment& TiXmlComment::operator=( const TiXmlComment& base ) +{ + Clear(); + base.CopyTo( this ); + return *this; +} + + +void TiXmlComment::Print( FILE* cfile, int depth ) const +{ + assert( cfile ); + for ( int i=0; i", value.c_str() ); +} + + +void TiXmlComment::CopyTo( TiXmlComment* target ) const +{ + TiXmlNode::CopyTo( target ); +} + + +bool TiXmlComment::Accept( TiXmlVisitor* visitor ) const +{ + return visitor->Visit( *this ); +} + + +TiXmlNode* TiXmlComment::Clone() const +{ + TiXmlComment* clone = new TiXmlComment(); + + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +void TiXmlText::Print( FILE* cfile, int depth ) const +{ + assert( cfile ); + if ( cdata ) + { + int i; + fprintf( cfile, "\n" ); + for ( i=0; i\n", value.c_str() ); // unformatted output + } + else + { + TIXML_STRING buffer; + EncodeString( value, &buffer ); + fprintf( cfile, "%s", buffer.c_str() ); + } +} + + +void TiXmlText::CopyTo( TiXmlText* target ) const +{ + TiXmlNode::CopyTo( target ); + target->cdata = cdata; +} + + +bool TiXmlText::Accept( TiXmlVisitor* visitor ) const +{ + return visitor->Visit( *this ); +} + + +TiXmlNode* TiXmlText::Clone() const +{ + TiXmlText* clone = 0; + clone = new TiXmlText( "" ); + + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +TiXmlDeclaration::TiXmlDeclaration( const char * _version, + const char * _encoding, + const char * _standalone ) + : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) +{ + version = _version; + encoding = _encoding; + standalone = _standalone; +} + + +#ifdef TIXML_USE_STL +TiXmlDeclaration::TiXmlDeclaration( const std::string& _version, + const std::string& _encoding, + const std::string& _standalone ) + : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) +{ + version = _version; + encoding = _encoding; + standalone = _standalone; +} +#endif + + +TiXmlDeclaration::TiXmlDeclaration( const TiXmlDeclaration& copy ) + : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) +{ + copy.CopyTo( this ); +} + + +TiXmlDeclaration& TiXmlDeclaration::operator=( const TiXmlDeclaration& copy ) +{ + Clear(); + copy.CopyTo( this ); + return *this; +} + + +void TiXmlDeclaration::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const +{ + if ( cfile ) fprintf( cfile, "" ); + if ( str ) (*str) += "?>"; +} + + +void TiXmlDeclaration::CopyTo( TiXmlDeclaration* target ) const +{ + TiXmlNode::CopyTo( target ); + + target->version = version; + target->encoding = encoding; + target->standalone = standalone; +} + + +bool TiXmlDeclaration::Accept( TiXmlVisitor* visitor ) const +{ + return visitor->Visit( *this ); +} + + +TiXmlNode* TiXmlDeclaration::Clone() const +{ + TiXmlDeclaration* clone = new TiXmlDeclaration(); + + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +void TiXmlUnknown::Print( FILE* cfile, int depth ) const +{ + for ( int i=0; i", value.c_str() ); +} + + +void TiXmlUnknown::CopyTo( TiXmlUnknown* target ) const +{ + TiXmlNode::CopyTo( target ); +} + + +bool TiXmlUnknown::Accept( TiXmlVisitor* visitor ) const +{ + return visitor->Visit( *this ); +} + + +TiXmlNode* TiXmlUnknown::Clone() const +{ + TiXmlUnknown* clone = new TiXmlUnknown(); + + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +TiXmlAttributeSet::TiXmlAttributeSet() +{ + sentinel.next = &sentinel; + sentinel.prev = &sentinel; +} + + +TiXmlAttributeSet::~TiXmlAttributeSet() +{ + assert( sentinel.next == &sentinel ); + assert( sentinel.prev == &sentinel ); +} + + +void TiXmlAttributeSet::Add( TiXmlAttribute* addMe ) +{ + #ifdef TIXML_USE_STL + assert( !Find( TIXML_STRING( addMe->Name() ) ) ); // Shouldn't be multiply adding to the set. + #else + assert( !Find( addMe->Name() ) ); // Shouldn't be multiply adding to the set. + #endif + + addMe->next = &sentinel; + addMe->prev = sentinel.prev; + + sentinel.prev->next = addMe; + sentinel.prev = addMe; +} + +void TiXmlAttributeSet::Remove( TiXmlAttribute* removeMe ) +{ + TiXmlAttribute* node; + + for( node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( node == removeMe ) + { + node->prev->next = node->next; + node->next->prev = node->prev; + node->next = 0; + node->prev = 0; + return; + } + } + assert( 0 ); // we tried to remove a non-linked attribute. +} + + +#ifdef TIXML_USE_STL +TiXmlAttribute* TiXmlAttributeSet::Find( const std::string& name ) const +{ + for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( node->name == name ) + return node; + } + return 0; +} + +TiXmlAttribute* TiXmlAttributeSet::FindOrCreate( const std::string& _name ) +{ + TiXmlAttribute* attrib = Find( _name ); + if ( !attrib ) { + attrib = new TiXmlAttribute(); + Add( attrib ); + attrib->SetName( _name ); + } + return attrib; +} +#endif + + +TiXmlAttribute* TiXmlAttributeSet::Find( const char* name ) const +{ + for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( strcmp( node->name.c_str(), name ) == 0 ) + return node; + } + return 0; +} + + +TiXmlAttribute* TiXmlAttributeSet::FindOrCreate( const char* _name ) +{ + TiXmlAttribute* attrib = Find( _name ); + if ( !attrib ) { + attrib = new TiXmlAttribute(); + Add( attrib ); + attrib->SetName( _name ); + } + return attrib; +} + + +#ifdef TIXML_USE_STL +std::istream& operator>> (std::istream & in, TiXmlNode & base) +{ + TIXML_STRING tag; + tag.reserve( 8 * 1000 ); + base.StreamIn( &in, &tag ); + + base.Parse( tag.c_str(), 0, TIXML_DEFAULT_ENCODING ); + return in; +} +#endif + + +#ifdef TIXML_USE_STL +std::ostream& operator<< (std::ostream & out, const TiXmlNode & base) +{ + TiXmlPrinter printer; + printer.SetStreamPrinting(); + base.Accept( &printer ); + out << printer.Str(); + + return out; +} + + +std::string& operator<< (std::string& out, const TiXmlNode& base ) +{ + TiXmlPrinter printer; + printer.SetStreamPrinting(); + base.Accept( &printer ); + out.append( printer.Str() ); + + return out; +} +#endif + + +TiXmlHandle TiXmlHandle::FirstChild() const +{ + if ( node ) + { + TiXmlNode* child = node->FirstChild(); + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::FirstChild( const char * value ) const +{ + if ( node ) + { + TiXmlNode* child = node->FirstChild( value ); + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::FirstChildElement() const +{ + if ( node ) + { + TiXmlElement* child = node->FirstChildElement(); + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::FirstChildElement( const char * value ) const +{ + if ( node ) + { + TiXmlElement* child = node->FirstChildElement( value ); + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::Child( int count ) const +{ + if ( node ) + { + int i; + TiXmlNode* child = node->FirstChild(); + for ( i=0; + child && iNextSibling(), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::Child( const char* value, int count ) const +{ + if ( node ) + { + int i; + TiXmlNode* child = node->FirstChild( value ); + for ( i=0; + child && iNextSibling( value ), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::ChildElement( int count ) const +{ + if ( node ) + { + int i; + TiXmlElement* child = node->FirstChildElement(); + for ( i=0; + child && iNextSiblingElement(), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::ChildElement( const char* value, int count ) const +{ + if ( node ) + { + int i; + TiXmlElement* child = node->FirstChildElement( value ); + for ( i=0; + child && iNextSiblingElement( value ), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +bool TiXmlPrinter::VisitEnter( const TiXmlDocument& ) +{ + return true; +} + +bool TiXmlPrinter::VisitExit( const TiXmlDocument& ) +{ + return true; +} + +bool TiXmlPrinter::VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute ) +{ + DoIndent(); + buffer += "<"; + buffer += element.Value(); + + for( const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() ) + { + buffer += " "; + attrib->Print( 0, 0, &buffer ); + } + + if ( !element.FirstChild() ) + { + buffer += " />"; + DoLineBreak(); + } + else + { + buffer += ">"; + if ( element.FirstChild()->ToText() + && element.LastChild() == element.FirstChild() + && element.FirstChild()->ToText()->CDATA() == false ) + { + simpleTextPrint = true; + // no DoLineBreak()! + } + else + { + DoLineBreak(); + } + } + ++depth; + return true; +} + + +bool TiXmlPrinter::VisitExit( const TiXmlElement& element ) +{ + --depth; + if ( !element.FirstChild() ) + { + // nothing. + } + else + { + if ( simpleTextPrint ) + { + simpleTextPrint = false; + } + else + { + DoIndent(); + } + buffer += ""; + DoLineBreak(); + } + return true; +} + + +bool TiXmlPrinter::Visit( const TiXmlText& text ) +{ + if ( text.CDATA() ) + { + DoIndent(); + buffer += ""; + DoLineBreak(); + } + else if ( simpleTextPrint ) + { + TIXML_STRING str; + TiXmlBase::EncodeString( text.ValueTStr(), &str ); + buffer += str; + } + else + { + DoIndent(); + TIXML_STRING str; + TiXmlBase::EncodeString( text.ValueTStr(), &str ); + buffer += str; + DoLineBreak(); + } + return true; +} + + +bool TiXmlPrinter::Visit( const TiXmlDeclaration& declaration ) +{ + DoIndent(); + declaration.Print( 0, 0, &buffer ); + DoLineBreak(); + return true; +} + + +bool TiXmlPrinter::Visit( const TiXmlComment& comment ) +{ + DoIndent(); + buffer += ""; + DoLineBreak(); + return true; +} + + +bool TiXmlPrinter::Visit( const TiXmlUnknown& unknown ) +{ + DoIndent(); + buffer += "<"; + buffer += unknown.Value(); + buffer += ">"; + DoLineBreak(); + return true; +} + diff --git a/exchange/exchangesource/DumpFeatureTree/TinyXML/tinyxml.h b/exchange/exchangesource/DumpFeatureTree/TinyXML/tinyxml.h new file mode 100644 index 0000000..a3589e5 --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/TinyXML/tinyxml.h @@ -0,0 +1,1805 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code by Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + + +#ifndef TINYXML_INCLUDED +#define TINYXML_INCLUDED + +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable : 4530 ) +#pragma warning( disable : 4786 ) +#endif + +#include +#include +#include +#include +#include + +// Help out windows: +#if defined( _DEBUG ) && !defined( DEBUG ) +#define DEBUG +#endif + +#ifdef TIXML_USE_STL + #include + #include + #include + #define TIXML_STRING std::string +#else + #include "tinystr.h" + #define TIXML_STRING TiXmlString +#endif + +// Deprecated library function hell. Compilers want to use the +// new safe versions. This probably doesn't fully address the problem, +// but it gets closer. There are too many compilers for me to fully +// test. If you get compilation troubles, undefine TIXML_SAFE +#define TIXML_SAFE + +#ifdef TIXML_SAFE + #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) + // Microsoft visual studio, version 2005 and higher. + #define TIXML_SNPRINTF _snprintf_s + #define TIXML_SSCANF sscanf_s + #elif defined(_MSC_VER) && (_MSC_VER >= 1200 ) + // Microsoft visual studio, version 6 and higher. + //#pragma message( "Using _sn* functions." ) + #define TIXML_SNPRINTF _snprintf + #define TIXML_SSCANF sscanf + #elif defined(__GNUC__) && (__GNUC__ >= 3 ) + // GCC version 3 and higher.s + //#warning( "Using sn* functions." ) + #define TIXML_SNPRINTF snprintf + #define TIXML_SSCANF sscanf + #else + #define TIXML_SNPRINTF snprintf + #define TIXML_SSCANF sscanf + #endif +#endif + +class TiXmlDocument; +class TiXmlElement; +class TiXmlComment; +class TiXmlUnknown; +class TiXmlAttribute; +class TiXmlText; +class TiXmlDeclaration; +class TiXmlParsingData; + +const int TIXML_MAJOR_VERSION = 2; +const int TIXML_MINOR_VERSION = 6; +const int TIXML_PATCH_VERSION = 2; + +/* Internal structure for tracking location of items + in the XML file. +*/ +struct TiXmlCursor +{ + TiXmlCursor() { Clear(); } + void Clear() { row = col = -1; } + + int row; // 0 based. + int col; // 0 based. +}; + + +/** + Implements the interface to the "Visitor pattern" (see the Accept() method.) + If you call the Accept() method, it requires being passed a TiXmlVisitor + class to handle callbacks. For nodes that contain other nodes (Document, Element) + you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves + are simply called with Visit(). + + If you return 'true' from a Visit method, recursive parsing will continue. If you return + false, no children of this node or its sibilings will be Visited. + + All flavors of Visit methods have a default implementation that returns 'true' (continue + visiting). You need to only override methods that are interesting to you. + + Generally Accept() is called on the TiXmlDocument, although all nodes suppert Visiting. + + You should never change the document from a callback. + + @sa TiXmlNode::Accept() +*/ +class TiXmlVisitor +{ +public: + virtual ~TiXmlVisitor() {} + + /// Visit a document. + virtual bool VisitEnter( const TiXmlDocument& /*doc*/ ) { return true; } + /// Visit a document. + virtual bool VisitExit( const TiXmlDocument& /*doc*/ ) { return true; } + + /// Visit an element. + virtual bool VisitEnter( const TiXmlElement& /*element*/, const TiXmlAttribute* /*firstAttribute*/ ) { return true; } + /// Visit an element. + virtual bool VisitExit( const TiXmlElement& /*element*/ ) { return true; } + + /// Visit a declaration + virtual bool Visit( const TiXmlDeclaration& /*declaration*/ ) { return true; } + /// Visit a text node + virtual bool Visit( const TiXmlText& /*text*/ ) { return true; } + /// Visit a comment node + virtual bool Visit( const TiXmlComment& /*comment*/ ) { return true; } + /// Visit an unknown node + virtual bool Visit( const TiXmlUnknown& /*unknown*/ ) { return true; } +}; + +// Only used by Attribute::Query functions +enum +{ + TIXML_SUCCESS, + TIXML_NO_ATTRIBUTE, + TIXML_WRONG_TYPE +}; + + +// Used by the parsing routines. +enum TiXmlEncoding +{ + TIXML_ENCODING_UNKNOWN, + TIXML_ENCODING_UTF8, + TIXML_ENCODING_LEGACY +}; + +const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN; + +/** TiXmlBase is a base class for every class in TinyXml. + It does little except to establish that TinyXml classes + can be printed and provide some utility functions. + + In XML, the document and elements can contain + other elements and other types of nodes. + + @verbatim + A Document can contain: Element (container or leaf) + Comment (leaf) + Unknown (leaf) + Declaration( leaf ) + + An Element can contain: Element (container or leaf) + Text (leaf) + Attributes (not on tree) + Comment (leaf) + Unknown (leaf) + + A Decleration contains: Attributes (not on tree) + @endverbatim +*/ +class TiXmlBase +{ + friend class TiXmlNode; + friend class TiXmlElement; + friend class TiXmlDocument; + +public: + TiXmlBase() : userData(0) {} + virtual ~TiXmlBase() {} + + /** All TinyXml classes can print themselves to a filestream + or the string class (TiXmlString in non-STL mode, std::string + in STL mode.) Either or both cfile and str can be null. + + This is a formatted print, and will insert + tabs and newlines. + + (For an unformatted stream, use the << operator.) + */ + virtual void Print( FILE* cfile, int depth ) const = 0; + + /** The world does not agree on whether white space should be kept or + not. In order to make everyone happy, these global, static functions + are provided to set whether or not TinyXml will condense all white space + into a single space or not. The default is to condense. Note changing this + value is not thread safe. + */ + static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; } + + /// Return the current white space setting. + static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; } + + /** Return the position, in the original source file, of this node or attribute. + The row and column are 1-based. (That is the first row and first column is + 1,1). If the returns values are 0 or less, then the parser does not have + a row and column value. + + Generally, the row and column value will be set when the TiXmlDocument::Load(), + TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set + when the DOM was created from operator>>. + + The values reflect the initial load. Once the DOM is modified programmatically + (by adding or changing nodes and attributes) the new values will NOT update to + reflect changes in the document. + + There is a minor performance cost to computing the row and column. Computation + can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value. + + @sa TiXmlDocument::SetTabSize() + */ + int Row() const { return location.row + 1; } + int Column() const { return location.col + 1; } ///< See Row() + + void SetUserData( void* user ) { userData = user; } ///< Set a pointer to arbitrary user data. + void* GetUserData() { return userData; } ///< Get a pointer to arbitrary user data. + const void* GetUserData() const { return userData; } ///< Get a pointer to arbitrary user data. + + // Table that returs, for a given lead byte, the total number of bytes + // in the UTF-8 sequence. + static const int utf8ByteTable[256]; + + virtual const char* Parse( const char* p, + TiXmlParsingData* data, + TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0; + + /** Expands entities in a string. Note this should not contian the tag's '<', '>', etc, + or they will be transformed into entities! + */ + static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out ); + + enum + { + TIXML_NO_ERROR = 0, + TIXML_ERROR, + TIXML_ERROR_OPENING_FILE, + TIXML_ERROR_PARSING_ELEMENT, + TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, + TIXML_ERROR_READING_ELEMENT_VALUE, + TIXML_ERROR_READING_ATTRIBUTES, + TIXML_ERROR_PARSING_EMPTY, + TIXML_ERROR_READING_END_TAG, + TIXML_ERROR_PARSING_UNKNOWN, + TIXML_ERROR_PARSING_COMMENT, + TIXML_ERROR_PARSING_DECLARATION, + TIXML_ERROR_DOCUMENT_EMPTY, + TIXML_ERROR_EMBEDDED_NULL, + TIXML_ERROR_PARSING_CDATA, + TIXML_ERROR_DOCUMENT_TOP_ONLY, + + TIXML_ERROR_STRING_COUNT + }; + +protected: + + static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding ); + + inline static bool IsWhiteSpace( char c ) + { + return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); + } + inline static bool IsWhiteSpace( int c ) + { + if ( c < 256 ) + return IsWhiteSpace( (char) c ); + return false; // Again, only truly correct for English/Latin...but usually works. + } + + #ifdef TIXML_USE_STL + static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag ); + static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag ); + #endif + + /* Reads an XML name into the string provided. Returns + a pointer just past the last character of the name, + or 0 if the function has an error. + */ + static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding ); + + /* Reads text. Returns a pointer past the given end tag. + Wickedly complex options, but it keeps the (sensitive) code in one place. + */ + static const char* ReadText( const char* in, // where to start + TIXML_STRING* text, // the string read + bool ignoreWhiteSpace, // whether to keep the white space + const char* endTag, // what ends this text + bool ignoreCase, // whether to ignore case in the end tag + TiXmlEncoding encoding ); // the current encoding + + // If an entity has been found, transform it into a character. + static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding ); + + // Get a character, while interpreting entities. + // The length can be from 0 to 4 bytes. + inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding ) + { + assert( p ); + if ( encoding == TIXML_ENCODING_UTF8 ) + { + *length = utf8ByteTable[ *((const unsigned char*)p) ]; + assert( *length >= 0 && *length < 5 ); + } + else + { + *length = 1; + } + + if ( *length == 1 ) + { + if ( *p == '&' ) + return GetEntity( p, _value, length, encoding ); + *_value = *p; + return p+1; + } + else if ( *length ) + { + //strncpy( _value, p, *length ); // lots of compilers don't like this function (unsafe), + // and the null terminator isn't needed + for( int i=0; p[i] && i<*length; ++i ) { + _value[i] = p[i]; + } + return p + (*length); + } + else + { + // Not valid text. + return 0; + } + } + + // Return true if the next characters in the stream are any of the endTag sequences. + // Ignore case only works for english, and should only be relied on when comparing + // to English words: StringEqual( p, "version", true ) is fine. + static bool StringEqual( const char* p, + const char* endTag, + bool ignoreCase, + TiXmlEncoding encoding ); + + static const char* errorString[ TIXML_ERROR_STRING_COUNT ]; + + TiXmlCursor location; + + /// Field containing a generic user pointer + void* userData; + + // None of these methods are reliable for any language except English. + // Good for approximation, not great for accuracy. + static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding ); + static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding ); + inline static int ToLower( int v, TiXmlEncoding encoding ) + { + if ( encoding == TIXML_ENCODING_UTF8 ) + { + if ( v < 128 ) return tolower( v ); + return v; + } + else + { + return tolower( v ); + } + } + static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ); + +private: + TiXmlBase( const TiXmlBase& ); // not implemented. + void operator=( const TiXmlBase& base ); // not allowed. + + struct Entity + { + const char* str; + unsigned int strLength; + char chr; + }; + enum + { + NUM_ENTITY = 5, + MAX_ENTITY_LENGTH = 6 + + }; + static Entity entity[ NUM_ENTITY ]; + static bool condenseWhiteSpace; +}; + + +/** The parent class for everything in the Document Object Model. + (Except for attributes). + Nodes have siblings, a parent, and children. A node can be + in a document, or stand on its own. The type of a TiXmlNode + can be queried, and it can be cast to its more defined type. +*/ +class TiXmlNode : public TiXmlBase +{ + friend class TiXmlDocument; + friend class TiXmlElement; + +public: + #ifdef TIXML_USE_STL + + /** An input stream operator, for every class. Tolerant of newlines and + formatting, but doesn't expect them. + */ + friend std::istream& operator >> (std::istream& in, TiXmlNode& base); + + /** An output stream operator, for every class. Note that this outputs + without any newlines or formatting, as opposed to Print(), which + includes tabs and new lines. + + The operator<< and operator>> are not completely symmetric. Writing + a node to a stream is very well defined. You'll get a nice stream + of output, without any extra whitespace or newlines. + + But reading is not as well defined. (As it always is.) If you create + a TiXmlElement (for example) and read that from an input stream, + the text needs to define an element or junk will result. This is + true of all input streams, but it's worth keeping in mind. + + A TiXmlDocument will read nodes until it reads a root element, and + all the children of that root element. + */ + friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base); + + /// Appends the XML node or attribute to a std::string. + friend std::string& operator<< (std::string& out, const TiXmlNode& base ); + + #endif + + /** The types of XML nodes supported by TinyXml. (All the + unsupported types are picked up by UNKNOWN.) + */ + enum NodeType + { + TINYXML_DOCUMENT, + TINYXML_ELEMENT, + TINYXML_COMMENT, + TINYXML_UNKNOWN, + TINYXML_TEXT, + TINYXML_DECLARATION, + TINYXML_TYPECOUNT + }; + + virtual ~TiXmlNode(); + + /** The meaning of 'value' changes for the specific type of + TiXmlNode. + @verbatim + Document: filename of the xml file + Element: name of the element + Comment: the comment text + Unknown: the tag contents + Text: the text string + @endverbatim + + The subclasses will wrap this function. + */ + const char *Value() const { return value.c_str (); } + + #ifdef TIXML_USE_STL + /** Return Value() as a std::string. If you only use STL, + this is more efficient than calling Value(). + Only available in STL mode. + */ + const std::string& ValueStr() const { return value; } + #endif + + const TIXML_STRING& ValueTStr() const { return value; } + + /** Changes the value of the node. Defined as: + @verbatim + Document: filename of the xml file + Element: name of the element + Comment: the comment text + Unknown: the tag contents + Text: the text string + @endverbatim + */ + void SetValue(const char * _value) { value = _value;} + + #ifdef TIXML_USE_STL + /// STL std::string form. + void SetValue( const std::string& _value ) { value = _value; } + #endif + + /// Delete all the children of this node. Does not affect 'this'. + void Clear(); + + /// One step up the DOM. + TiXmlNode* Parent() { return parent; } + const TiXmlNode* Parent() const { return parent; } + + const TiXmlNode* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children. + TiXmlNode* FirstChild() { return firstChild; } + const TiXmlNode* FirstChild( const char * value ) const; ///< The first child of this node with the matching 'value'. Will be null if none found. + /// The first child of this node with the matching 'value'. Will be null if none found. + TiXmlNode* FirstChild( const char * _value ) { + // Call through to the const version - safe since nothing is changed. Exiting syntax: cast this to a const (always safe) + // call the method, cast the return back to non-const. + return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value )); + } + const TiXmlNode* LastChild() const { return lastChild; } /// The last child of this node. Will be null if there are no children. + TiXmlNode* LastChild() { return lastChild; } + + const TiXmlNode* LastChild( const char * value ) const; /// The last child of this node matching 'value'. Will be null if there are no children. + TiXmlNode* LastChild( const char * _value ) { + return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value )); + } + + #ifdef TIXML_USE_STL + const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); } ///< STL std::string form. + TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); } ///< STL std::string form. + const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); } ///< STL std::string form. + TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); } ///< STL std::string form. + #endif + + /** An alternate way to walk the children of a node. + One way to iterate over nodes is: + @verbatim + for( child = parent->FirstChild(); child; child = child->NextSibling() ) + @endverbatim + + IterateChildren does the same thing with the syntax: + @verbatim + child = 0; + while( child = parent->IterateChildren( child ) ) + @endverbatim + + IterateChildren takes the previous child as input and finds + the next one. If the previous child is null, it returns the + first. IterateChildren will return null when done. + */ + const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const; + TiXmlNode* IterateChildren( const TiXmlNode* previous ) { + return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) ); + } + + /// This flavor of IterateChildren searches for children with a particular 'value' + const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const; + TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) { + return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) ); + } + + #ifdef TIXML_USE_STL + const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. + TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. + #endif + + /** Add a new node related to this. Adds a child past the LastChild. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNode* InsertEndChild( const TiXmlNode& addThis ); + + + /** Add a new node related to this. Adds a child past the LastChild. + + NOTE: the node to be added is passed by pointer, and will be + henceforth owned (and deleted) by tinyXml. This method is efficient + and avoids an extra copy, but should be used with care as it + uses a different memory model than the other insert functions. + + @sa InsertEndChild + */ + TiXmlNode* LinkEndChild( TiXmlNode* addThis ); + + /** Add a new node related to this. Adds a child before the specified child. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ); + + /** Add a new node related to this. Adds a child after the specified child. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ); + + /** Replace a child of this node. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ); + + /// Delete a child of this node. + bool RemoveChild( TiXmlNode* removeThis ); + + /// Navigate to a sibling node. + const TiXmlNode* PreviousSibling() const { return prev; } + TiXmlNode* PreviousSibling() { return prev; } + + /// Navigate to a sibling node. + const TiXmlNode* PreviousSibling( const char * ) const; + TiXmlNode* PreviousSibling( const char *_prev ) { + return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) ); + } + + #ifdef TIXML_USE_STL + const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. + TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. + const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); } ///< STL std::string form. + TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); } ///< STL std::string form. + #endif + + /// Navigate to a sibling node. + const TiXmlNode* NextSibling() const { return next; } + TiXmlNode* NextSibling() { return next; } + + /// Navigate to a sibling node with the given 'value'. + const TiXmlNode* NextSibling( const char * ) const; + TiXmlNode* NextSibling( const char* _next ) { + return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) ); + } + + /** Convenience function to get through elements. + Calls NextSibling and ToElement. Will skip all non-Element + nodes. Returns 0 if there is not another element. + */ + const TiXmlElement* NextSiblingElement() const; + TiXmlElement* NextSiblingElement() { + return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() ); + } + + /** Convenience function to get through elements. + Calls NextSibling and ToElement. Will skip all non-Element + nodes. Returns 0 if there is not another element. + */ + const TiXmlElement* NextSiblingElement( const char * ) const; + TiXmlElement* NextSiblingElement( const char *_next ) { + return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) ); + } + + #ifdef TIXML_USE_STL + const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. + TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. + #endif + + /// Convenience function to get through elements. + const TiXmlElement* FirstChildElement() const; + TiXmlElement* FirstChildElement() { + return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() ); + } + + /// Convenience function to get through elements. + const TiXmlElement* FirstChildElement( const char * _value ) const; + TiXmlElement* FirstChildElement( const char * _value ) { + return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) ); + } + + #ifdef TIXML_USE_STL + const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. + TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. + #endif + + /** Query the type (as an enumerated value, above) of this node. + The possible types are: TINYXML_DOCUMENT, TINYXML_ELEMENT, TINYXML_COMMENT, + TINYXML_UNKNOWN, TINYXML_TEXT, and TINYXML_DECLARATION. + */ + int Type() const { return type; } + + /** Return a pointer to the Document this node lives in. + Returns null if not in a document. + */ + const TiXmlDocument* GetDocument() const; + TiXmlDocument* GetDocument() { + return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() ); + } + + /// Returns true if this node has no children. + bool NoChildren() const { return !firstChild; } + + virtual const TiXmlDocument* ToDocument() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual const TiXmlElement* ToElement() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual const TiXmlComment* ToComment() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual const TiXmlUnknown* ToUnknown() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual const TiXmlText* ToText() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual const TiXmlDeclaration* ToDeclaration() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + + virtual TiXmlDocument* ToDocument() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual TiXmlElement* ToElement() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual TiXmlComment* ToComment() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual TiXmlUnknown* ToUnknown() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual TiXmlText* ToText() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual TiXmlDeclaration* ToDeclaration() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + + /** Create an exact duplicate of this node and return it. The memory must be deleted + by the caller. + */ + virtual TiXmlNode* Clone() const = 0; + + /** Accept a hierchical visit the nodes in the TinyXML DOM. Every node in the + XML tree will be conditionally visited and the host will be called back + via the TiXmlVisitor interface. + + This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse + the XML for the callbacks, so the performance of TinyXML is unchanged by using this + interface versus any other.) + + The interface has been based on ideas from: + + - http://www.saxproject.org/ + - http://c2.com/cgi/wiki?HierarchicalVisitorPattern + + Which are both good references for "visiting". + + An example of using Accept(): + @verbatim + TiXmlPrinter printer; + tinyxmlDoc.Accept( &printer ); + const char* xmlcstr = printer.CStr(); + @endverbatim + */ + virtual bool Accept( TiXmlVisitor* visitor ) const = 0; + +protected: + TiXmlNode( NodeType _type ); + + // Copy to the allocated object. Shared functionality between Clone, Copy constructor, + // and the assignment operator. + void CopyTo( TiXmlNode* target ) const; + + #ifdef TIXML_USE_STL + // The real work of the input operator. + virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0; + #endif + + // Figure out what is at *p, and parse it. Returns null if it is not an xml node. + TiXmlNode* Identify( const char* start, TiXmlEncoding encoding ); + + TiXmlNode* parent; + NodeType type; + + TiXmlNode* firstChild; + TiXmlNode* lastChild; + + TIXML_STRING value; + + TiXmlNode* prev; + TiXmlNode* next; + +private: + TiXmlNode( const TiXmlNode& ); // not implemented. + void operator=( const TiXmlNode& base ); // not allowed. +}; + + +/** An attribute is a name-value pair. Elements have an arbitrary + number of attributes, each with a unique name. + + @note The attributes are not TiXmlNodes, since they are not + part of the tinyXML document object model. There are other + suggested ways to look at this problem. +*/ +class TiXmlAttribute : public TiXmlBase +{ + friend class TiXmlAttributeSet; + +public: + /// Construct an empty attribute. + TiXmlAttribute() : TiXmlBase() + { + document = 0; + prev = next = 0; + } + + #ifdef TIXML_USE_STL + /// std::string constructor. + TiXmlAttribute( const std::string& _name, const std::string& _value ) + { + name = _name; + value = _value; + document = 0; + prev = next = 0; + } + #endif + + /// Construct an attribute with a name and value. + TiXmlAttribute( const char * _name, const char * _value ) + { + name = _name; + value = _value; + document = 0; + prev = next = 0; + } + + const char* Name() const { return name.c_str(); } ///< Return the name of this attribute. + const char* Value() const { return value.c_str(); } ///< Return the value of this attribute. + #ifdef TIXML_USE_STL + const std::string& ValueStr() const { return value; } ///< Return the value of this attribute. + #endif + int IntValue() const; ///< Return the value of this attribute, converted to an integer. + double DoubleValue() const; ///< Return the value of this attribute, converted to a double. + + // Get the tinyxml string representation + const TIXML_STRING& NameTStr() const { return name; } + + /** QueryIntValue examines the value string. It is an alternative to the + IntValue() method with richer error checking. + If the value is an integer, it is stored in 'value' and + the call returns TIXML_SUCCESS. If it is not + an integer, it returns TIXML_WRONG_TYPE. + + A specialized but useful call. Note that for success it returns 0, + which is the opposite of almost all other TinyXml calls. + */ + int QueryIntValue( int* _value ) const; + /// QueryDoubleValue examines the value string. See QueryIntValue(). + int QueryDoubleValue( double* _value ) const; + + void SetName( const char* _name ) { name = _name; } ///< Set the name of this attribute. + void SetValue( const char* _value ) { value = _value; } ///< Set the value. + + void SetIntValue( int _value ); ///< Set the value from an integer. + void SetDoubleValue( double _value ); ///< Set the value from a double. + + #ifdef TIXML_USE_STL + /// STL std::string form. + void SetName( const std::string& _name ) { name = _name; } + /// STL std::string form. + void SetValue( const std::string& _value ) { value = _value; } + #endif + + /// Get the next sibling attribute in the DOM. Returns null at end. + const TiXmlAttribute* Next() const; + TiXmlAttribute* Next() { + return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() ); + } + + /// Get the previous sibling attribute in the DOM. Returns null at beginning. + const TiXmlAttribute* Previous() const; + TiXmlAttribute* Previous() { + return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() ); + } + + bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; } + bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; } + bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; } + + /* Attribute parsing starts: first letter of the name + returns: the next char after the value end quote + */ + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + + // Prints this Attribute to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const { + Print( cfile, depth, 0 ); + } + void Print( FILE* cfile, int depth, TIXML_STRING* str ) const; + + // [internal use] + // Set the document pointer so the attribute can report errors. + void SetDocument( TiXmlDocument* doc ) { document = doc; } + +private: + TiXmlAttribute( const TiXmlAttribute& ); // not implemented. + void operator=( const TiXmlAttribute& base ); // not allowed. + + TiXmlDocument* document; // A pointer back to a document, for error reporting. + TIXML_STRING name; + TIXML_STRING value; + TiXmlAttribute* prev; + TiXmlAttribute* next; +}; + + +/* A class used to manage a group of attributes. + It is only used internally, both by the ELEMENT and the DECLARATION. + + The set can be changed transparent to the Element and Declaration + classes that use it, but NOT transparent to the Attribute + which has to implement a next() and previous() method. Which makes + it a bit problematic and prevents the use of STL. + + This version is implemented with circular lists because: + - I like circular lists + - it demonstrates some independence from the (typical) doubly linked list. +*/ +class TiXmlAttributeSet +{ +public: + TiXmlAttributeSet(); + ~TiXmlAttributeSet(); + + void Add( TiXmlAttribute* attribute ); + void Remove( TiXmlAttribute* attribute ); + + const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } + TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } + const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } + TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } + + TiXmlAttribute* Find( const char* _name ) const; + TiXmlAttribute* FindOrCreate( const char* _name ); + +# ifdef TIXML_USE_STL + TiXmlAttribute* Find( const std::string& _name ) const; + TiXmlAttribute* FindOrCreate( const std::string& _name ); +# endif + + +private: + //*ME: Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element), + //*ME: this class must be also use a hidden/disabled copy-constructor !!! + TiXmlAttributeSet( const TiXmlAttributeSet& ); // not allowed + void operator=( const TiXmlAttributeSet& ); // not allowed (as TiXmlAttribute) + + TiXmlAttribute sentinel; +}; + + +/** The element is a container class. It has a value, the element name, + and can contain other elements, text, comments, and unknowns. + Elements also contain an arbitrary number of attributes. +*/ +class TiXmlElement : public TiXmlNode +{ +public: + /// Construct an element. + TiXmlElement (const char * in_value); + + #ifdef TIXML_USE_STL + /// std::string constructor. + TiXmlElement( const std::string& _value ); + #endif + + TiXmlElement( const TiXmlElement& ); + + TiXmlElement& operator=( const TiXmlElement& base ); + + virtual ~TiXmlElement(); + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + */ + const char* Attribute( const char* name ) const; + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + If the attribute exists and can be converted to an integer, + the integer value will be put in the return 'i', if 'i' + is non-null. + */ + const char* Attribute( const char* name, int* i ) const; + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + If the attribute exists and can be converted to an double, + the double value will be put in the return 'd', if 'd' + is non-null. + */ + const char* Attribute( const char* name, double* d ) const; + + /** QueryIntAttribute examines the attribute - it is an alternative to the + Attribute() method with richer error checking. + If the attribute is an integer, it is stored in 'value' and + the call returns TIXML_SUCCESS. If it is not + an integer, it returns TIXML_WRONG_TYPE. If the attribute + does not exist, then TIXML_NO_ATTRIBUTE is returned. + */ + int QueryIntAttribute( const char* name, int* _value ) const; + /// QueryUnsignedAttribute examines the attribute - see QueryIntAttribute(). + int QueryUnsignedAttribute( const char* name, unsigned* _value ) const; + /** QueryBoolAttribute examines the attribute - see QueryIntAttribute(). + Note that '1', 'true', or 'yes' are considered true, while '0', 'false' + and 'no' are considered false. + */ + int QueryBoolAttribute( const char* name, bool* _value ) const; + /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). + int QueryDoubleAttribute( const char* name, double* _value ) const; + /// QueryFloatAttribute examines the attribute - see QueryIntAttribute(). + int QueryFloatAttribute( const char* name, float* _value ) const { + double d; + int result = QueryDoubleAttribute( name, &d ); + if ( result == TIXML_SUCCESS ) { + *_value = (float)d; + } + return result; + } + + #ifdef TIXML_USE_STL + /// QueryStringAttribute examines the attribute - see QueryIntAttribute(). + int QueryStringAttribute( const char* name, std::string* _value ) const { + const char* cstr = Attribute( name ); + if ( cstr ) { + *_value = std::string( cstr ); + return TIXML_SUCCESS; + } + return TIXML_NO_ATTRIBUTE; + } + + /** Template form of the attribute query which will try to read the + attribute into the specified type. Very easy, very powerful, but + be careful to make sure to call this with the correct type. + + NOTE: This method doesn't work correctly for 'string' types that contain spaces. + + @return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE + */ + template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const + { + const TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + + std::stringstream sstream( node->ValueStr() ); + sstream >> *outValue; + if ( !sstream.fail() ) + return TIXML_SUCCESS; + return TIXML_WRONG_TYPE; + } + + int QueryValueAttribute( const std::string& name, std::string* outValue ) const + { + const TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + *outValue = node->ValueStr(); + return TIXML_SUCCESS; + } + #endif + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetAttribute( const char* name, const char * _value ); + + #ifdef TIXML_USE_STL + const std::string* Attribute( const std::string& name ) const; + const std::string* Attribute( const std::string& name, int* i ) const; + const std::string* Attribute( const std::string& name, double* d ) const; + int QueryIntAttribute( const std::string& name, int* _value ) const; + int QueryDoubleAttribute( const std::string& name, double* _value ) const; + + /// STL std::string form. + void SetAttribute( const std::string& name, const std::string& _value ); + ///< STL std::string form. + void SetAttribute( const std::string& name, int _value ); + ///< STL std::string form. + void SetDoubleAttribute( const std::string& name, double value ); + #endif + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetAttribute( const char * name, int value ); + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetDoubleAttribute( const char * name, double value ); + + /** Deletes an attribute with the given name. + */ + void RemoveAttribute( const char * name ); + #ifdef TIXML_USE_STL + void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); } ///< STL std::string form. + #endif + + const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); } ///< Access the first attribute in this element. + TiXmlAttribute* FirstAttribute() { return attributeSet.First(); } + const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); } ///< Access the last attribute in this element. + TiXmlAttribute* LastAttribute() { return attributeSet.Last(); } + + /** Convenience function for easy access to the text inside an element. Although easy + and concise, GetText() is limited compared to getting the TiXmlText child + and accessing it directly. + + If the first child of 'this' is a TiXmlText, the GetText() + returns the character string of the Text node, else null is returned. + + This is a convenient method for getting the text of simple contained text: + @verbatim + This is text + const char* str = fooElement->GetText(); + @endverbatim + + 'str' will be a pointer to "This is text". + + Note that this function can be misleading. If the element foo was created from + this XML: + @verbatim + This is text + @endverbatim + + then the value of str would be null. The first child node isn't a text node, it is + another element. From this XML: + @verbatim + This is text + @endverbatim + GetText() will return "This is ". + + WARNING: GetText() accesses a child node - don't become confused with the + similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are + safe type casts on the referenced node. + */ + const char* GetText() const; + + /// Creates a new Element and returns it - the returned element is a copy. + virtual TiXmlNode* Clone() const; + // Print the Element to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + /* Attribtue parsing starts: next char past '<' + returns: next char past '>' + */ + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + + virtual const TiXmlElement* ToElement() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual TiXmlElement* ToElement() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( TiXmlVisitor* visitor ) const; + +protected: + + void CopyTo( TiXmlElement* target ) const; + void ClearThis(); // like clear, but initializes 'this' object as well + + // Used to be public [internal use] + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif + /* [internal use] + Reads the "value" of the element -- another element, or text. + This should terminate with the current end tag. + */ + const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding ); + +private: + TiXmlAttributeSet attributeSet; +}; + + +/** An XML comment. +*/ +class TiXmlComment : public TiXmlNode +{ +public: + /// Constructs an empty comment. + TiXmlComment() : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) {} + /// Construct a comment from text. + TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) { + SetValue( _value ); + } + TiXmlComment( const TiXmlComment& ); + TiXmlComment& operator=( const TiXmlComment& base ); + + virtual ~TiXmlComment() {} + + /// Returns a copy of this Comment. + virtual TiXmlNode* Clone() const; + // Write this Comment to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + /* Attribtue parsing starts: at the ! of the !-- + returns: next char past '>' + */ + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + + virtual const TiXmlComment* ToComment() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual TiXmlComment* ToComment() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( TiXmlVisitor* visitor ) const; + +protected: + void CopyTo( TiXmlComment* target ) const; + + // used to be public + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif +// virtual void StreamOut( TIXML_OSTREAM * out ) const; + +private: + +}; + + +/** XML text. A text node can have 2 ways to output the next. "normal" output + and CDATA. It will default to the mode it was parsed from the XML file and + you generally want to leave it alone, but you can change the output mode with + SetCDATA() and query it with CDATA(). +*/ +class TiXmlText : public TiXmlNode +{ + friend class TiXmlElement; +public: + /** Constructor for text element. By default, it is treated as + normal, encoded text. If you want it be output as a CDATA text + element, set the parameter _cdata to 'true' + */ + TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT) + { + SetValue( initValue ); + cdata = false; + } + virtual ~TiXmlText() {} + + #ifdef TIXML_USE_STL + /// Constructor. + TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT) + { + SetValue( initValue ); + cdata = false; + } + #endif + + TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TINYXML_TEXT ) { copy.CopyTo( this ); } + TiXmlText& operator=( const TiXmlText& base ) { base.CopyTo( this ); return *this; } + + // Write this text object to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + /// Queries whether this represents text using a CDATA section. + bool CDATA() const { return cdata; } + /// Turns on or off a CDATA representation of text. + void SetCDATA( bool _cdata ) { cdata = _cdata; } + + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + + virtual const TiXmlText* ToText() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual TiXmlText* ToText() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( TiXmlVisitor* content ) const; + +protected : + /// [internal use] Creates a new Element and returns it. + virtual TiXmlNode* Clone() const; + void CopyTo( TiXmlText* target ) const; + + bool Blank() const; // returns true if all white space and new lines + // [internal use] + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif + +private: + bool cdata; // true if this should be input and output as a CDATA style text element +}; + + +/** In correct XML the declaration is the first entry in the file. + @verbatim + + @endverbatim + + TinyXml will happily read or write files without a declaration, + however. There are 3 possible attributes to the declaration: + version, encoding, and standalone. + + Note: In this version of the code, the attributes are + handled as special cases, not generic attributes, simply + because there can only be at most 3 and they are always the same. +*/ +class TiXmlDeclaration : public TiXmlNode +{ +public: + /// Construct an empty declaration. + TiXmlDeclaration() : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) {} + +#ifdef TIXML_USE_STL + /// Constructor. + TiXmlDeclaration( const std::string& _version, + const std::string& _encoding, + const std::string& _standalone ); +#endif + + /// Construct. + TiXmlDeclaration( const char* _version, + const char* _encoding, + const char* _standalone ); + + TiXmlDeclaration( const TiXmlDeclaration& copy ); + TiXmlDeclaration& operator=( const TiXmlDeclaration& copy ); + + virtual ~TiXmlDeclaration() {} + + /// Version. Will return an empty string if none was found. + const char *Version() const { return version.c_str (); } + /// Encoding. Will return an empty string if none was found. + const char *Encoding() const { return encoding.c_str (); } + /// Is this a standalone document? + const char *Standalone() const { return standalone.c_str (); } + + /// Creates a copy of this Declaration and returns it. + virtual TiXmlNode* Clone() const; + // Print this declaration to a FILE stream. + virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const; + virtual void Print( FILE* cfile, int depth ) const { + Print( cfile, depth, 0 ); + } + + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + + virtual const TiXmlDeclaration* ToDeclaration() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual TiXmlDeclaration* ToDeclaration() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( TiXmlVisitor* visitor ) const; + +protected: + void CopyTo( TiXmlDeclaration* target ) const; + // used to be public + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif + +private: + + TIXML_STRING version; + TIXML_STRING encoding; + TIXML_STRING standalone; +}; + + +/** Any tag that tinyXml doesn't recognize is saved as an + unknown. It is a tag of text, but should not be modified. + It will be written back to the XML, unchanged, when the file + is saved. + + DTD tags get thrown into TiXmlUnknowns. +*/ +class TiXmlUnknown : public TiXmlNode +{ +public: + TiXmlUnknown() : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN ) {} + virtual ~TiXmlUnknown() {} + + TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN ) { copy.CopyTo( this ); } + TiXmlUnknown& operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); return *this; } + + /// Creates a copy of this Unknown and returns it. + virtual TiXmlNode* Clone() const; + // Print this Unknown to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + + virtual const TiXmlUnknown* ToUnknown() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual TiXmlUnknown* ToUnknown() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( TiXmlVisitor* content ) const; + +protected: + void CopyTo( TiXmlUnknown* target ) const; + + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif + +private: + +}; + + +/** Always the top level node. A document binds together all the + XML pieces. It can be saved, loaded, and printed to the screen. + The 'value' of a document node is the xml file name. +*/ +class TiXmlDocument : public TiXmlNode +{ +public: + /// Create an empty document, that has no name. + TiXmlDocument(); + /// Create a document with a name. The name of the document is also the filename of the xml. + TiXmlDocument( const char * documentName ); + + #ifdef TIXML_USE_STL + /// Constructor. + TiXmlDocument( const std::string& documentName ); + #endif + + TiXmlDocument( const TiXmlDocument& copy ); + TiXmlDocument& operator=( const TiXmlDocument& copy ); + + virtual ~TiXmlDocument() {} + + /** Load a file using the current document value. + Returns true if successful. Will delete any existing + document data before loading. + */ + bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); + /// Save a file using the current document value. Returns true if successful. + bool SaveFile() const; + /// Load a file using the given filename. Returns true if successful. + bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); + /// Save a file using the given filename. Returns true if successful. + bool SaveFile( const char * filename ) const; + /** Load a file using the given FILE*. Returns true if successful. Note that this method + doesn't stream - the entire object pointed at by the FILE* + will be interpreted as an XML file. TinyXML doesn't stream in XML from the current + file location. Streaming may be added in the future. + */ + bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); + /// Save a file using the given FILE*. Returns true if successful. + bool SaveFile( FILE* ) const; + + #ifdef TIXML_USE_STL + bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ) ///< STL std::string version. + { + return LoadFile( filename.c_str(), encoding ); + } + bool SaveFile( const std::string& filename ) const ///< STL std::string version. + { + return SaveFile( filename.c_str() ); + } + #endif + + /** Parse the given null terminated block of xml data. Passing in an encoding to this + method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml + to use that encoding, regardless of what TinyXml might otherwise try to detect. + */ + virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); + + /** Get the root element -- the only top level element -- of the document. + In well formed XML, there should only be one. TinyXml is tolerant of + multiple elements at the document level. + */ + const TiXmlElement* RootElement() const { return FirstChildElement(); } + TiXmlElement* RootElement() { return FirstChildElement(); } + + /** If an error occurs, Error will be set to true. Also, + - The ErrorId() will contain the integer identifier of the error (not generally useful) + - The ErrorDesc() method will return the name of the error. (very useful) + - The ErrorRow() and ErrorCol() will return the location of the error (if known) + */ + bool Error() const { return error; } + + /// Contains a textual (english) description of the error if one occurs. + const char * ErrorDesc() const { return errorDesc.c_str (); } + + /** Generally, you probably want the error string ( ErrorDesc() ). But if you + prefer the ErrorId, this function will fetch it. + */ + int ErrorId() const { return errorId; } + + /** Returns the location (if known) of the error. The first column is column 1, + and the first row is row 1. A value of 0 means the row and column wasn't applicable + (memory errors, for example, have no row/column) or the parser lost the error. (An + error in the error reporting, in that case.) + + @sa SetTabSize, Row, Column + */ + int ErrorRow() const { return errorLocation.row+1; } + int ErrorCol() const { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow() + + /** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol()) + to report the correct values for row and column. It does not change the output + or input in any way. + + By calling this method, with a tab size + greater than 0, the row and column of each node and attribute is stored + when the file is loaded. Very useful for tracking the DOM back in to + the source file. + + The tab size is required for calculating the location of nodes. If not + set, the default of 4 is used. The tabsize is set per document. Setting + the tabsize to 0 disables row/column tracking. + + Note that row and column tracking is not supported when using operator>>. + + The tab size needs to be enabled before the parse or load. Correct usage: + @verbatim + TiXmlDocument doc; + doc.SetTabSize( 8 ); + doc.Load( "myfile.xml" ); + @endverbatim + + @sa Row, Column + */ + void SetTabSize( int _tabsize ) { tabsize = _tabsize; } + + int TabSize() const { return tabsize; } + + /** If you have handled the error, it can be reset with this call. The error + state is automatically cleared if you Parse a new XML block. + */ + void ClearError() { error = false; + errorId = 0; + errorDesc = ""; + errorLocation.row = errorLocation.col = 0; + //errorLocation.last = 0; + } + + /** Write the document to standard out using formatted printing ("pretty print"). */ + void Print() const { Print( stdout, 0 ); } + + /* Write the document to a string using formatted printing ("pretty print"). This + will allocate a character array (new char[]) and return it as a pointer. The + calling code pust call delete[] on the return char* to avoid a memory leak. + */ + //char* PrintToMemory() const; + + /// Print this Document to a FILE stream. + virtual void Print( FILE* cfile, int depth = 0 ) const; + // [internal use] + void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding ); + + virtual const TiXmlDocument* ToDocument() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual TiXmlDocument* ToDocument() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( TiXmlVisitor* content ) const; + +protected : + // [internal use] + virtual TiXmlNode* Clone() const; + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif + +private: + void CopyTo( TiXmlDocument* target ) const; + + bool error; + int errorId; + TIXML_STRING errorDesc; + int tabsize; + TiXmlCursor errorLocation; + bool useMicrosoftBOM; // the UTF-8 BOM were found when read. Note this, and try to write. +}; + + +/** + A TiXmlHandle is a class that wraps a node pointer with null checks; this is + an incredibly useful thing. Note that TiXmlHandle is not part of the TinyXml + DOM structure. It is a separate utility class. + + Take an example: + @verbatim + + + + + + + @endverbatim + + Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very + easy to write a *lot* of code that looks like: + + @verbatim + TiXmlElement* root = document.FirstChildElement( "Document" ); + if ( root ) + { + TiXmlElement* element = root->FirstChildElement( "Element" ); + if ( element ) + { + TiXmlElement* child = element->FirstChildElement( "Child" ); + if ( child ) + { + TiXmlElement* child2 = child->NextSiblingElement( "Child" ); + if ( child2 ) + { + // Finally do something useful. + @endverbatim + + And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity + of such code. A TiXmlHandle checks for null pointers so it is perfectly safe + and correct to use: + + @verbatim + TiXmlHandle docHandle( &document ); + TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).ToElement(); + if ( child2 ) + { + // do something useful + @endverbatim + + Which is MUCH more concise and useful. + + It is also safe to copy handles - internally they are nothing more than node pointers. + @verbatim + TiXmlHandle handleCopy = handle; + @endverbatim + + What they should not be used for is iteration: + + @verbatim + int i=0; + while ( true ) + { + TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).ToElement(); + if ( !child ) + break; + // do something + ++i; + } + @endverbatim + + It seems reasonable, but it is in fact two embedded while loops. The Child method is + a linear walk to find the element, so this code would iterate much more than it needs + to. Instead, prefer: + + @verbatim + TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).ToElement(); + + for( child; child; child=child->NextSiblingElement() ) + { + // do something + } + @endverbatim +*/ +class TiXmlHandle +{ +public: + /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. + TiXmlHandle( TiXmlNode* _node ) { this->node = _node; } + /// Copy constructor + TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; } + TiXmlHandle operator=( const TiXmlHandle& ref ) { if ( &ref != this ) this->node = ref.node; return *this; } + + /// Return a handle to the first child node. + TiXmlHandle FirstChild() const; + /// Return a handle to the first child node with the given name. + TiXmlHandle FirstChild( const char * value ) const; + /// Return a handle to the first child element. + TiXmlHandle FirstChildElement() const; + /// Return a handle to the first child element with the given name. + TiXmlHandle FirstChildElement( const char * value ) const; + + /** Return a handle to the "index" child with the given name. + The first child is 0, the second 1, etc. + */ + TiXmlHandle Child( const char* value, int index ) const; + /** Return a handle to the "index" child. + The first child is 0, the second 1, etc. + */ + TiXmlHandle Child( int index ) const; + /** Return a handle to the "index" child element with the given name. + The first child element is 0, the second 1, etc. Note that only TiXmlElements + are indexed: other types are not counted. + */ + TiXmlHandle ChildElement( const char* value, int index ) const; + /** Return a handle to the "index" child element. + The first child element is 0, the second 1, etc. Note that only TiXmlElements + are indexed: other types are not counted. + */ + TiXmlHandle ChildElement( int index ) const; + + #ifdef TIXML_USE_STL + TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); } + TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); } + + TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); } + TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); } + #endif + + /** Return the handle as a TiXmlNode. This may return null. + */ + TiXmlNode* ToNode() const { return node; } + /** Return the handle as a TiXmlElement. This may return null. + */ + TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); } + /** Return the handle as a TiXmlText. This may return null. + */ + TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); } + /** Return the handle as a TiXmlUnknown. This may return null. + */ + TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); } + + /** @deprecated use ToNode. + Return the handle as a TiXmlNode. This may return null. + */ + TiXmlNode* Node() const { return ToNode(); } + /** @deprecated use ToElement. + Return the handle as a TiXmlElement. This may return null. + */ + TiXmlElement* Element() const { return ToElement(); } + /** @deprecated use ToText() + Return the handle as a TiXmlText. This may return null. + */ + TiXmlText* Text() const { return ToText(); } + /** @deprecated use ToUnknown() + Return the handle as a TiXmlUnknown. This may return null. + */ + TiXmlUnknown* Unknown() const { return ToUnknown(); } + +private: + TiXmlNode* node; +}; + + +/** Print to memory functionality. The TiXmlPrinter is useful when you need to: + + -# Print to memory (especially in non-STL mode) + -# Control formatting (line endings, etc.) + + When constructed, the TiXmlPrinter is in its default "pretty printing" mode. + Before calling Accept() you can call methods to control the printing + of the XML document. After TiXmlNode::Accept() is called, the printed document can + be accessed via the CStr(), Str(), and Size() methods. + + TiXmlPrinter uses the Visitor API. + @verbatim + TiXmlPrinter printer; + printer.SetIndent( "\t" ); + + doc.Accept( &printer ); + fprintf( stdout, "%s", printer.CStr() ); + @endverbatim +*/ +class TiXmlPrinter : public TiXmlVisitor +{ +public: + TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ), + buffer(), indent( " " ), lineBreak( "\n" ) {} + + virtual bool VisitEnter( const TiXmlDocument& doc ); + virtual bool VisitExit( const TiXmlDocument& doc ); + + virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute ); + virtual bool VisitExit( const TiXmlElement& element ); + + virtual bool Visit( const TiXmlDeclaration& declaration ); + virtual bool Visit( const TiXmlText& text ); + virtual bool Visit( const TiXmlComment& comment ); + virtual bool Visit( const TiXmlUnknown& unknown ); + + /** Set the indent characters for printing. By default 4 spaces + but tab (\t) is also useful, or null/empty string for no indentation. + */ + void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; } + /// Query the indention string. + const char* Indent() { return indent.c_str(); } + /** Set the line breaking string. By default set to newline (\n). + Some operating systems prefer other characters, or can be + set to the null/empty string for no indenation. + */ + void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; } + /// Query the current line breaking string. + const char* LineBreak() { return lineBreak.c_str(); } + + /** Switch over to "stream printing" which is the most dense formatting without + linebreaks. Common when the XML is needed for network transmission. + */ + void SetStreamPrinting() { indent = ""; + lineBreak = ""; + } + /// Return the result. + const char* CStr() { return buffer.c_str(); } + /// Return the length of the result string. + size_t Size() { return buffer.size(); } + + #ifdef TIXML_USE_STL + /// Return the result. + const std::string& Str() { return buffer; } + #endif + +private: + void DoIndent() { + for( int i=0; i +#include + +#include "tinyxml.h" + +//#define DEBUG_PARSER +#if defined( DEBUG_PARSER ) +# if defined( DEBUG ) && defined( _MSC_VER ) +# include +# define TIXML_LOG OutputDebugString +# else +# define TIXML_LOG printf +# endif +#endif + +// Note tha "PutString" hardcodes the same list. This +// is less flexible than it appears. Changing the entries +// or order will break putstring. +TiXmlBase::Entity TiXmlBase::entity[ TiXmlBase::NUM_ENTITY ] = +{ + { "&", 5, '&' }, + { "<", 4, '<' }, + { ">", 4, '>' }, + { """, 6, '\"' }, + { "'", 6, '\'' } +}; + +// Bunch of unicode info at: +// http://www.unicode.org/faq/utf_bom.html +// Including the basic of this table, which determines the #bytes in the +// sequence from the lead byte. 1 placed for invalid sequences -- +// although the result will be junk, pass it through as much as possible. +// Beware of the non-characters in UTF-8: +// ef bb bf (Microsoft "lead bytes") +// ef bf be +// ef bf bf + +const unsigned char TIXML_UTF_LEAD_0 = 0xefU; +const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; +const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; + +const int TiXmlBase::utf8ByteTable[256] = +{ + // 0 1 2 3 4 5 6 7 8 9 a b c d e f + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x00 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x10 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x20 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x30 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x50 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x70 End of ASCII range + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x80 0x80 to 0xc1 invalid + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x90 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xa0 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xb0 + 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xc0 0xc2 to 0xdf 2 byte + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xd0 + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xe0 0xe0 to 0xef 3 byte + 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // 0xf0 0xf0 to 0xf4 4 byte, 0xf5 and higher invalid +}; + + +void TiXmlBase::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ) +{ + const unsigned long BYTE_MASK = 0xBF; + const unsigned long BYTE_MARK = 0x80; + const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; + + if (input < 0x80) + *length = 1; + else if ( input < 0x800 ) + *length = 2; + else if ( input < 0x10000 ) + *length = 3; + else if ( input < 0x200000 ) + *length = 4; + else + { *length = 0; return; } // This code won't covert this correctly anyway. + + output += *length; + + // Scary scary fall throughs. + switch (*length) + { + case 4: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + case 3: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + case 2: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + case 1: + --output; + *output = (char)(input | FIRST_BYTE_MARK[*length]); + } +} + + +/*static*/ int TiXmlBase::IsAlpha( unsigned char anyByte, TiXmlEncoding /*encoding*/ ) +{ + // This will only work for low-ascii, everything else is assumed to be a valid + // letter. I'm not sure this is the best approach, but it is quite tricky trying + // to figure out alhabetical vs. not across encoding. So take a very + // conservative approach. + +// if ( encoding == TIXML_ENCODING_UTF8 ) +// { + if ( anyByte < 127 ) + return isalpha( anyByte ); + else + return 1; // What else to do? The unicode set is huge...get the english ones right. +// } +// else +// { +// return isalpha( anyByte ); +// } +} + + +/*static*/ int TiXmlBase::IsAlphaNum( unsigned char anyByte, TiXmlEncoding /*encoding*/ ) +{ + // This will only work for low-ascii, everything else is assumed to be a valid + // letter. I'm not sure this is the best approach, but it is quite tricky trying + // to figure out alhabetical vs. not across encoding. So take a very + // conservative approach. + +// if ( encoding == TIXML_ENCODING_UTF8 ) +// { + if ( anyByte < 127 ) + return isalnum( anyByte ); + else + return 1; // What else to do? The unicode set is huge...get the english ones right. +// } +// else +// { +// return isalnum( anyByte ); +// } +} + + +class TiXmlParsingData +{ + friend class TiXmlDocument; + public: + void Stamp( const char* now, TiXmlEncoding encoding ); + + const TiXmlCursor& Cursor() const { return cursor; } + + private: + // Only used by the document! + TiXmlParsingData( const char* start, int _tabsize, int row, int col ) + { + assert( start ); + stamp = start; + tabsize = _tabsize; + cursor.row = row; + cursor.col = col; + } + + TiXmlCursor cursor; + const char* stamp; + int tabsize; +}; + + +void TiXmlParsingData::Stamp( const char* now, TiXmlEncoding encoding ) +{ + assert( now ); + + // Do nothing if the tabsize is 0. + if ( tabsize < 1 ) + { + return; + } + + // Get the current row, column. + int row = cursor.row; + int col = cursor.col; + const char* p = stamp; + assert( p ); + + while ( p < now ) + { + // Treat p as unsigned, so we have a happy compiler. + const unsigned char* pU = (const unsigned char*)p; + + // Code contributed by Fletcher Dunn: (modified by lee) + switch (*pU) { + case 0: + // We *should* never get here, but in case we do, don't + // advance past the terminating null character, ever + return; + + case '\r': + // bump down to the next line + ++row; + col = 0; + // Eat the character + ++p; + + // Check for \r\n sequence, and treat this as a single character + if (*p == '\n') { + ++p; + } + break; + + case '\n': + // bump down to the next line + ++row; + col = 0; + + // Eat the character + ++p; + + // Check for \n\r sequence, and treat this as a single + // character. (Yes, this bizarre thing does occur still + // on some arcane platforms...) + if (*p == '\r') { + ++p; + } + break; + + case '\t': + // Eat the character + ++p; + + // Skip to next tab stop + col = (col / tabsize + 1) * tabsize; + break; + + case TIXML_UTF_LEAD_0: + if ( encoding == TIXML_ENCODING_UTF8 ) + { + if ( *(p+1) && *(p+2) ) + { + // In these cases, don't advance the column. These are + // 0-width spaces. + if ( *(pU+1)==TIXML_UTF_LEAD_1 && *(pU+2)==TIXML_UTF_LEAD_2 ) + p += 3; + else if ( *(pU+1)==0xbfU && *(pU+2)==0xbeU ) + p += 3; + else if ( *(pU+1)==0xbfU && *(pU+2)==0xbfU ) + p += 3; + else + { p +=3; ++col; } // A normal character. + } + } + else + { + ++p; + ++col; + } + break; + + default: + if ( encoding == TIXML_ENCODING_UTF8 ) + { + // Eat the 1 to 4 byte utf8 character. + int step = TiXmlBase::utf8ByteTable[*((const unsigned char*)p)]; + if ( step == 0 ) + step = 1; // Error case from bad encoding, but handle gracefully. + p += step; + + // Just advance one column, of course. + ++col; + } + else + { + ++p; + ++col; + } + break; + } + } + cursor.row = row; + cursor.col = col; + assert( cursor.row >= -1 ); + assert( cursor.col >= -1 ); + stamp = p; + assert( stamp ); +} + + +const char* TiXmlBase::SkipWhiteSpace( const char* p, TiXmlEncoding encoding ) +{ + if ( !p || !*p ) + { + return 0; + } + if ( encoding == TIXML_ENCODING_UTF8 ) + { + while ( *p ) + { + const unsigned char* pU = (const unsigned char*)p; + + // Skip the stupid Microsoft UTF-8 Byte order marks + if ( *(pU+0)==TIXML_UTF_LEAD_0 + && *(pU+1)==TIXML_UTF_LEAD_1 + && *(pU+2)==TIXML_UTF_LEAD_2 ) + { + p += 3; + continue; + } + else if(*(pU+0)==TIXML_UTF_LEAD_0 + && *(pU+1)==0xbfU + && *(pU+2)==0xbeU ) + { + p += 3; + continue; + } + else if(*(pU+0)==TIXML_UTF_LEAD_0 + && *(pU+1)==0xbfU + && *(pU+2)==0xbfU ) + { + p += 3; + continue; + } + + if ( IsWhiteSpace( *p ) ) // Still using old rules for white space. + ++p; + else + break; + } + } + else + { + while ( *p && IsWhiteSpace( *p ) ) + ++p; + } + + return p; +} + +#ifdef TIXML_USE_STL +/*static*/ bool TiXmlBase::StreamWhiteSpace( std::istream * in, TIXML_STRING * tag ) +{ + for( ;; ) + { + if ( !in->good() ) return false; + + int c = in->peek(); + // At this scope, we can't get to a document. So fail silently. + if ( !IsWhiteSpace( c ) || c <= 0 ) + return true; + + *tag += (char) in->get(); + } +} + +/*static*/ bool TiXmlBase::StreamTo( std::istream * in, int character, TIXML_STRING * tag ) +{ + //assert( character > 0 && character < 128 ); // else it won't work in utf-8 + while ( in->good() ) + { + int c = in->peek(); + if ( c == character ) + return true; + if ( c <= 0 ) // Silent failure: can't get document at this scope + return false; + + in->get(); + *tag += (char) c; + } + return false; +} +#endif + +// One of TinyXML's more performance demanding functions. Try to keep the memory overhead down. The +// "assign" optimization removes over 10% of the execution time. +// +const char* TiXmlBase::ReadName( const char* p, TIXML_STRING * name, TiXmlEncoding encoding ) +{ + // Oddly, not supported on some comilers, + //name->clear(); + // So use this: + *name = ""; + assert( p ); + + // Names start with letters or underscores. + // Of course, in unicode, tinyxml has no idea what a letter *is*. The + // algorithm is generous. + // + // After that, they can be letters, underscores, numbers, + // hyphens, or colons. (Colons are valid ony for namespaces, + // but tinyxml can't tell namespaces from names.) + if ( p && *p + && ( IsAlpha( (unsigned char) *p, encoding ) || *p == '_' ) ) + { + const char* start = p; + while( p && *p + && ( IsAlphaNum( (unsigned char ) *p, encoding ) + || *p == '_' + || *p == '-' + || *p == '.' + || *p == ':' ) ) + { + //(*name) += *p; // expensive + ++p; + } + if ( p-start > 0 ) { + name->assign( start, p-start ); + } + return p; + } + return 0; +} + +const char* TiXmlBase::GetEntity( const char* p, char* value, int* length, TiXmlEncoding encoding ) +{ + // Presume an entity, and pull it out. + TIXML_STRING ent; + int i; + *length = 0; + + if ( *(p+1) && *(p+1) == '#' && *(p+2) ) + { + unsigned long ucs = 0; + ptrdiff_t delta = 0; + unsigned mult = 1; + + if ( *(p+2) == 'x' ) + { + // Hexadecimal. + if ( !*(p+3) ) return 0; + + const char* q = p+3; + q = strchr( q, ';' ); + + if ( !q || !*q ) return 0; + + delta = q-p; + --q; + + while ( *q != 'x' ) + { + if ( *q >= '0' && *q <= '9' ) + ucs += mult * (*q - '0'); + else if ( *q >= 'a' && *q <= 'f' ) + ucs += mult * (*q - 'a' + 10); + else if ( *q >= 'A' && *q <= 'F' ) + ucs += mult * (*q - 'A' + 10 ); + else + return 0; + mult *= 16; + --q; + } + } + else + { + // Decimal. + if ( !*(p+2) ) return 0; + + const char* q = p+2; + q = strchr( q, ';' ); + + if ( !q || !*q ) return 0; + + delta = q-p; + --q; + + while ( *q != '#' ) + { + if ( *q >= '0' && *q <= '9' ) + ucs += mult * (*q - '0'); + else + return 0; + mult *= 10; + --q; + } + } + if ( encoding == TIXML_ENCODING_UTF8 ) + { + // convert the UCS to UTF-8 + ConvertUTF32ToUTF8( ucs, value, length ); + } + else + { + *value = (char)ucs; + *length = 1; + } + return p + delta + 1; + } + + // Now try to match it. + for( i=0; iappend( cArr, len ); + } + } + else + { + bool whitespace = false; + + // Remove leading white space: + p = SkipWhiteSpace( p, encoding ); + while ( p && *p + && !StringEqual( p, endTag, caseInsensitive, encoding ) ) + { + if ( *p == '\r' || *p == '\n' ) + { + whitespace = true; + ++p; + } + else if ( IsWhiteSpace( *p ) ) + { + whitespace = true; + ++p; + } + else + { + // If we've found whitespace, add it before the + // new character. Any whitespace just becomes a space. + if ( whitespace ) + { + (*text) += ' '; + whitespace = false; + } + int len; + char cArr[4] = { 0, 0, 0, 0 }; + p = GetChar( p, cArr, &len, encoding ); + if ( len == 1 ) + (*text) += cArr[0]; // more efficient + else + text->append( cArr, len ); + } + } + } + if ( p && *p ) + p += strlen( endTag ); + return ( p && *p ) ? p : 0; +} + +#ifdef TIXML_USE_STL + +void TiXmlDocument::StreamIn( std::istream * in, TIXML_STRING * tag ) +{ + // The basic issue with a document is that we don't know what we're + // streaming. Read something presumed to be a tag (and hope), then + // identify it, and call the appropriate stream method on the tag. + // + // This "pre-streaming" will never read the closing ">" so the + // sub-tag can orient itself. + + if ( !StreamTo( in, '<', tag ) ) + { + SetError( TIXML_ERROR_PARSING_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return; + } + + while ( in->good() ) + { + int tagIndex = (int) tag->length(); + while ( in->good() && in->peek() != '>' ) + { + int c = in->get(); + if ( c <= 0 ) + { + SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); + break; + } + (*tag) += (char) c; + } + + if ( in->good() ) + { + // We now have something we presume to be a node of + // some sort. Identify it, and call the node to + // continue streaming. + TiXmlNode* node = Identify( tag->c_str() + tagIndex, TIXML_DEFAULT_ENCODING ); + + if ( node ) + { + node->StreamIn( in, tag ); + bool isElement = node->ToElement() != 0; + delete node; + node = 0; + + // If this is the root element, we're done. Parsing will be + // done by the >> operator. + if ( isElement ) + { + return; + } + } + else + { + SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); + return; + } + } + } + // We should have returned sooner. + SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); +} + +#endif + +const char* TiXmlDocument::Parse( const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding ) +{ + ClearError(); + + // Parse away, at the document level. Since a document + // contains nothing but other tags, most of what happens + // here is skipping white space. + if ( !p || !*p ) + { + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + // Note that, for a document, this needs to come + // before the while space skip, so that parsing + // starts from the pointer we are given. + location.Clear(); + if ( prevData ) + { + location.row = prevData->cursor.row; + location.col = prevData->cursor.col; + } + else + { + location.row = 0; + location.col = 0; + } + TiXmlParsingData data( p, TabSize(), location.row, location.col ); + location = data.Cursor(); + + if ( encoding == TIXML_ENCODING_UNKNOWN ) + { + // Check for the Microsoft UTF-8 lead bytes. + const unsigned char* pU = (const unsigned char*)p; + if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0 + && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1 + && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 ) + { + encoding = TIXML_ENCODING_UTF8; + useMicrosoftBOM = true; + } + } + + p = SkipWhiteSpace( p, encoding ); + if ( !p ) + { + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + while ( p && *p ) + { + TiXmlNode* node = Identify( p, encoding ); + if ( node ) + { + p = node->Parse( p, &data, encoding ); + LinkEndChild( node ); + } + else + { + break; + } + + // Did we get encoding info? + if ( encoding == TIXML_ENCODING_UNKNOWN + && node->ToDeclaration() ) + { + TiXmlDeclaration* dec = node->ToDeclaration(); + const char* enc = dec->Encoding(); + assert( enc ); + + if ( *enc == 0 ) + encoding = TIXML_ENCODING_UTF8; + else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) ) + encoding = TIXML_ENCODING_UTF8; + else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) ) + encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice + else + encoding = TIXML_ENCODING_LEGACY; + } + + p = SkipWhiteSpace( p, encoding ); + } + + // Was this empty? + if ( !firstChild ) { + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding ); + return 0; + } + + // All is well. + return p; +} + +void TiXmlDocument::SetError( int err, const char* pError, TiXmlParsingData* data, TiXmlEncoding encoding ) +{ + // The first error in a chain is more accurate - don't set again! + if ( error ) + return; + + assert( err > 0 && err < TIXML_ERROR_STRING_COUNT ); + error = true; + errorId = err; + errorDesc = errorString[ errorId ]; + + errorLocation.Clear(); + if ( pError && data ) + { + data->Stamp( pError, encoding ); + errorLocation = data->Cursor(); + } +} + + +TiXmlNode* TiXmlNode::Identify( const char* p, TiXmlEncoding encoding ) +{ + TiXmlNode* returnNode = 0; + + p = SkipWhiteSpace( p, encoding ); + if( !p || !*p || *p != '<' ) + { + return 0; + } + + p = SkipWhiteSpace( p, encoding ); + + if ( !p || !*p ) + { + return 0; + } + + // What is this thing? + // - Elements start with a letter or underscore, but xml is reserved. + // - Comments: "; + + if ( !StringEqual( p, startTag, false, encoding ) ) + { + if ( document ) + document->SetError( TIXML_ERROR_PARSING_COMMENT, p, data, encoding ); + return 0; + } + p += strlen( startTag ); + + // [ 1475201 ] TinyXML parses entities in comments + // Oops - ReadText doesn't work, because we don't want to parse the entities. + // p = ReadText( p, &value, false, endTag, false, encoding ); + // + // from the XML spec: + /* + [Definition: Comments may appear anywhere in a document outside other markup; in addition, + they may appear within the document type declaration at places allowed by the grammar. + They are not part of the document's character data; an XML processor MAY, but need not, + make it possible for an application to retrieve the text of comments. For compatibility, + the string "--" (double-hyphen) MUST NOT occur within comments.] Parameter entity + references MUST NOT be recognized within comments. + + An example of a comment: + + + */ + + value = ""; + // Keep all the white space. + while ( p && *p && !StringEqual( p, endTag, false, encoding ) ) + { + value.append( p, 1 ); + ++p; + } + if ( p && *p ) + p += strlen( endTag ); + + return p; +} + + +const char* TiXmlAttribute::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) +{ + p = SkipWhiteSpace( p, encoding ); + if ( !p || !*p ) return 0; + + if ( data ) + { + data->Stamp( p, encoding ); + location = data->Cursor(); + } + // Read the name, the '=' and the value. + const char* pErr = p; + p = ReadName( p, &name, encoding ); + if ( !p || !*p ) + { + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding ); + return 0; + } + p = SkipWhiteSpace( p, encoding ); + if ( !p || !*p || *p != '=' ) + { + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); + return 0; + } + + ++p; // skip '=' + p = SkipWhiteSpace( p, encoding ); + if ( !p || !*p ) + { + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); + return 0; + } + + const char* end; + const char SINGLE_QUOTE = '\''; + const char DOUBLE_QUOTE = '\"'; + + if ( *p == SINGLE_QUOTE ) + { + ++p; + end = "\'"; // single quote in string + p = ReadText( p, &value, false, end, false, encoding ); + } + else if ( *p == DOUBLE_QUOTE ) + { + ++p; + end = "\""; // double quote in string + p = ReadText( p, &value, false, end, false, encoding ); + } + else + { + // All attribute values should be in single or double quotes. + // But this is such a common error that the parser will try + // its best, even without them. + value = ""; + while ( p && *p // existence + && !IsWhiteSpace( *p ) // whitespace + && *p != '/' && *p != '>' ) // tag end + { + if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) { + // [ 1451649 ] Attribute values with trailing quotes not handled correctly + // We did not have an opening quote but seem to have a + // closing one. Give up and throw an error. + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); + return 0; + } + value += *p; + ++p; + } + } + return p; +} + +#ifdef TIXML_USE_STL +void TiXmlText::StreamIn( std::istream * in, TIXML_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->peek(); + if ( !cdata && (c == '<' ) ) + { + return; + } + if ( c <= 0 ) + { + TiXmlDocument* document = GetDocument(); + if ( document ) + document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); + return; + } + + (*tag) += (char) c; + in->get(); // "commits" the peek made above + + if ( cdata && c == '>' && tag->size() >= 3 ) { + size_t len = tag->size(); + if ( (*tag)[len-2] == ']' && (*tag)[len-3] == ']' ) { + // terminator of cdata. + return; + } + } + } +} +#endif + +const char* TiXmlText::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) +{ + value = ""; + TiXmlDocument* document = GetDocument(); + + if ( data ) + { + data->Stamp( p, encoding ); + location = data->Cursor(); + } + + const char* const startTag = ""; + + if ( cdata || StringEqual( p, startTag, false, encoding ) ) + { + cdata = true; + + if ( !StringEqual( p, startTag, false, encoding ) ) + { + if ( document ) + document->SetError( TIXML_ERROR_PARSING_CDATA, p, data, encoding ); + return 0; + } + p += strlen( startTag ); + + // Keep all the white space, ignore the encoding, etc. + while ( p && *p + && !StringEqual( p, endTag, false, encoding ) + ) + { + value += *p; + ++p; + } + + TIXML_STRING dummy; + p = ReadText( p, &dummy, false, endTag, false, encoding ); + return p; + } + else + { + bool ignoreWhite = true; + + const char* end = "<"; + p = ReadText( p, &value, ignoreWhite, end, false, encoding ); + if ( p && *p ) + return p-1; // don't truncate the '<' + return 0; + } +} + +#ifdef TIXML_USE_STL +void TiXmlDeclaration::StreamIn( std::istream * in, TIXML_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->get(); + if ( c <= 0 ) + { + TiXmlDocument* document = GetDocument(); + if ( document ) + document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); + return; + } + (*tag) += (char) c; + + if ( c == '>' ) + { + // All is well. + return; + } + } +} +#endif + +const char* TiXmlDeclaration::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding _encoding ) +{ + p = SkipWhiteSpace( p, _encoding ); + // Find the beginning, find the end, and look for + // the stuff in-between. + TiXmlDocument* document = GetDocument(); + if ( !p || !*p || !StringEqual( p, "SetError( TIXML_ERROR_PARSING_DECLARATION, 0, 0, _encoding ); + return 0; + } + if ( data ) + { + data->Stamp( p, _encoding ); + location = data->Cursor(); + } + p += 5; + + version = ""; + encoding = ""; + standalone = ""; + + while ( p && *p ) + { + if ( *p == '>' ) + { + ++p; + return p; + } + + p = SkipWhiteSpace( p, _encoding ); + if ( StringEqual( p, "version", true, _encoding ) ) + { + TiXmlAttribute attrib; + p = attrib.Parse( p, data, _encoding ); + version = attrib.Value(); + } + else if ( StringEqual( p, "encoding", true, _encoding ) ) + { + TiXmlAttribute attrib; + p = attrib.Parse( p, data, _encoding ); + encoding = attrib.Value(); + } + else if ( StringEqual( p, "standalone", true, _encoding ) ) + { + TiXmlAttribute attrib; + p = attrib.Parse( p, data, _encoding ); + standalone = attrib.Value(); + } + else + { + // Read over whatever it is. + while( p && *p && *p != '>' && !IsWhiteSpace( *p ) ) + ++p; + } + } + return 0; +} + +bool TiXmlText::Blank() const +{ + for ( unsigned i=0; i +#ifdef TF_A3DLIBS +# define A3DAPI_INTERNAL +#else +#include +#endif + +class A3DConnector +{ +protected: + + const A3DEntity* m_pEntity; + + A3DConnector(const A3DEntity* pEntity) : m_pEntity(pEntity) {} + A3DConnector() : m_pEntity(NULL) {}; +public: + + const A3DEntity* GetA3DEntity() const { return m_pEntity; } + virtual A3DEEntityType GetType() const { return kA3DTypeUnknown; } + +}; + +#endif \ No newline at end of file diff --git a/exchange/exchangesource/DumpFeatureTree/Visitor/TreeTraverse.cpp b/exchange/exchangesource/DumpFeatureTree/Visitor/TreeTraverse.cpp new file mode 100644 index 0000000..95bd455 --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/Visitor/TreeTraverse.cpp @@ -0,0 +1,576 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file TreeConnector.cpp + +This file contains fuctionalities to traverse a Prc Model Tree + +***********************************************************************************************************************/ + +#include "TreeTraverse.h" +#include "VisitorContainer.h" + +/************************************************************************************ + +Traverse Model File + +*************************************************************************************/ + +// Traverse all the model tree +A3DStatus A3DModelFileConnector::Traverse(A3DVisitorContainer* psVisitor, bool bVisitPrototype) +{ + unsigned int uI; + psVisitor->visitEnter(*this); + + for (uI = 0; uI < m_sModelFileData.m_uiPOccurrencesSize; uI++) + { + psVisitor->SetCurrentPoFather(NULL); + A3DProductOccurrenceConnector sTreeConnector(m_sModelFileData.m_ppPOccurrences[uI]); + if (sTreeConnector.TraversePO(m_sModelFileData.m_ppPOccurrences[uI], psVisitor, bVisitPrototype) != A3D_SUCCESS) + return A3D_ERROR; + } + psVisitor->visitLeave(*this); + return A3D_SUCCESS; +} + +// Traversing the assembly Structure +A3DStatus A3DProductOccurrenceConnector::TraversePO(const A3DAsmProductOccurrence* pOccurrence, + A3DVisitorContainer* psVisitor, + bool bVisitPrototype) +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + //Traverse AnnotationEntity + A3DUns32 uI; +#ifdef CONNECT_PMI + A3DUns32 uNbAnnotationEntity = m_sProductOccurrenceData.m_uiAnnotationsSize; + for (uI = 0; uI < uNbAnnotationEntity; uI++) + { + A3DMkpAnnotationEntityConnector sAnnotationEntityConnector(m_sProductOccurrenceData.m_ppAnnotations[uI]); + sAnnotationEntityConnector.TraverseAnnotationEntity(psVisitor); + } + if (!uNbAnnotationEntity && m_sProductOccurrenceData.m_pPrototype != NULL) + { + A3DAsmProductOccurrence* pProductPrototype = m_sProductOccurrenceData.m_pPrototype; + while (pProductPrototype) + { + A3DAsmProductOccurrenceData sProductPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductPrototypeData); + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(pProductPrototype, &sProductPrototypeData)); + uNbAnnotationEntity = sProductPrototypeData.m_uiAnnotationsSize; + for (uI = 0; uI < uNbAnnotationEntity; uI++) + { + A3DMkpAnnotationEntityConnector sAnnotationEntityConnector(sProductPrototypeData.m_ppAnnotations[uI]); + sAnnotationEntityConnector.TraverseAnnotationEntity(psVisitor); + } + + pProductPrototype = sProductPrototypeData.m_pPrototype; + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(NULL, &sProductPrototypeData)); + } + } +#endif + +#ifdef CONNECT_VIEWS + A3DUns32 uNbView = m_sProductOccurrenceData.m_uiViewsSize; + if (!uNbView && m_sProductOccurrenceData.m_pPrototype != NULL) + { + A3DAsmProductOccurrence* pProductPrototype = m_sProductOccurrenceData.m_pPrototype; + while (pProductPrototype) + { + A3DAsmProductOccurrenceData sProductPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductPrototypeData); + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(pProductPrototype, &sProductPrototypeData)); + uNbView = sProductPrototypeData.m_uiViewsSize; + for (uI = 0; uI < uNbView; uI++) + { + A3DMkpViewConnector sMkpViewConnector(sProductPrototypeData.m_ppViews[uI]); + sMkpViewConnector.TraverseView(psVisitor); + } + pProductPrototype = sProductPrototypeData.m_pPrototype; + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(NULL, &sProductPrototypeData)); + } + } + else if (uNbView) + { + for (uI = 0; uI < uNbView; uI++) + { + A3DMkpViewConnector sMkpViewConnector(m_sProductOccurrenceData.m_ppViews[uI]); + sMkpViewConnector.TraverseView(psVisitor); + } + } + +#endif + +#ifdef CONNECT_FEATURE + + A3DUns32 uNbFeatureBasedEntity = m_sProductOccurrenceData.m_uiFeatureBasedEntitiesSize; + if (!uNbFeatureBasedEntity && m_sProductOccurrenceData.m_pPrototype != NULL) + { + A3DAsmProductOccurrence* pProductPrototype = m_sProductOccurrenceData.m_pPrototype; + while (pProductPrototype) + { + A3DAsmProductOccurrenceData sProductPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductPrototypeData); + CHECK_RET(A3DAsmProductOccurrenceGet(pProductPrototype, &sProductPrototypeData)); + uNbFeatureBasedEntity = sProductPrototypeData.m_uiFeatureBasedEntitiesSize; + for (uI = 0; uI < uNbFeatureBasedEntity; uI++) + { + A3DFRMTreeConnector sConnector(sProductPrototypeData.m_ppFeatureBasedEntities[uI]); + sConnector.TraverseFeatureTree(psVisitor); + } + pProductPrototype = sProductPrototypeData.m_pPrototype; + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sProductPrototypeData)); + } + } + else if (uNbFeatureBasedEntity) + { + for (uI = 0; uI < uNbFeatureBasedEntity; uI++) + { + A3DFRMTreeConnector sConnector(m_sProductOccurrenceData.m_ppFeatureBasedEntities[uI]); + sConnector.TraverseFeatureTree(psVisitor); + } + } +#endif + A3DAsmPartDefinition* pPart = NULL; + if (!bVisitPrototype) + { + CHECK_RET(GetPart(pPart)); + } + else + { + pPart = m_sProductOccurrenceData.m_pPart; + } + if (pPart) + { + void * pEntityInMap = psVisitor->FindInMap(pPart); + psVisitor->SetInMap(pPart, pPart); + A3DPartConnector sPartConnector(pPart); + psVisitor->SetCurrentPoFather(pOccurrence); + sPartConnector.SetProductOccurenceFather(pOccurrence); + + // if we haven't found the part in the map or if we traverse the instance + if (pEntityInMap == NULL || psVisitor->TraverseInstances()) + { + CHECK_RET(sPartConnector.TraversePart(psVisitor)); + } + psVisitor->SetCurrentPoFather(NULL); + } + std::vector apSons; + if (!bVisitPrototype) + { + CollectSons(apSons); + } + else + { + if (m_sProductOccurrenceData.m_pPrototype) + { + if (psVisitor->FindInMap(m_sProductOccurrenceData.m_pPrototype) == NULL) + { + psVisitor->SetInMap(m_sProductOccurrenceData.m_pPrototype, m_sProductOccurrenceData.m_pPrototype); + A3DProductOccurrenceConnector sPrototypeConnector(m_sProductOccurrenceData.m_pPrototype); + sPrototypeConnector.SetPrototypeType(true); + sPrototypeConnector.TraversePO(m_sProductOccurrenceData.m_pPrototype, psVisitor, bVisitPrototype); + } + } + if (m_sProductOccurrenceData.m_pExternalData) + { + if (psVisitor->FindInMap(m_sProductOccurrenceData.m_pExternalData) == NULL) + { + psVisitor->SetInMap(m_sProductOccurrenceData.m_pExternalData, m_sProductOccurrenceData.m_pExternalData); + A3DProductOccurrenceConnector sExternalConnector(m_sProductOccurrenceData.m_pExternalData); + sExternalConnector.SetExternalType(true); + sExternalConnector.TraversePO(m_sProductOccurrenceData.m_pExternalData, psVisitor, bVisitPrototype); + } + } + + + unsigned int uSize = m_sProductOccurrenceData.m_uiPOccurrencesSize; + for (uI = 0; uI < uSize; uI++) + { + apSons.push_back(m_sProductOccurrenceData.m_ppPOccurrences[uI]); + } + } + + for (uI = 0; uI < apSons.size(); uI++) + { + A3DProductOccurrenceConnector sPoConnector(apSons[uI]); + sPoConnector.SetProductOccurrenceFather(this->GetA3DEntity()); + psVisitor->SetCurrentPoFather(pOccurrence); + CHECK_RET(sPoConnector.TraversePO(apSons[uI], psVisitor, bVisitPrototype)); + psVisitor->SetCurrentPoFather(NULL); + } + CHECK_RET(psVisitor->visitLeave(*this)); + + return A3D_SUCCESS; +} + +A3DStatus A3DProductOccurrenceConnector::CollectSons( + std::vector& apSons) const +{ + //Get Children or children on Prototype's ....Prototype's + A3DAsmProductOccurrence* pPrototype = m_sProductOccurrenceData.m_pPrototype; + A3DAsmProductOccurrence** ppPo = m_sProductOccurrenceData.m_ppPOccurrences; + unsigned int uSize = m_sProductOccurrenceData.m_uiPOccurrencesSize; + A3DStatus iRet = A3D_SUCCESS; + + while (uSize == 0 && pPrototype) + { + A3DAsmProductOccurrenceData sPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sPrototypeData); + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(pPrototype, &sPrototypeData)); + pPrototype = sPrototypeData.m_pPrototype; + + uSize = sPrototypeData.m_uiPOccurrencesSize; + ppPo = sPrototypeData.m_ppPOccurrences; + + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(NULL, &sPrototypeData)); + } + + unsigned uI; + for (uI = 0; uI < uSize; uI++) + apSons.push_back(ppPo[uI]); + + //Get Children on Externals + if (m_sProductOccurrenceData.m_pExternalData) + { + if (apSons.size() == 0) + { + A3DProductOccurrenceConnector sExternalConnector(m_sProductOccurrenceData.m_pExternalData); + CHECK_RET(sExternalConnector.CollectSons(apSons)); + } + else + apSons.push_back(m_sProductOccurrenceData.m_pExternalData); + } + + return A3D_SUCCESS; +} + +A3DStatus A3DProductOccurrenceConnector::GetPart( + A3DAsmPartDefinition*& pPart) const +{ + pPart = NULL; + A3DStatus iRet = A3D_SUCCESS;; + if (m_sProductOccurrenceData.m_pPart) + { + pPart = m_sProductOccurrenceData.m_pPart; + return A3D_SUCCESS; + } + + A3DAsmProductOccurrence* pProductPrototype = m_sProductOccurrenceData.m_pPrototype; + while (pProductPrototype) + { + A3DAsmProductOccurrenceData sProductPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductPrototypeData); + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(pProductPrototype, &sProductPrototypeData)); + if (sProductPrototypeData.m_pPart) + { + pPart = sProductPrototypeData.m_pPart; + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(NULL, &sProductPrototypeData)); + return A3D_SUCCESS; + } + else + pProductPrototype = sProductPrototypeData.m_pPrototype; + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(NULL, &sProductPrototypeData)); + } + + if (m_sProductOccurrenceData.m_uiPOccurrencesSize == 0) + { + if (m_sProductOccurrenceData.m_pExternalData) + { + A3DProductOccurrenceConnector sExternalconnector(m_sProductOccurrenceData.m_pExternalData); + CHECK_RET(sExternalconnector.GetPart(pPart)); + } + } + return A3D_SUCCESS; +} + +A3DStatus A3DPartConnector::TraversePart(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + + CHECK_RET(psVisitor->visitEnter(*this)); + + //Traverse AnnotationEntity + A3DUns32 uI; +#ifdef CONNECT_PMI + A3DUns32 uNbAnnotationEntity = m_sPartData.m_uiAnnotationsSize; + for (uI = 0; uI < uNbAnnotationEntity; uI++) + { + A3DMkpAnnotationEntityConnector sAnnotationEntityConnector(m_sPartData.m_ppAnnotations[uI]); + sAnnotationEntityConnector.TraverseAnnotationEntity(psVisitor); + } +#endif + +#ifdef CONNECT_VIEWS + A3DUns32 uNbView = m_sPartData.m_uiViewsSize; + for (uI = 0; uI < uNbView; uI++) + { + A3DMkpViewConnector sMkpViewConnector(m_sPartData.m_ppViews[uI]); + sMkpViewConnector.TraverseView(psVisitor); + } +#endif + + //Traverse RI + for (uI = 0; uI < m_sPartData.m_uiRepItemsSize; uI++) + { + A3DRiConnector sRiConnector(m_sPartData.m_ppRepItems[uI]); + sRiConnector.TraverseRi(psVisitor); + } + + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +A3DStatus A3DRiConnector::TraverseRi(A3DVisitorContainer* psVisitor) +{ + A3DStatus iRet = A3D_SUCCESS; + psVisitor->visitEnter(*this); + + const A3DEntity* pRi = GetA3DEntity(); + A3DEEntityType eType = kA3DTypeUnknown; + CALL_A3D_FCTION(A3DEntityGetType,(pRi,&eType)); + + if (iRet == A3D_SUCCESS) + { + switch (eType) + { + case kA3DTypeRiBrepModel: + { + A3DRiBrepModelConnector sConnector((A3DRiBrepModel*)pRi); + CHECK_RET(sConnector.TraverseRiBrepModel(psVisitor)); + break; + } + case kA3DTypeRiSet: + { + A3DRiSetConnector sConnector(static_cast(pRi)); + CHECK_RET(sConnector.TraverseRiSet(psVisitor)); + break; + } + + case kA3DTypeRiCurve: + { + A3DRiCurveConnector sConnector((A3DRiCurve*)pRi); + CHECK_RET(sConnector.TraverseRiCurve(psVisitor)); + break; + } + case kA3DTypeRiPointSet: + case kA3DTypeRiDirection: + case kA3DTypeRiCoordinateSystem: + case kA3DTypeRiPlane: + break; + case kA3DTypeRiPolyBrepModel: + { + A3DPolyRiBrepModelConnector sConnector((A3DRiPolyBrepModel*)pRi); + CHECK_RET(sConnector.TraverseRiPolyBrepModel(psVisitor)); + break; + } + case kA3DTypeRiPolyWire: + { + A3DRiPolyWireConnector sConnector((A3DRiPolyWire*)pRi); + CHECK_RET(sConnector.TraverseRiPolyWire(psVisitor)); + break; + } + default: + iRet = A3D_NOT_IMPLEMENTED; + break; + } + } + psVisitor->visitLeave(*this); + + return A3D_SUCCESS; +} + +// RiBrepModel +A3DStatus A3DRiBrepModelConnector::TraverseRiBrepModel(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + //Traverse Mesh +#ifdef CONNECT_MESH + A3DRiRepresentationItemData sRidata; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, sRidata); + CHECK_RET_CALL_A3D_FCTION(A3DRiRepresentationItemGet,(this->GetA3DEntity(), &sRidata)); + A3DTessDataConnector sTessConnector((A3DTess3D*)sRidata.m_pTessBase); + CHECK_RET(sTessConnector.Traverse(psVisitor)); + CHECK_RET_CALL_A3D_FCTION(A3DRiRepresentationItemGet,(NULL, &sRidata)); +#endif + + //Traverse Brep Data +#ifdef CONNECT_BREP + A3DBrepDataConnector sTopoConnector(m_sRiBrepModelData.m_pBrepData); + CHECK_RET(sTopoConnector.Traverse(psVisitor)); + +#endif + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} + +// RiSet +A3DStatus A3DRiSetConnector::TraverseRiSet(A3DVisitorContainer* psVisitor) +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned uI; + for (uI = 0; uI < m_sRiSetData.m_uiRepItemsSize; uI++) + { + A3DRiConnector sRiConnector(m_sRiSetData.m_ppRepItems[uI]); + sRiConnector.TraverseRi(psVisitor); + } + + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} + +// RiPolyBrepModel +A3DStatus A3DPolyRiBrepModelConnector::TraverseRiPolyBrepModel(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); +/* + A3DRiRepresentationItemData sRiData; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, sRiData); + CHECK_RET_CALL_A3D_FCTION(A3DRiRepresentationItemGet,(this->GetA3DEntity(), &sRiData)); + A3DTessDataConnector sTessConnector((A3DTess3D*)sRiData.m_pTessBase); + CHECK_RET(sTessConnector.Traverse(psVisitor)); + CHECK_RET_CALL_A3D_FCTION(A3DRiRepresentationItemGet,(NULL, &sRiData)); +*/ + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} + +/////////////////////////////////////////////////////////////////////////////////////// +// RiCurve +/////////////////////////////////////////////////////////////////////////////////////// +A3DStatus A3DRiCurveConnector::TraverseRiCurve(A3DVisitorContainer* psVisitor) +{ + + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + +#ifdef CONNECT_MESH + A3DRiRepresentationItemData sRidata; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, sRidata); + CHECK_RET(A3DRiRepresentationItemGet(this->GetA3DEntity(), &sRidata)); + A3DWireTessDataConnector sWireTessConnector((A3DTess3DWire*)sRidata.m_pTessBase); + CHECK_RET(sWireTessConnector.Traverse(psVisitor)); + CHECK_RET(A3DRiRepresentationItemGet(NULL, &sRidata)); +#endif + + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} + +/////////////////////////////////////////////////////////////////////////////////////// +// RiPolyWire +/////////////////////////////////////////////////////////////////////////////////////// +A3DStatus A3DRiPolyWireConnector::TraverseRiPolyWire(A3DVisitorContainer* psVisitor) +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + +#ifdef CONNECT_MESH + A3DRiRepresentationItemData sRidata; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, sRidata); + CHECK_RET(A3DRiRepresentationItemGet(this->GetA3DEntity(), &sRidata)); + A3DWireTessDataConnector sWireTessConnector((A3DTess3DWire*)sRidata.m_pTessBase); + CHECK_RET(sWireTessConnector.Traverse(psVisitor)); + CHECK_RET(A3DRiRepresentationItemGet(NULL, &sRidata)); +#endif + + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} + + +// A3DFRMParameter +A3DStatus A3DFRMFeatureConnector::TraverseFeature(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned uI; + + for (uI = 0; uI < m_sData.m_uiConnectionSize; uI++) + { + A3DFRMLinkedItemConnector sFeatureLinkedItemConnector(m_sData.m_ppConnections[uI]); + sFeatureLinkedItemConnector.TraverseConnection(psVisitor); + } + + + for (uI = 0; uI < m_sData.m_uiParametersSize; uI++) + { + A3DFRMParameterConnector sParameterConnector(m_sData.m_ppParameters[uI]); + sParameterConnector.TraverseParameter(psVisitor); + } + + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} + +// A3DFRMParameter +A3DStatus A3DFRMLinkedItemConnector::TraverseConnection(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + CHECK_RET(psVisitor->visitLeave(*this)); + return iRet; +} + +// A3DFRMParameter +A3DStatus A3DFRMParameterConnector::TraverseParameter(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned uI; + + for (uI = 0; uI < m_sData.m_uiFeatureSize; uI++) + { + A3DFRMFeatureConnector sFeatureConnector(m_sData.m_ppFeatures[uI]); + sFeatureConnector.TraverseFeature(psVisitor); + } + + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} + + +// FeatureTree +A3DStatus A3DFRMTreeConnector::TraverseFeatureTree(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned uI; + + for (uI = 0; uI < m_sTreeData.m_uiIntermediateGeometriesSize; uI++) + { + A3DRiConnector sRiConnector(m_sTreeData.m_ppIntermediateGeometries[uI]); + sRiConnector.TraverseRi(psVisitor); + } + + for (uI = 0; uI < m_sTreeData.m_uiParametersSize; uI++) + { + A3DFRMParameterConnector sParameterConnector(m_sTreeData.m_ppsParameters[uI]); + sParameterConnector.TraverseParameter(psVisitor); + } + + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} diff --git a/exchange/exchangesource/DumpFeatureTree/Visitor/TreeTraverse.h b/exchange/exchangesource/DumpFeatureTree/Visitor/TreeTraverse.h new file mode 100644 index 0000000..9d7a81d --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/Visitor/TreeTraverse.h @@ -0,0 +1,364 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_TREE_CONNECTOR +#define A3D_TREE_CONNECTOR + +#include +#include "Connector.h" + +//###################################################################################################################### + +class A3DVisitorContainer; +class A3DModelFileConnector : public A3DConnector +{ +public: + + A3DModelFileConnector(const A3DAsmModelFile* pModelFile) : A3DConnector(pModelFile) + { + A3D_INITIALIZE_DATA(A3DAsmModelFileData, m_sModelFileData); + A3DAsmModelFileGet(pModelFile, &m_sModelFileData); + } + + ~A3DModelFileConnector() { A3DAsmModelFileGet(NULL, &m_sModelFileData); } + + A3DStatus Traverse(A3DVisitorContainer* psVisitor, bool bVisitPrototype = false); + +public: + + A3DAsmModelFileData m_sModelFileData; +}; + +//###################################################################################################################### +class A3DProductOccurrenceConnector : public A3DConnector +{ + friend class A3DModelFileConnector; + const A3DAsmProductOccurrence* m_pFather; + bool m_bIsInstanciated; + bool m_bIsPrototype; + bool m_bIsExternal; + +private: + + A3DProductOccurrenceConnector(const A3DAsmProductOccurrence* pProductOccurrence) + : A3DConnector(pProductOccurrence) + { + m_pFather = NULL; + m_bIsInstanciated = false; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, m_sProductOccurrenceData); + A3DAsmProductOccurrenceGet(pProductOccurrence, &m_sProductOccurrenceData); + m_bIsPrototype = false; + m_bIsExternal = false; + } + + ~A3DProductOccurrenceConnector() { A3DAsmProductOccurrenceGet(NULL, &m_sProductOccurrenceData); } + + A3DStatus TraversePO(const A3DAsmProductOccurrence* pOccurrence, A3DVisitorContainer* psVisitor, bool bVisitPrototype = false); + + void SetProductOccurrenceFather(const A3DAsmProductOccurrence* pFather) { m_pFather = pFather; } + +public: + A3DStatus GetPart(A3DAsmPartDefinition*& pPart) const; + A3DStatus CollectSons(std::vector& apSons) const; + + A3DAsmProductOccurrenceData m_sProductOccurrenceData; + const A3DAsmProductOccurrence* GetProductOccurrenceFather() { return m_pFather; } + void SetIsInstanciated(bool bIsInstanciated) { m_bIsInstanciated = bIsInstanciated; } + bool IsInstanciated() { return m_bIsInstanciated; } + void SetPrototypeType(bool bIsPrototype) { m_bIsPrototype = bIsPrototype; } + bool IsProtoType() const { return m_bIsPrototype; } + void SetExternalType(bool bIsExternal) { m_bIsExternal = bIsExternal; } + bool IsExternal() const { return m_bIsExternal; } +}; + +//###################################################################################################################### +class A3DPartConnector : public A3DConnector +{ + friend class A3DProductOccurrenceConnector; + const A3DAsmProductOccurrence* m_pFather; + bool m_bIsInstanciated; + +private: + + A3DPartConnector(const A3DAsmPartDefinition *pPart) : A3DConnector(pPart) + { + m_pFather = NULL; + m_bIsInstanciated = false; + A3D_INITIALIZE_DATA(A3DAsmPartDefinitionData, m_sPartData); + A3DAsmPartDefinitionGet(pPart, &m_sPartData); + } + + ~A3DPartConnector() + { + A3DAsmPartDefinitionGet(NULL, &m_sPartData); + } + + void SetProductOccurenceFather(const A3DAsmProductOccurrence* pFather) { m_pFather = pFather; } + +public: + A3DStatus TraversePart(A3DVisitorContainer* psVisitor) const; + A3DAsmPartDefinitionData m_sPartData; + const A3DAsmProductOccurrence* GetProductOccurenceFather() { return m_pFather; } + void SetIsInstanciated(bool bIsInstanciated) { m_bIsInstanciated = bIsInstanciated; } + bool IsInstanciated() { return m_bIsInstanciated; } +}; + +//###################################################################################################################### +class A3DRiConnector : public A3DConnector +{ + friend class A3DPartConnector; + friend class A3DRiSetConnector; + bool m_bIsInstanciated; + +public: + + A3DRiConnector(const A3DRiRepresentationItem *pRi) : A3DConnector(pRi) + { + m_bIsInstanciated = false; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, m_sRiData); + A3DRiRepresentationItemGet(pRi, &m_sRiData); + } + + ~A3DRiConnector() + { + A3DRiRepresentationItemGet(NULL, &m_sRiData); + } + + A3DStatus TraverseRi(A3DVisitorContainer* psVisitor); + +public: + + A3DRiRepresentationItemData m_sRiData; + void SetIsInstanciated(bool bIsInstanciated) { m_bIsInstanciated = bIsInstanciated; } + bool IsInstanciated() { return m_bIsInstanciated; } +}; + +//###################################################################################################################### +class A3DRiBrepModelConnector : public A3DConnector +{ + friend class A3DRiConnector; +public: + + A3DRiBrepModelConnector(const A3DRiBrepModel *pRi) : m_pRiBrepModel(pRi), A3DConnector(pRi) + { + A3D_INITIALIZE_DATA(A3DRiBrepModelData, m_sRiBrepModelData); + A3DRiBrepModelGet(m_pRiBrepModel, &m_sRiBrepModelData); + } + + ~A3DRiBrepModelConnector() + { + A3DRiBrepModelGet(NULL, &m_sRiBrepModelData); + } + + A3DStatus TraverseRiBrepModel(A3DVisitorContainer* psVisitor) const; + +public: + A3DRiBrepModel const* m_pRiBrepModel; + A3DRiBrepModelData m_sRiBrepModelData; +}; + +//###################################################################################################################### +class A3DRiSetConnector : public A3DConnector +{ + friend class A3DRiConnector; +private: + + A3DRiSetConnector(const A3DRiSet *pRi) : A3DConnector(pRi) + { + A3D_INITIALIZE_DATA(A3DRiSetData, m_sRiSetData); + A3DRiSetGet(pRi, &m_sRiSetData); + } + + ~A3DRiSetConnector() + { + A3DRiSetGet(NULL, &m_sRiSetData); + } + + A3DStatus TraverseRiSet(A3DVisitorContainer* psVisitor); + +public: + + A3DRiSetData m_sRiSetData; +}; + +//###################################################################################################################### +class A3DPolyRiBrepModelConnector : public A3DConnector +{ + friend class A3DRiConnector; +private: + + A3DPolyRiBrepModelConnector(const A3DRiPolyBrepModel* pRi) : A3DConnector(pRi) + { + A3D_INITIALIZE_DATA(A3DRiPolyBrepModelData, m_sRiPolyBrepModelData); + A3DRiPolyBrepModelGet(pRi, &m_sRiPolyBrepModelData); + } + + ~A3DPolyRiBrepModelConnector() + { + A3DRiPolyBrepModelGet(NULL, &m_sRiPolyBrepModelData); + } + +public: + A3DStatus TraverseRiPolyBrepModel(A3DVisitorContainer* psVisitor) const; + A3DRiPolyBrepModelData m_sRiPolyBrepModelData; +}; + +//###################################################################################################################### +class A3DRiCurveConnector : public A3DConnector +{ + friend class A3DRiConnector; +private: + + A3DRiCurveConnector(const A3DRiCurve* pRi) : A3DConnector(pRi) + { + A3D_INITIALIZE_DATA(A3DRiCurveData, m_sRiCurveData); + A3DRiCurveGet(pRi, &m_sRiCurveData); + } + + ~A3DRiCurveConnector() + { + A3DRiCurveGet(NULL, &m_sRiCurveData); + } + + A3DStatus TraverseRiCurve(A3DVisitorContainer* psVisitor); + +public: + + A3DRiCurveData m_sRiCurveData; +}; + +//###################################################################################################################### +class A3DRiPolyWireConnector : public A3DConnector +{ + friend class A3DRiConnector; +private: + + A3DRiPolyWireConnector(const A3DRiPolyWire* pRi) : A3DConnector(pRi) + { + A3D_INITIALIZE_DATA(A3DRiPolyWireData, m_sRiPolyWireData); + A3DRiPolyWireGet(pRi, &m_sRiPolyWireData); + } + + ~A3DRiPolyWireConnector() + { + A3DRiPolyWireGet(NULL, &m_sRiPolyWireData); + } + + A3DStatus TraverseRiPolyWire(A3DVisitorContainer* psVisitor); + +public: + + A3DRiPolyWireData m_sRiPolyWireData; +}; + +//###################################################################################################################### +class A3DFRMParameterConnector : public A3DConnector +{ + friend class A3DFRMTreeConnector; + friend class A3DFRMFeatureConnector; +private: + + A3DFRMParameterConnector(const A3DFRMParameter *pParameter) : A3DConnector(pParameter) + { + A3D_INITIALIZE_DATA(A3DFRMParameterData, m_sData); + A3DFRMParameterGet(pParameter, &m_sData); + } + + ~A3DFRMParameterConnector() + { + A3DFRMParameterGet(NULL, &m_sData); + } + + +public: + + A3DFRMParameterData m_sData; + + A3DStatus TraverseParameter(A3DVisitorContainer* psVisitor) const; +}; + + +//###################################################################################################################### +class A3DFRMLinkedItemConnector : public A3DConnector +{ + friend class A3DFRMFeatureConnector; +private: + + A3DFRMLinkedItemConnector(const A3DFRMLinkedItem *pLinkedItem) : A3DConnector(pLinkedItem) + { + A3D_INITIALIZE_DATA(A3DFRMLinkedItemData, m_sData); + A3DFRMLinkedItemGet(pLinkedItem, &m_sData); + } + + ~A3DFRMLinkedItemConnector() + { + A3DFRMLinkedItemGet(NULL, &m_sData); + } + + +public: + + A3DFRMLinkedItemData m_sData; + + A3DStatus TraverseConnection(A3DVisitorContainer* psVisitor) const; +}; + + +//###################################################################################################################### +class A3DFRMFeatureConnector : public A3DConnector +{ + friend class A3DFRMParameterConnector; +private: + + A3DFRMFeatureConnector(const A3DFRMFeature *pFeature) : A3DConnector(pFeature) + { + A3D_INITIALIZE_DATA(A3DFRMFeatureData, m_sData); + A3DFRMFeatureGet(pFeature, &m_sData); + } + + ~A3DFRMFeatureConnector() + { + A3DFRMFeatureGet(NULL, &m_sData); + } + + +public: + + A3DFRMFeatureData m_sData; + A3DStatus TraverseFeature(A3DVisitorContainer* psVisitor) const; + + +}; + +//###################################################################################################################### +class A3DFRMTreeConnector : public A3DConnector +{ + friend class A3DProductOccurrenceConnector; +protected: + + A3DFRMTreeConnector(const A3DFRMTree *pTree) : A3DConnector(pTree) + { + A3D_INITIALIZE_DATA(A3DFRMTreeData, m_sTreeData); + A3DFRMTreeGet(pTree, &m_sTreeData); + } + + ~A3DFRMTreeConnector() + { + A3DFRMTreeGet(NULL, &m_sTreeData); + } + + A3DStatus TraverseFeatureTree(A3DVisitorContainer* psVisitor) const; + +public: + + A3DFRMTreeData m_sTreeData; +}; +#endif diff --git a/exchange/exchangesource/DumpFeatureTree/Visitor/VisitorContainer.cpp b/exchange/exchangesource/DumpFeatureTree/Visitor/VisitorContainer.cpp new file mode 100644 index 0000000..75b4efa --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/Visitor/VisitorContainer.cpp @@ -0,0 +1,586 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "VisitorContainer.h" +#include "Visitors.h" + + +#ifdef CONNECT_ASSEMBLY_TREE +#include "VisitorTree.h" +#endif + +#include +#include + +using namespace std; + +#define VISITENTER \ +{\ + ActivateEntityReference(sConnector.GetA3DEntity()); \ + for(unsigned uI = 0; uI < m_apVisitor.size(); uI++)\ + m_apVisitor[uI]->visitEnter(sConnector);\ + return A3D_SUCCESS;\ +} + +#define VISITLEAVE \ +{\ + DeactivateEntityReference(sConnector.GetA3DEntity()); \ + for(unsigned uI = 0; uI < m_apVisitor.size(); uI++)\ + m_apVisitor[uI]->visitLeave(sConnector);\ + return A3D_SUCCESS;\ +} + +//Tree +#ifdef CONNECT_ASSEMBLY_TREE +// +// static A3DStatus stCreateAndPushCascadedAttributes( const A3DRootBaseWithGraphics* pBase, +// const A3DMiscCascadedAttributes* pFatherAttr, +// A3DMiscCascadedAttributes** ppAttr, +// A3DMiscCascadedAttributesData* psAttrData) +// { +// A3DStatus iRet = A3D_SUCCESS; +// +// CHECK_RET(A3DMiscCascadedAttributesCreate(ppAttr)); +// CHECK_RET(A3DMiscCascadedAttributesPush(*ppAttr, pBase, pFatherAttr)); +// +// A3D_INITIALIZE_DATA(A3DMiscCascadedAttributesData, (*psAttrData)); +// CHECK_RET(A3DMiscCascadedAttributesGet(*ppAttr, psAttrData)); +// +// return iRet; +// } + +A3DStatus A3DVisitorContainer::visitEnter(const A3DModelFileConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitEnter(const A3DProductOccurrenceConnector& sConnector) +{ + m_uiCurrentLevel++; + + // Entity Reference + unsigned int uI, uNbRefEntity = sConnector.m_sProductOccurrenceData.m_uiEntityReferenceSize; + for(uI = 0; uI < uNbRefEntity; uI++) + { + A3DMiscEntityReferenceData sMiscRefData; + A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sMiscRefData); + A3DMiscEntityReference* pEntityRef = sConnector.m_sProductOccurrenceData.m_ppEntityReferences[uI]; + A3DMiscEntityReferenceGet(pEntityRef, &sMiscRefData); + A3DStepEntityRefManager sEntityManager; + sEntityManager.m_pStepEntityRef = pEntityRef; + sEntityManager.m_uiPOLevel = m_uiCurrentLevel; + + A3DEEntityType sType; + A3DEntityGetType(sMiscRefData.m_pEntity, &sType); + if(sType == kA3DTypeMiscReferenceOnTopology) + { + A3DMiscReferenceOnTopologyData sTopoRefData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnTopologyData,sTopoRefData); + A3DMiscReferenceOnTopologyGet(pEntityRef, &sTopoRefData); + sEntityManager.m_pA3DEntityRef = sTopoRefData.m_pBrepData; + sEntityManager.m_bRefOnTopoItem = true; + A3DMiscReferenceOnTopologyGet(NULL, &sTopoRefData); + } + else if(sType == kA3DTypeMiscReferenceOnCsysItem) + { + A3DMiscReferenceOnCsysItemData sA3DMiscReferenceOnCSYSITemData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnCsysItemData, sA3DMiscReferenceOnCSYSITemData); + A3DMiscReferenceOnCsysItemGet(pEntityRef, &sA3DMiscReferenceOnCSYSITemData); + sEntityManager.m_pA3DEntityRef = sA3DMiscReferenceOnCSYSITemData.m_pCoordinateSystem; + A3DMiscReferenceOnCsysItemGet(NULL, &sA3DMiscReferenceOnCSYSITemData); + } + else + sEntityManager.m_pA3DEntityRef = sMiscRefData.m_pEntity; + + A3DMiscEntityReferenceGet(NULL, &sMiscRefData); + + m_asStepEntityRefManager.push_back(sEntityManager); + } + + A3DStatus iRet = A3D_SUCCESS; + + + ActivateEntityReference(sConnector.GetA3DEntity()); + for(uI = 0; uI < m_apVisitor.size(); uI++) + { + m_apVisitor[uI]->visitEnter(sConnector); + } + + return iRet; +} + +A3DStatus A3DVisitorContainer::visitEnter(const A3DPartConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DRiConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DRiBrepModelConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DRiSetConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DPolyRiBrepModelConnector& sConnector) +VISITENTER + + +A3DStatus A3DVisitorContainer::visitLeave(const A3DModelFileConnector& sConnector) +VISITLEAVE + +A3DStatus A3DVisitorContainer::visitLeave(const A3DProductOccurrenceConnector& sConnector) +{ + for(unsigned uI = 0; uI < m_apVisitor.size(); uI++) + { + m_apVisitor[uI]->visitLeave(sConnector); + } + + unsigned int uI, uNbRefEntity = sConnector.m_sProductOccurrenceData.m_uiEntityReferenceSize; + for (uI = 0; uI < uNbRefEntity; uI++) + { + m_asStepEntityRefManager.pop_back(); + } + + + DeactivateEntityReference(sConnector.GetA3DEntity()); + + m_uiCurrentLevel--; + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorContainer::visitLeave(const A3DPartConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DRiConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DRiBrepModelConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DRiSetConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DPolyRiBrepModelConnector& sConnector) +VISITLEAVE +#endif + +//Markup +#ifdef CONNECT_PMI +A3DStatus A3DVisitorContainer::visitEnter(const A3DMkpAnnotationEntityConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMkpAnnotationSetConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMkpAnnotationItemConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMarkupConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMarkupDimensionConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMarkupGDTConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMarkupDatumConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMarkupTessConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitLeave(const A3DMkpAnnotationEntityConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMkpAnnotationSetConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMkpAnnotationItemConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMarkupDimensionConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMarkupConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMarkupGDTConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMarkupDatumConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMarkupTessConnector& sConnector) +VISITLEAVE + +#endif + +//Brep +#ifdef CONNECT_BREP +A3DStatus A3DVisitorContainer::visitEnter(const A3DBrepDataConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DConnexConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DShellConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DFaceConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DLoopConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DCoEdgeConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DEdgeConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DUniqueVertexConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMultipleVertexConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitLeave(const A3DBrepDataConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DConnexConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DShellConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DFaceConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DLoopConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DCoEdgeConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DEdgeConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DUniqueVertexConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMultipleVertexConnector& sConnector) +VISITLEAVE +#endif + +//Mesh +#ifdef CONNECT_MESH +A3DStatus A3DVisitorContainer::visitEnter(const A3DTessDataConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitLeave(const A3DTessDataConnector& sConnector) +VISITLEAVE + +A3DStatus A3DVisitorContainer::visitEnter(const A3DFaceTessDataConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitLeave(const A3DFaceTessDataConnector& sConnector) +VISITLEAVE + +A3DStatus A3DVisitorContainer::visitEnter(const A3DWireTessDataConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitLeave(const A3DWireTessDataConnector& sConnector) +VISITLEAVE + +//VISIT(const A3DTessDataConnector&) +#endif + +A3DVisitorContainer::A3DVisitorContainer(unsigned int uFlagElementToconnect) +: A3DVisitor("Container"), + m_pTreeVisitor(NULL), + m_pCurrentPOFather(NULL), + m_psActivatedView(NULL), + m_bTraverseActivatedViewOnly(true), + m_uiCurrentLevel(0) +{ +#ifdef CONNECT_TRANSFO + if(uFlagElementToconnect&CONNECT_TRANSFO) + { + A3DVisitorTransfo* psVisistorTransfo = new A3DVisitorTransfo(this); + this->push( psVisistorTransfo); + } +#endif +#ifdef CONNECT_COLORS + if(uFlagElementToconnect&CONNECT_COLORS) + { + A3DVisitorColorMaterials* psVisitorcascadedAttribute = new A3DVisitorColorMaterials(this); + this->push( psVisitorcascadedAttribute); + } +#endif +#ifdef CONNECT_MESH + if(uFlagElementToconnect&CONNECT_MESH) + { + A3DVisitorTessellation* psVisitorTessellation = new A3DVisitorTessellation(this); + this->push( psVisitorTessellation); + } +#endif +#ifdef CONNECT_BREP + if(uFlagElementToconnect&CONNECT_BREP) + { + A3DVisitorBrep* psVisitorBrep = new A3DVisitorBrep(this); + this->push( psVisitorBrep); + } +#endif +#ifdef CONNECT_ASSEMBLY_TREE + if(uFlagElementToconnect&CONNECT_ASSEMBLY_TREE) + { + A3DTreeVisitor* psVisitorTree= new A3DTreeVisitor(this); + this->push( psVisitorTree); + } +#endif +#ifdef CONNECT_PMI + if(uFlagElementToconnect&CONNECT_PMI) + { + //A3DVisitorPMI* psVisitorPMI = new A3DVisitorPMI(this); + //this->push( psVisitorPMI ); + } +#endif +#ifdef CONNECT_VIEWS + if(uFlagElementToconnect&CONNECT_VIEWS) + { + // Not yet Implemented + // A3DVisitorview* psVisitorViews = new A3DVisitorview(this); + // this->push( psVisitorViews); + } + m_bTraverseInstance = true; +#endif +} + +#ifdef CONNECT_VIEWS + +A3DStatus A3DVisitorContainer::visitEnter(const A3DMkpViewConnector& sConnector) +{ + if ((m_psActivatedView == NULL) || (m_psActivatedView != sConnector.GetA3DEntity())) + { + if (!m_bTraverseActivatedViewOnly) + { + VISITENTER; + } + + return A3D_SUCCESS; + } + + // VISITENTER + ActivateEntityReference(sConnector.GetA3DEntity()); + for (unsigned uI = 0; uI < m_apVisitor.size(); uI++) + { + m_apVisitor[uI]->visitEnter(sConnector); + } + + unsigned int uI, uNbRefEntity = sConnector.GetViewData().m_uiLinkedItemsSize; + for (uI = 0; uI < uNbRefEntity; uI++) + { + A3DMiscMarkupLinkedItemData sMkpLinkedItemData; + A3D_INITIALIZE_DATA(A3DMiscMarkupLinkedItemData, sMkpLinkedItemData); + A3DMiscMarkupLinkedItem* pMkpLinkedItemEntityRef = sConnector.GetViewData().m_ppLinkedItems[uI]; + A3DMiscMarkupLinkedItemGet(pMkpLinkedItemEntityRef, &sMkpLinkedItemData); + A3DViewLinkedItemManager sViewLinkedItemManager; + + A3DMiscEntityReferenceData sMiscRefData; + A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sMiscRefData); + A3DMiscEntityReferenceGet(pMkpLinkedItemEntityRef, &sMiscRefData); + + sViewLinkedItemManager.m_pA3DEntityRef = sMiscRefData.m_pEntity; + sViewLinkedItemManager.m_POOwner = sMkpLinkedItemData.m_pTargetProductOccurrence; + sViewLinkedItemManager.m_pMarkupLinkedItem = pMkpLinkedItemEntityRef; + sViewLinkedItemManager.m_uiPOLevel = m_uiCurrentLevel; + + A3DEEntityType sType; + A3DEntityGetType(sMiscRefData.m_pEntity, &sType); + if (sType == kA3DTypeMiscReferenceOnTopology) + { + A3DMiscReferenceOnTopologyData sTopoRefData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnTopologyData, sTopoRefData); + A3DMiscReferenceOnTopologyGet(sMiscRefData.m_pEntity, &sTopoRefData); + sViewLinkedItemManager.m_pA3DEntityRef = sTopoRefData.m_pBrepData; + sViewLinkedItemManager.m_bRefOnTopoItem = true; + A3DMiscReferenceOnTopologyGet(NULL, &sTopoRefData); + } + else if (sType == kA3DTypeMiscReferenceOnCsysItem) + { + A3DMiscReferenceOnCsysItemData sA3DMiscReferenceOnCSYSITemData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnCsysItemData, sA3DMiscReferenceOnCSYSITemData); + A3DMiscReferenceOnCsysItemGet(sMiscRefData.m_pEntity, &sA3DMiscReferenceOnCSYSITemData); + sViewLinkedItemManager.m_pA3DEntityRef = sA3DMiscReferenceOnCSYSITemData.m_pCoordinateSystem; + A3DMiscReferenceOnCsysItemGet(NULL, &sA3DMiscReferenceOnCSYSITemData); + } + else + sViewLinkedItemManager.m_pA3DEntityRef = sMiscRefData.m_pEntity; + + A3DMiscEntityReferenceGet(NULL, &sMiscRefData); + + m_asViewLinkedItemManager.push_back(sViewLinkedItemManager); + } + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorContainer::visitLeave(const A3DMkpViewConnector& sConnector) +{ + if ((m_psActivatedView == NULL) || (m_psActivatedView != sConnector.GetA3DEntity())) + { + if (!m_bTraverseActivatedViewOnly) + VISITLEAVE; + + return A3D_SUCCESS; + } + + VISITLEAVE; +} + +#endif + +void A3DVisitorContainer::push( A3DVisitor* psVisitor ) +{ +// vector::iterator iter = +// search(m_apVisitor.begin(), m_apVisitor.end(), &psVisitor, &psVisitor+1); +// if(iter == m_apVisitor.end()) +// { +// m_apVisitorExcludedForDelete.push_back(psVisitor); +// } + m_apVisitor.push_back(psVisitor); + if(!m_pTreeVisitor) + m_pTreeVisitor = (A3DVisitor*)dynamic_cast(psVisitor);//dynamic_cast return null if failed. +} + + +A3DVisitorContainer::~A3DVisitorContainer() +{ + size_t uI, uNbVisitor = m_apVisitor.size(); +// vector::iterator iter; + for(uI = 0; uI < uNbVisitor; uI++) +// { +// iter = search( m_apVisitorExcludedForDelete.begin(), +// m_apVisitorExcludedForDelete.end(), +// &m_apVisitor[uI], +// &m_apVisitor[uI]+1); +// if(iter == m_apVisitorExcludedForDelete.end()) + delete m_apVisitor[uI]; +// } +} + + +void* A3DVisitorContainer::FindInMap(const A3DEntity* pA3DEntity) +{ + map::iterator my_mapIter; + my_mapIter = m_apA3DEntityYourEntityMap.find(pA3DEntity); + if(my_mapIter == m_apA3DEntityYourEntityMap.end()) + return NULL; + return my_mapIter->second; +} + +void A3DVisitorContainer::SetInMap(const A3DEntity* pA3DEntity, void* pYourEntity) +{ + m_apA3DEntityYourEntityMap.insert(std::pair(pA3DEntity, pYourEntity)); +} + +A3DVisitor* A3DVisitorContainer::GetVisitorByName( std::string strName ) +{ + vector::iterator iter = m_apVisitor.begin(); + for( ; iter != m_apVisitor.end(); ++iter) + if(strName.compare((*iter)->GetName()) == 0) + return *iter; + return NULL; +} + +A3DVisitor* A3DVisitorContainer::GetTreeVisitor() const +{ + return m_pTreeVisitor; +} + +void A3DVisitorContainer::ActivateEntityReference( A3DEntity const* pEntity ) +{ + // StepEntityReference + size_t uI, uNbPushStepEntityRef = m_asStepEntityRefManager.size(); + for(uI = 0; uI < uNbPushStepEntityRef; uI++) + { + if(m_asStepEntityRefManager[uI].m_pA3DEntityRef == pEntity) + { + m_asStepEntityRefManager[uI].m_uiPushLevel = m_uiCurrentLevel; + } + } + + // ViewLinkedItem + size_t uNbPushViewLMkpLinkedItem = m_asViewLinkedItemManager.size(); + for (uI = 0; uI < uNbPushViewLMkpLinkedItem; uI++) + { + A3DViewLinkedItemManager *pCurManager = &m_asViewLinkedItemManager[uI]; + if (pCurManager->m_pA3DEntityRef == pEntity && + ( pCurManager->m_POOwner == NULL || + pCurManager->m_POOwner == pEntity || + pCurManager->m_POOwner == m_pCurrentPOFather + ) + ) + { + pCurManager->m_uiPushLevel = m_uiCurrentLevel; + } + } +} + +void A3DVisitorContainer::DeactivateEntityReference( A3DEntity const* pEntity ) +{ + // StepEntityReference + size_t uI, uNbPushStepEntityRef = m_asStepEntityRefManager.size(); + for(uI = 0; uI < uNbPushStepEntityRef; uI++) + { + if(m_asStepEntityRefManager[uI].m_pA3DEntityRef == pEntity) + { + m_asStepEntityRefManager[uI].m_uiPushLevel = ~0U; + } + } + + // ViewLinkedItem + size_t uNbPushViewLMkpLinkedItem = m_asViewLinkedItemManager.size(); + for (uI = 0; uI < uNbPushViewLMkpLinkedItem; uI++) + { + A3DViewLinkedItemManager *pCurManager = &m_asViewLinkedItemManager[uI]; + if (pCurManager->m_pA3DEntityRef == pEntity && + ( pCurManager->m_POOwner == NULL || + pCurManager->m_POOwner == pEntity || + pCurManager->m_POOwner == m_pCurrentPOFather + ) + ) + { + pCurManager->m_uiPushLevel = ~0U; + } + } +} + +A3DStepEntityRefManager const* A3DVisitorContainer::GetActiveStepEntityRefManager(A3DEntity const * pEntity) const +{ + A3DStepEntityRefManager const * psActivated = NULL; + size_t uI, uNbPushStepEntityRef = m_asStepEntityRefManager.size(); + for(uI = 0; uI < uNbPushStepEntityRef; uI++) + { + A3DStepEntityRefManager const * psCurManager = &m_asStepEntityRefManager[uI]; + if (psCurManager->m_uiPushLevel!=~0U && (pEntity==NULL || psCurManager->m_pA3DEntityRef==pEntity)) + { + if (!psActivated) + psActivated = psCurManager; + else if (psCurManager->IsFirst(*psActivated)) + psActivated = psCurManager; + } + } + return psActivated; +} + +A3DViewLinkedItemManager const* A3DVisitorContainer::GetActiveViewLinkedItemManager(A3DEntity const * pEntity) const +{ + A3DViewLinkedItemManager const * psActivated = NULL; + + size_t uI, uNbPushViewMarkupLinkedItem = m_asViewLinkedItemManager.size(); + for (uI = 0; uI < uNbPushViewMarkupLinkedItem; uI++) + { + A3DViewLinkedItemManager const * psCurManager = &m_asViewLinkedItemManager[uI]; + if (psCurManager->m_uiPushLevel!=~0U && (pEntity==NULL || psCurManager->m_pA3DEntityRef==pEntity)) + { + if (!psActivated) + psActivated = psCurManager; + else if (psCurManager->IsFirst(*psActivated)) + psActivated = psCurManager; + } + } + + return psActivated; +} + + +#ifdef CONNECT_FEATURE +A3DStatus A3DVisitorContainer::visitEnter(const A3DFRMFeatureConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitLeave(const A3DFRMFeatureConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitEnter(const A3DFRMParameterConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitLeave(const A3DFRMParameterConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitEnter(const A3DFRMTreeConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitLeave(const A3DFRMTreeConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitEnter(const A3DFRMLinkedItemConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitLeave(const A3DFRMLinkedItemConnector& sConnector) +VISITLEAVE + +#endif \ No newline at end of file diff --git a/exchange/exchangesource/DumpFeatureTree/Visitor/VisitorContainer.h b/exchange/exchangesource/DumpFeatureTree/Visitor/VisitorContainer.h new file mode 100644 index 0000000..41461e5 --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/Visitor/VisitorContainer.h @@ -0,0 +1,239 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3DVISITOR_CONTAINER +#define A3DVISITOR_CONTAINER +#include +#include "Visitors.h" + +//This class allow to use several vistor when traversing 3DX Tree. +//It allow also to exchange parameters between visitors + +#define NODE_INSTANCES 0x0001 + +class A3DStepEntityRefManager +{ +public: + unsigned int m_uiPOLevel; // Level of creation + unsigned int m_uiPushLevel; // if not ~0U , then is activated + bool m_bRefOnTopoItem;; + A3DMiscEntityReference* m_pStepEntityRef; + A3DEntity* m_pA3DEntityRef; + + A3DStepEntityRefManager() : m_uiPOLevel(~0U), m_uiPushLevel(~0U), m_pStepEntityRef(NULL), m_bRefOnTopoItem(false), + m_pA3DEntityRef(NULL){} + void GetMatrix(); + + bool IsFirst( A3DStepEntityRefManager const & sOther) const { return (m_uiPOLevelsOther.m_uiPushLevel);} +}; + + + +class A3DViewLinkedItemManager + +{ +public: + unsigned int m_uiPOLevel; + unsigned int m_uiPushLevel; // if not ~0U , then is activated + bool m_bRefOnTopoItem; + A3DMiscMarkupLinkedItem * m_pMarkupLinkedItem; + A3DAsmProductOccurrence * m_POOwner; + A3DEntity * m_pA3DEntityRef; + + A3DViewLinkedItemManager() : m_uiPOLevel(~0U), m_uiPushLevel(~0U), m_pMarkupLinkedItem(NULL),m_bRefOnTopoItem(false), + m_POOwner(NULL), m_pA3DEntityRef(NULL){} + void GetMatrix(); + + bool IsFirst( A3DViewLinkedItemManager const & sOther) const { return (m_uiPOLevelsOther.m_uiPushLevel);} +}; + +class A3DVisitorContainer : public A3DVisitor +{ +#ifdef _MSC_VER + +#pragma warning(push) +#pragma warning(disable:4251) // Suppress the warning C4251 because it leads to have that kind of warning : "warning +// C4251: 'A3DVisitorColorMaterials::m_apsCascadedAttribute' : class 'std::vector<_Ty>' needs to have dll-interface to +// be used by clients of class 'A3DVisitorColorMaterials" +// This is because of the "dllexport" on the visitor classes, as they use stl members and it seems that stl causes +// warning with dllexport with microsoft compiler +#endif // _MSC_VER + + std::map m_apA3DEntityYourEntityMap; + std::vector m_apVisitor; + bool m_bTraverseInstance; + + A3DVisitor* m_pTreeVisitor; + A3DAsmProductOccurrence const * m_pCurrentPOFather; + A3DMkpView const * m_psActivatedView; + bool m_bTraverseActivatedViewOnly; + + std::vector m_asStepEntityRefManager; + std::vector m_asViewLinkedItemManager; + unsigned int m_uiCurrentLevel; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif // _MSC_VER + +public: + A3DVisitorContainer(unsigned int uFlagElementToconnect = 0); + + virtual ~A3DVisitorContainer(); + + void push( A3DVisitor* psVisitor); + + //A3DConnector + virtual A3DStatus visitEnter(const A3DConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DConnector& /*sConnector*/) { return A3D_SUCCESS; } + + //Assmebly Tree +#ifdef CONNECT_ASSEMBLY_TREE + virtual A3DStatus visitEnter(const A3DModelFileConnector& sConnector); + virtual A3DStatus visitLeave(const A3DModelFileConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DProductOccurrenceConnector& sConnector); + virtual A3DStatus visitLeave(const A3DProductOccurrenceConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DPartConnector& sConnector); + virtual A3DStatus visitLeave(const A3DPartConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DRiConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiConnector& sConnector); + + + virtual A3DStatus visitEnter(const A3DRiBrepModelConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiBrepModelConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DRiSetConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiSetConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DPolyRiBrepModelConnector& sConnector); + virtual A3DStatus visitLeave(const A3DPolyRiBrepModelConnector& sConnector); + +#endif +#ifdef CONNECT_PMI + //Markup Tree + virtual A3DStatus visitEnter(const A3DMkpAnnotationEntityConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMkpAnnotationEntityConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMkpAnnotationSetConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMkpAnnotationSetConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMkpAnnotationItemConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMkpAnnotationItemConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMarkupConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMarkupConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMarkupDimensionConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMarkupDimensionConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMarkupGDTConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMarkupGDTConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMarkupTessConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMarkupTessConnector& sConnector); + +#endif + +#ifdef CONNECT_BREP + //Brep + virtual A3DStatus visitEnter(const A3DBrepDataConnector& sConnector); + virtual A3DStatus visitLeave(const A3DBrepDataConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DConnexConnector& sConnector); + virtual A3DStatus visitLeave(const A3DConnexConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DShellConnector& sConnector); + virtual A3DStatus visitLeave(const A3DShellConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DFaceConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFaceConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DLoopConnector& sConnector); + virtual A3DStatus visitLeave(const A3DLoopConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DCoEdgeConnector& sConnector); + virtual A3DStatus visitLeave(const A3DCoEdgeConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DEdgeConnector& sConnector); + virtual A3DStatus visitLeave(const A3DEdgeConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DUniqueVertexConnector& sConnector); + virtual A3DStatus visitLeave(const A3DUniqueVertexConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMultipleVertexConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMultipleVertexConnector& sConnector); +#endif +#ifdef CONNECT_MESH + //Mesh + virtual A3DStatus visitEnter(const A3DTessDataConnector& sConnector); + virtual A3DStatus visitLeave(const A3DTessDataConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DFaceTessDataConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFaceTessDataConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMarkupDatumConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMarkupDatumConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DWireTessDataConnector& sConnector); + virtual A3DStatus visitLeave(const A3DWireTessDataConnector& sConnector); + + +#endif + //Views +#ifdef CONNECT_VIEWS + virtual A3DStatus visitEnter(const A3DMkpViewConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMkpViewConnector& sConnector); +#endif +#ifdef CONNECT_FEATURE + virtual A3DStatus visitEnter(const A3DFRMFeatureConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFRMFeatureConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DFRMParameterConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFRMParameterConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DFRMTreeConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFRMTreeConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DFRMLinkedItemConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFRMLinkedItemConnector& sConnector); +#endif + + void* FindInMap(const A3DEntity* pA3DEntity); + void SetInMap(const A3DEntity* pA3DEntity, void* pYourEntity); + + std::vector& GetVisitor() { return m_apVisitor; } + + + bool TraverseInstances() { return m_bTraverseInstance; } + void SetTraverseInstance(bool bTraverseInstance) { m_bTraverseInstance = bTraverseInstance; } + + A3DVisitor* GetVisitorByName(std::string strName); + A3DVisitor* GetTreeVisitor() const; + + void SetCurrentPoFather(A3DAsmProductOccurrence const * pCurrentPOFather) { m_pCurrentPOFather = pCurrentPOFather; } + A3DAsmProductOccurrence const * GetCurrentPoFather() { return m_pCurrentPOFather; } + + void SetActivateView(A3DMkpView const * psActivatedView) { m_psActivatedView = psActivatedView; } + A3DMkpView const * GetActivatedView() { return m_psActivatedView; } + + void SetTraverseActivatedViewOnly(bool bTraverseActivatedViewOnly) { m_bTraverseActivatedViewOnly = bTraverseActivatedViewOnly; } + + // StepEntityReference and ViewLinkedItem treatment + A3DStepEntityRefManager const* GetActiveStepEntityRefManager(A3DEntity const * pEntity) const; + A3DViewLinkedItemManager const* GetActiveViewLinkedItemManager(A3DEntity const * pEntity) const; + + void ActivateEntityReference( A3DEntity const* pEntity ); + void DeactivateEntityReference(A3DEntity const* pEntity); +}; +#endif diff --git a/exchange/exchangesource/DumpFeatureTree/Visitor/VisitorTree.cpp b/exchange/exchangesource/DumpFeatureTree/Visitor/VisitorTree.cpp new file mode 100644 index 0000000..914acaa --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/Visitor/VisitorTree.cpp @@ -0,0 +1,87 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "VisitorTree.h" + +A3DStatus A3DTreeVisitor::visitEnter(const A3DRiBrepModelConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DRiBrepModelConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitEnter(const A3DRiSetConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DRiSetConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitEnter(const A3DRiConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DRiConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitEnter(const A3DPartConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DPartConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitEnter(const A3DProductOccurrenceConnector& sConnector) +{ + if(m_uOption&NODE_INSTANCES) + { + m_pYourEntity = m_psContainer->FindInMap(sConnector.GetA3DEntity()); + if(m_pYourEntity) + { + ((A3DProductOccurrenceConnector*) &sConnector)->SetIsInstanciated(true); + } + } + + m_psContainer->SetInMap(sConnector.GetA3DEntity(),(void*) sConnector.GetA3DEntity() ); + + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DProductOccurrenceConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + + +void A3DTreeVisitor::SetYourEntity(void* /*pYourEnity*/) +{ + //std::vector::iterator sIter; + //for(sIter = m_asStepEntityRefManager.begin(); sIter != m_asStepEntityRefManager.end(); ++sIter) + //{ + // if(sIter->m_bPushChildren == true) + // sIter->m_apYourEntity.push_back(pYourEnity); + //} + // + //return; +} + diff --git a/exchange/exchangesource/DumpFeatureTree/Visitor/VisitorTree.h b/exchange/exchangesource/DumpFeatureTree/Visitor/VisitorTree.h new file mode 100644 index 0000000..4fc80b2 --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/Visitor/VisitorTree.h @@ -0,0 +1,57 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef VISIT_TREE +#define VISIT_TREE +#include "Visitors.h" +#include "VisitorContainer.h" + + +class A3DConnector; +class A3DVisitorContainer; + +class A3DTreeVisitor : public A3DVisitor +{ + friend class A3DVisitorContainer; +protected: + unsigned m_uOption; + void* m_pYourEntity; + +public: + + A3DTreeVisitor(A3DVisitorContainer* psContainer = NULL) : A3DVisitor("Tree", psContainer) + { + m_uOption = 0; + m_pYourEntity = NULL; + } + + virtual ~A3DTreeVisitor() {}; + + virtual A3DStatus visitEnter(const A3DRiBrepModelConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiBrepModelConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DRiSetConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiSetConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DRiConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DPartConnector& sConnector ); + virtual A3DStatus visitLeave(const A3DPartConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DProductOccurrenceConnector& sConnector); + virtual A3DStatus visitLeave(const A3DProductOccurrenceConnector& sConnector); + + + void SetYourEntity(void* pYourEnity); + +}; +#endif \ No newline at end of file diff --git a/exchange/exchangesource/DumpFeatureTree/Visitor/Visitors.h b/exchange/exchangesource/DumpFeatureTree/Visitor/Visitors.h new file mode 100644 index 0000000..9531cc0 --- /dev/null +++ b/exchange/exchangesource/DumpFeatureTree/Visitor/Visitors.h @@ -0,0 +1,206 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_VISITOR +#define A3D_VISITOR + +//#define CONNECT_TRANSFO 0x0001 +//#define CONNECT_COLORS 0x0002 +//#define CONNECT_MESH 0x0004 +#define CONNECT_ASSEMBLY_TREE 0x008 +//#define CONNECT_BREP 0x0010 +//#define CONNECT_PMI 0x00020 +//#define CONNECT_VIEWS 0x00040 +#define CONNECT_FEATURE 0x00080 + + +#include "TreeTraverse.h" +#ifdef CONNECT_PMI +#include "MarkupTraverse.h" +#endif +#ifdef CONNECT_BREP +#include "BrepTraverse.h" +#endif +#ifdef CONNECT_PMI +#include "MarkupTraverse.h" +#endif +#ifdef CONNECT_MESH +#include "TessConnector.h" +#endif +#ifdef CONNECT_VIEWS +#include "ViewTraverse.h" +#endif + +#include + +#ifndef CALL_A3D_FCTION +#define CALL_A3D_FCTION(fctname, params) \ + fctname params +#endif + +#ifndef CHECK_RET_CALL_A3D_FCTION +#define CHECK_RET_CALL_A3D_FCTION(fctname, params) \ + { \ + if ((iRet = fctname params)!=A3D_SUCCESS) \ + { /*__debugbreak();*/ return iRet; } \ + } +#endif + +#ifndef CHECK_RET +#define CHECK_RET(function_call) \ + {\ + if ((iRet = function_call)!=A3D_SUCCESS) \ + return iRet; \ + } +#endif + +class A3DConnector; +class A3DVisitorContainer; +class A3DVisitor +{ +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) // Suppress the warning C4251 because it leads to have that kind of warning : "warning + // C4251: 'A3DVisitorColorMaterials::m_apsCascadedAttribute' : class 'std::vector<_Ty>' needs to have dll-interface to + // be used by clients of class 'A3DVisitorColorMaterials" + // This is because of the "dllexport" on the visitor classes, as they use stl members and it seems that stl causes + // warning with dllexport with microsoft compiler +#endif // _MSC_VER + +protected: + A3DVisitorContainer* m_psContainer; + std::string m_strName; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif // _MSC_VER + +public : + A3DVisitor(std::string strName, A3DVisitorContainer* psContainer = NULL) + : m_strName(strName), m_psContainer(psContainer){} + + virtual ~A3DVisitor() {} + + virtual std::string GetName() const { return m_strName; } + +//Assembly +#ifdef CONNECT_ASSEMBLY_TREE + virtual A3DStatus visitEnter(const A3DModelFileConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DModelFileConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DProductOccurrenceConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DProductOccurrenceConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DPartConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DPartConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DRiConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DRiConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DRiBrepModelConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DRiBrepModelConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DRiSetConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DRiSetConnector& /*sConnector*/) { return A3D_SUCCESS;} + + virtual A3DStatus visitEnter(const A3DPolyRiBrepModelConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DPolyRiBrepModelConnector& /*sConnector*/) { return A3D_SUCCESS; } + +#endif +//Markup +#ifdef CONNECT_PMI + virtual A3DStatus visitEnter(const A3DMkpAnnotationEntityConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMkpAnnotationEntityConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMkpAnnotationSetConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMkpAnnotationSetConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMkpAnnotationItemConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMkpAnnotationItemConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMarkupConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMarkupConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMarkupDimensionConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMarkupDimensionConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMarkupGDTConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMarkupGDTConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMarkupDatumConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMarkupDatumConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMarkupTessConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMarkupTessConnector& /*sConnector*/) { return A3D_SUCCESS; } + +#endif +//Brep +#ifdef CONNECT_BREP + virtual A3DStatus visitEnter(const A3DBrepDataConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DBrepDataConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DConnexConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DConnexConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DShellConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DShellConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DFaceConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DFaceConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DLoopConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DLoopConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DCoEdgeConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DCoEdgeConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DEdgeConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DEdgeConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DUniqueVertexConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DUniqueVertexConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMultipleVertexConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMultipleVertexConnector&) { return A3D_SUCCESS; } +#endif + //Mesh +#ifdef CONNECT_MESH + virtual A3DStatus visitEnter(const A3DTessDataConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DTessDataConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DFaceTessDataConnector&) {return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DFaceTessDataConnector&) {return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DWireTessDataConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DWireTessDataConnector&) { return A3D_SUCCESS; } +#endif + //Views +#ifdef CONNECT_VIEWS + virtual A3DStatus visitEnter(const A3DMkpViewConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMkpViewConnector&) { return A3D_SUCCESS; } +#endif +#ifdef CONNECT_FEATURE + virtual A3DStatus visitEnter(const A3DFRMFeatureConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DFRMFeatureConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DFRMParameterConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DFRMParameterConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DFRMTreeConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DFRMTreeConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DFRMLinkedItemConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DFRMLinkedItemConnector& /*sConnector*/) { return A3D_SUCCESS; } +#endif +}; + + +#endif diff --git a/exchange/exchangesource/ImportExport/ImportExport.cpp b/exchange/exchangesource/ImportExport/ImportExport.cpp new file mode 100644 index 0000000..6bf1818 --- /dev/null +++ b/exchange/exchangesource/ImportExport/ImportExport.cpp @@ -0,0 +1,82 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +/* +* This sample demonstrates how to load a model and export it as a model file of a different format. The chosen +* format is determined by the file extension of the output file name. +*/ + +#define INITIALIZE_A3D_API +#include + +#include "../common.hpp" + +static MY_CHAR acSrcFileName[_MAX_PATH * 2]; +static MY_CHAR acDstFileName[_MAX_PATH * 2]; +static MY_CHAR acLogFileName[_MAX_PATH * 2]; + +//###################################################################################################################### +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + // + // ### COMMAND LINE ARGUMENTS + // + + if (iArgc < 2) + { + MY_PRINTF2("Usage:\n %s [input CAD file] [output CAD file] [output LOG file]\n", ppcArgv[0]); + MY_PRINTF(" Default output CAD file is [input CAD file].prc\n"); + MY_PRINTF(" Default output LOG file is [output CAD file]_Log.txt\n\n"); + return A3D_ERROR; + } + + if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]); + else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD); + if (iArgc > 2) MY_STRCPY(acDstFileName, ppcArgv[2]); + else MY_SPRINTF(acDstFileName, "%s.prc", acSrcFileName); + if (iArgc > 3) MY_STRCPY(acLogFileName, ppcArgv[3]); + else MY_SPRINTF(acLogFileName, "%s_Log.txt", acDstFileName); + GetLogFile(acLogFileName); // Initialize log file + + // + // ### INITIALIZE HOOPS EXCHANGE + // + + A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); + CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus); + + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + // + // ### PROCESS SAMPLE CODE + // + + // specify input file + A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + + // specify output file + A3DExport sExport(acDstFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + + // perform conversion + CHECK_RET(sHoopsExchangeLoader.Convert(sImport, sExport)); + + // + // ### TERMINATE HOOPS EXCHANGE + // + + // Check memory allocations + return (int)ListLeaks(); +} diff --git a/exchange/exchangesource/ImportExport/ImportExport.vcxproj b/exchange/exchangesource/ImportExport/ImportExport.vcxproj new file mode 100644 index 0000000..bca1ef3 --- /dev/null +++ b/exchange/exchangesource/ImportExport/ImportExport.vcxproj @@ -0,0 +1,165 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {58B52422-7322-40C5-BFF7-8E575B7AB63C} + ImportExport + Win32Proj + 10.0 + + + + Application + v145 + true + + + Application + v145 + + + Application + v145 + true + + + Application + v145 + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + ;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + true + Console + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + Disabled + ;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + true + Console + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + MaxSpeed + true + ;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + Level4 + ProgramDatabase + false + + + true + Console + true + true + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + MaxSpeed + true + ;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + Level4 + ProgramDatabase + false + + + true + Console + true + true + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/ImportExport/ImportExport.vcxproj.filters b/exchange/exchangesource/ImportExport/ImportExport.vcxproj.filters new file mode 100644 index 0000000..3495a6f --- /dev/null +++ b/exchange/exchangesource/ImportExport/ImportExport.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + Source Files + + + \ No newline at end of file diff --git a/exchange/exchangesource/IncrementalLoad/IncrementalLoad.cpp b/exchange/exchangesource/IncrementalLoad/IncrementalLoad.cpp new file mode 100644 index 0000000..38d0bac --- /dev/null +++ b/exchange/exchangesource/IncrementalLoad/IncrementalLoad.cpp @@ -0,0 +1,166 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file IncrementalLoad.cpp + +Incremental loading technique allows a more fine-grained approach for loading files, +which is especially beneficial when dealing with huge files +(e.g. I want to load only item 26 and 72, not the whole file in one shot). + +The only input is the file path, optionnal inputs are is the reading mode of the file and unload. + +***********************************************************************************************************************/ + +#define _CRT_SECURE_NO_DEPRECATE 1 +#define INITIALIZE_A3D_API +#include + +#include "../common.hpp" + +//###################################################################################################################### +A3DStatus stLoadRequiredProductOccurrence(A3DAsmProductOccurrence* pOcc, + A3DAsmProductOccurrence* pRoot, + A3DSDKHOOPSExchangeLoader& sHoopsExchangeLoader, + A3DImport& sImport, + A3DEReadGeomTessMode eMode, + bool bWithUnload) +{ + A3DStatus iRet = A3D_SUCCESS; + + if (pRoot == NULL) + { + // trying to incremental load a part... + return A3D_ERROR; + } + + sImport.m_sLoadData.m_sGeneral.m_eReadGeomTessMode = eMode; + sImport.m_sLoadData.m_sIncremental.m_bLoadStructureOnly = false; + sImport.m_sLoadData.m_sIncremental.m_ppProductOccurrences = &pOcc; + sImport.m_sLoadData.m_sIncremental.m_pRootProductOccurrence = pRoot; + sImport.m_sLoadData.m_sIncremental.m_uiProductOccurrencesSize = 1; + + CHECK_RET(sHoopsExchangeLoader.Import(sImport)); + + if (bWithUnload) + { + CHECK_RET(A3DAsmModelFileUnloadParts(sHoopsExchangeLoader.m_psModelFile, 1, &pOcc)); + } + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stIncrementalLoadFromProductOccurrences(A3DAsmProductOccurrence* pProductOccurrence, + A3DAsmProductOccurrence* pRoot, + A3DSDKHOOPSExchangeLoader& sHoopsExchangeLoader, + A3DImport& sImport, + A3DEReadGeomTessMode eMode, + bool bWithUnload) +{ + // get the data + A3DAsmProductOccurrenceData sProductOccurrenceData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductOccurrenceData); + CHECK_RET(A3DAsmProductOccurrenceGet(pProductOccurrence, &sProductOccurrenceData)); + + // If the PO is a leaf, load the PO + if (sProductOccurrenceData.m_uiPOccurrencesSize == 0) + { + stLoadRequiredProductOccurrence(pProductOccurrence, pRoot, sHoopsExchangeLoader, sImport, eMode, bWithUnload); + } + // If not, find leaves recursively + else + { + for (A3DUns32 i = 0; i < sProductOccurrenceData.m_uiPOccurrencesSize; ++i) + { + stIncrementalLoadFromProductOccurrences(sProductOccurrenceData.m_ppPOccurrences[i], pProductOccurrence, sHoopsExchangeLoader, sImport, eMode, bWithUnload); + } + } + A3DAsmProductOccurrenceGet(nullptr, &sProductOccurrenceData); + return A3D_SUCCESS; +} + +static MY_CHAR acSrcFileName[_MAX_PATH * 2]; +static MY_CHAR acDstFileName[_MAX_PATH * 2]; +static MY_CHAR acLogFileName[_MAX_PATH * 2]; + +//###################################################################################################################### +// Main function +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + // + // ### COMMAND LINE ARGUMENTS + // + + if (iArgc > 5) + { + MY_PRINTF2("Usage:\n %s [input CAD file] [reading mode: 0=geom only, 1=geom+tess, 2=tess only] [with unload] [output LOG file]\n", ppcArgv[0]); + MY_PRINTF(" Default output LOG file is [input CAD file]_Log.txt\n\n"); + return A3D_ERROR; + } + + A3DEReadGeomTessMode eMode = kA3DReadTessOnly; + bool bWithUnload = true; + + if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]); + else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD); + if (iArgc > 2) eMode = (A3DEReadGeomTessMode)MY_ATOI(ppcArgv[2]); + else eMode = kA3DReadTessOnly; + if (iArgc > 3) bWithUnload = MY_ATOI(ppcArgv[3]) == 1; + else bWithUnload = true; + if (iArgc > 4) MY_STRCPY(acLogFileName, ppcArgv[4]); + else MY_SPRINTF(acLogFileName, "%s_Log.txt", acDstFileName); + GetLogFile(acLogFileName); // Initialize log file + + // + // ### INITIALIZE HOOPS EXCHANGE + // + + A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); + CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus); + + // Initialize call backs + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + // + // ### PROCESS SAMPLE CODE + // + + A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + + //loading of the CAD file in incremental mode + sImport.m_sLoadData.m_sIncremental.m_bLoadStructureOnly = true; + A3DStatus iRet = sHoopsExchangeLoader.Import(sImport); + if (iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS) + CHECK_RET(iRet); + + // Get Model File + A3DAsmModelFileData sModelFileData; + A3D_INITIALIZE_DATA(A3DAsmModelFileData, sModelFileData); + CHECK_RET(A3DAsmModelFileGet(sHoopsExchangeLoader.m_psModelFile, &sModelFileData)); + + // iterate on each root PO + for (A3DUns32 i = 0; i < sModelFileData.m_uiPOccurrencesSize; ++i) + { + stIncrementalLoadFromProductOccurrences(sModelFileData.m_ppPOccurrences[i], NULL, sHoopsExchangeLoader, sImport, eMode, bWithUnload); + } + A3DAsmModelFileGet(nullptr, &sModelFileData); + // + // ### TERMINATE HOOPS EXCHANGE + // + + // Check memory allocations + return (int)ListLeaks(); +} diff --git a/exchange/exchangesource/IncrementalLoad/IncrementalLoad.vcxproj b/exchange/exchangesource/IncrementalLoad/IncrementalLoad.vcxproj new file mode 100644 index 0000000..1b496ab --- /dev/null +++ b/exchange/exchangesource/IncrementalLoad/IncrementalLoad.vcxproj @@ -0,0 +1,180 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {6A9058C6-06BD-4213-8F50-BC7DF8305EC0} + IncrementalLoad + Win32Proj + 10.0 + + + + Application + v145 + true + + + Application + v145 + false + + + Application + v145 + true + + + Application + v145 + false + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + LinkVerboseLib + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + false + + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + LinkVerboseLib + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + false + + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + Use + Level4 + ProgramDatabase + false + + + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + true + true + false + + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + Use + Level4 + ProgramDatabase + false + + + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + true + true + false + + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/IncrementalLoad/IncrementalLoad.vcxproj.filters b/exchange/exchangesource/IncrementalLoad/IncrementalLoad.vcxproj.filters new file mode 100644 index 0000000..781a84c --- /dev/null +++ b/exchange/exchangesource/IncrementalLoad/IncrementalLoad.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {513ECD84-F743-49CE-84FB-646C76083915} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {EA354C8E-1C5B-4C36-85AB-AAA368E888FB} + h;hpp;hxx;hm;inl;inc;xsd + + + {BABC709D-0B23-4E7F-BAD2-C291E6F52054} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + Source Files + + + \ No newline at end of file diff --git a/exchange/exchangesource/LoadMultiConfigCADFile/LoadMultiConfigCADFile.cpp b/exchange/exchangesource/LoadMultiConfigCADFile/LoadMultiConfigCADFile.cpp new file mode 100644 index 0000000..17b1a91 --- /dev/null +++ b/exchange/exchangesource/LoadMultiConfigCADFile/LoadMultiConfigCADFile.cpp @@ -0,0 +1,170 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file LoadMultiConfigCADFile.cpp + +This file demonstrates how to programmatically load CAD files that contain multiple configurations using HOOPS Exchange. +The only input is the file path. +***********************************************************************************************************************/ + +#define _CRT_SECURE_NO_DEPRECATE 1 +#define INITIALIZE_A3D_API +#include + +#include "../common.hpp" + +//###################################################################################################################### +A3DStatus stLoadMultiConfigFile(A3DSDKHOOPSExchangeLoader& sHoopsExchangeLoader, A3DImport& sImport) +{ + A3DStatus iRet = A3D_SUCCESS; + + sImport.m_sLoadData.m_sGeneral.m_bReadSolids = true; + sImport.m_sLoadData.m_sGeneral.m_bReadSurfaces = true; + sImport.m_sLoadData.m_sGeneral.m_eReadGeomTessMode = kA3DReadGeomOnly; + + A3DUTF8Char* pcName = NULL; + FILE* pLogFile = GetLogFile(); + + for(int i = 0; i < 2; ++i) + { + sImport.m_sLoadData.m_sMultiEntries.m_bLoadDefault = (i == 0) ? true : false; + + iRet = sHoopsExchangeLoader.Import(sImport); + if(iRet == A3D_SUCCESS || iRet == A3D_LOAD_MULTI_MODELS_CADFILE || iRet == A3D_LOAD_MISSING_COMPONENTS) + { + A3DAsmModelFile* pModelFile=sHoopsExchangeLoader.m_psModelFile; + sHoopsExchangeLoader.m_psModelFile = NULL; + A3DAsmModelFileData sModelFileData; + A3D_INITIALIZE_DATA(A3DAsmModelFileData, sModelFileData); + + CHECK_RET(A3DAsmModelFileGet(pModelFile, &sModelFileData)); + + // the first level of ProductOccurrences + A3DAsmProductOccurrenceData sRootProductOccurrenceData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sRootProductOccurrenceData); + CHECK_RET(A3DAsmProductOccurrenceGet(sModelFileData.m_ppPOccurrences[0], &sRootProductOccurrenceData)); + + fprintf(pLogFile, "\nNumber of configurations: %u with m_bLoadDefault=%i\n", sRootProductOccurrenceData.m_uiPOccurrencesSize, sImport.m_sLoadData.m_sMultiEntries.m_bLoadDefault); + if(i == 1) //sLoadParametersData.m_sMultiEntries.m_bLoadDefault=false + fprintf(pLogFile, "None of the configurations have been loaded\n"); + + A3DAsmProductOccurrenceData sProductOccurrenceData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductOccurrenceData); + A3DRootBaseData sRootBaseData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sRootBaseData); + + for(unsigned int j = 0; j < sRootProductOccurrenceData.m_uiPOccurrencesSize; j++) + { + CHECK_RET(A3DAsmProductOccurrenceGet(sRootProductOccurrenceData.m_ppPOccurrences[j], &sProductOccurrenceData)); + + if(sProductOccurrenceData.m_uiProductFlags&A3D_PRODUCT_FLAG_CONFIG && sProductOccurrenceData.m_uiProductFlags&A3D_PRODUCT_FLAG_DEFAULT) + { + if(i == 0) //sLoadParametersData.m_sMultiEntries.m_bLoadDefault=true; + { + fprintf(pLogFile, "The config #%u is the default one.\n", j); + // getting its name + CHECK_RET(A3DRootBaseGet(sRootProductOccurrenceData.m_ppPOccurrences[j], &sRootBaseData)); + + pcName = (A3DUTF8Char*) malloc(A3DUns32(strlen(sRootBaseData.m_pcName))+1); + strncpy(pcName, sRootBaseData.m_pcName, strlen(sRootBaseData.m_pcName)); + pcName[strlen(sRootBaseData.m_pcName)] = '\0'; + + CHECK_RET(A3DRootBaseGet(NULL, &sRootBaseData)); + fprintf(pLogFile, "The default configuration has been loaded.\n"); + } + } + else + { + if(i == 0) + fprintf(pLogFile, "The config #%u is not the default one, its children have not been loaded.\n", j); + } + + fprintf(pLogFile, "Number of children of config #%u: %u.\n", j, sProductOccurrenceData.m_uiPOccurrencesSize); + + // don't forget to free the allocated data + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sProductOccurrenceData)); + } + + // freeing the rest + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sRootProductOccurrenceData)); + + CHECK_RET(A3DAsmModelFileGet(NULL, &sModelFileData)); + + CHECK_RET(A3DAsmModelFileDelete(pModelFile)); + } + } + + // now we know the default configuration number, we can load it, or any other configuration needed + sImport.m_sLoadData.m_sMultiEntries.m_bLoadDefault = false; + sImport.m_sLoadData.m_sMultiEntries.m_uiEntriesSize = 1; + sImport.m_sLoadData.m_sMultiEntries.m_ppcEntries = &pcName; + + sHoopsExchangeLoader.Import(sImport); + + // Your processing... + + return iRet; +} + +static MY_CHAR acSrcFileName[_MAX_PATH * 2]; +static MY_CHAR acLogFileName[_MAX_PATH * 2]; + +//###################################################################################################################### +// Main function +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + // + // ### COMMAND LINE ARGUMENTS + // + + if (iArgc > 3) + { + MY_PRINTF2("Usage:\n %s [input CAD file] [output LOG file]\n", ppcArgv[0]); + MY_PRINTF(" Default output LOG file is [input CAD file]_Log.txt\n\n"); + return A3D_ERROR; + } + + if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]); + else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD); + if (iArgc > 2) MY_STRCPY(acLogFileName, ppcArgv[2]); + else MY_SPRINTF(acLogFileName, "%s_Log.txt", acSrcFileName); + GetLogFile(acLogFileName); // Initialize log file + + // + // ### INITIALIZE HOOPS EXCHANGE + // + + A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); + CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus); + + // Initialize callbacks + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + // + // ### PROCESS SAMPLE CODE + // + + A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + + CHECK_RET(stLoadMultiConfigFile(sHoopsExchangeLoader, sImport)); + + // + // ### TERMINATE HOOPS EXCHANGE + // + + // Check memory allocations + return (int)ListLeaks(); +} diff --git a/exchange/exchangesource/LoadMultiConfigCADFile/LoadMultiConfigCADFile.vcxproj b/exchange/exchangesource/LoadMultiConfigCADFile/LoadMultiConfigCADFile.vcxproj new file mode 100644 index 0000000..541ce25 --- /dev/null +++ b/exchange/exchangesource/LoadMultiConfigCADFile/LoadMultiConfigCADFile.vcxproj @@ -0,0 +1,180 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {88467A66-9EF5-43F4-AD35-DB2C530E2374} + LoadMultiConfigCADFile + Win32Proj + 10.0 + + + + Application + v145 + true + + + Application + v145 + false + + + Application + v145 + true + + + Application + v145 + false + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + LinkVerboseLib + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + false + + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + LinkVerboseLib + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + false + + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + Use + Level4 + ProgramDatabase + false + + + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + true + true + false + + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + Use + Level4 + ProgramDatabase + false + + + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + true + true + false + + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/LoadMultiConfigCADFile/LoadMultiConfigCADFile.vcxproj.filters b/exchange/exchangesource/LoadMultiConfigCADFile/LoadMultiConfigCADFile.vcxproj.filters new file mode 100644 index 0000000..6e848ea --- /dev/null +++ b/exchange/exchangesource/LoadMultiConfigCADFile/LoadMultiConfigCADFile.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + Source Files + + + \ No newline at end of file diff --git a/exchange/exchangesource/MultiplePRCFiles/MultiplePRC.cpp b/exchange/exchangesource/MultiplePRCFiles/MultiplePRC.cpp new file mode 100644 index 0000000..81ed961 --- /dev/null +++ b/exchange/exchangesource/MultiplePRCFiles/MultiplePRC.cpp @@ -0,0 +1,403 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file MultiplePrc.cpp + +This file demonstrates how to programmatically create and read multiple PRC files +from a CAD assembly using HOOPS Exchange. +The input is the CAD assembly file path and a directory. +The program generates multiple PRC files from this CAD assembly. + +This mode is supported for the following format: V4, V5, ProE, UG, SLDW. +With other formats, only one PRC file is generated. + +***********************************************************************************************************************/ + +#define _CRT_SECURE_NO_DEPRECATE 1 + +#include + +#define INITIALIZE_A3D_API +#include + +#include "../common.hpp" + +//###################################################################################################################### +bool MakePath(const std::string& strPath); +std::string ExtractPath(const A3DUTF8Char* pcIn); +std::string ExtractFileName(const A3DUTF8Char* pcIn); +A3DStatus TestOutputFile(const std::string& strFileName); + +static MY_CHAR acSrcFileName[_MAX_PATH * 2]; +static MY_CHAR acDstPathName[_MAX_PATH * 2]; +static MY_CHAR acLogFileName[_MAX_PATH * 2]; + +//###################################################################################################################### +// Main function +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + // + // ### INITIALIZE HOOPS EXCHANGE + // + + A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); + CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus); + + // Initialize callbacks + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + // + // ### COMMAND LINE ARGUMENTS + // + + if (iArgc > 4) + { + MY_PRINTF2("Usage:\n %s [input CAD file] [output PRC path] [output LOG file]\n", ppcArgv[0]); + MY_PRINTF(" Default output PRC path is from [input CAD file]\n"); + MY_PRINTF(" Default output LOG file is [input CAD file]_Log.txt\n\n"); + return A3D_ERROR; + } + + A3DUTF8Char sSrcFileNameUTF8[_MAX_PATH]; + if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]); + else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD); + +#ifdef _MSC_VER + A3DMiscUTF16ToUTF8(acSrcFileName, sSrcFileNameUTF8); +#else + MY_STRCPY(sSrcFileNameUTF8, acSrcFileName); +#endif + + A3DUTF8Char sDstFileNameUTF8[_MAX_PATH]; + if (iArgc > 2) + { + MY_STRCPY(acDstPathName, ppcArgv[2]); +#ifdef _MSC_VER + A3DMiscUTF16ToUTF8(acDstPathName, sDstFileNameUTF8); +#else + MY_STRCPY(sDstFileNameUTF8, acDstPathName); +#endif + } + else + { + std::string strPath = ExtractPath(sSrcFileNameUTF8); + strcpy(sDstFileNameUTF8, strPath.c_str()); + } + + if (iArgc > 3) MY_STRCPY(acLogFileName, ppcArgv[3]); + else MY_SPRINTF(acLogFileName, "%s_Log.txt", acSrcFileName); + GetLogFile(acLogFileName); // Initialize log file + + // + // ### PROCESS SAMPLE CODE + // + + std::string strMainFileName = ExtractFileName(sSrcFileNameUTF8); + std::string strOutDir = sDstFileNameUTF8; + // remove " from path (if found). + for (size_t iFound = strOutDir.find('"'); iFound != std::string::npos; iFound = strOutDir.find('"')) + strOutDir.erase(iFound, 1); + + //////////////////////////////////////////////////////////////////////////// + // Check input file and output directory. + //////////////////////////////////////////////////////////////////////////// + if (FILE* pFile = fopen(sSrcFileNameUTF8, "rb")) + { + fclose(pFile); + } + else + { + fprintf(stderr, "cannot open input file %s\n", sSrcFileNameUTF8); + return A3D_LOAD_CANNOT_ACCESS_CADFILE; + } + + //////////////////////////////////////////////////////////////////////////// + // 2- Read input file in mode "tree only". + //////////////////////////////////////////////////////////////////////////// + A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + sImport.m_sLoadData.m_sIncremental.m_bLoadStructureOnly = true; + A3DStatus iRet = sHoopsExchangeLoader.Import(sImport); + if (iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS) + CHECK_RET(iRet); + + //////////////////////////////////////////////////////////////////////////// + // 3- Extract file names. + //////////////////////////////////////////////////////////////////////////// + A3DUns32 nbFiles = 0, nbAssemblyFiles = 0, nbMissingFiles = 0; + A3DUTF8Char** ppPaths = NULL, ** ppAssemblyPaths = NULL, ** ppMissingPaths = NULL; + CHECK_RET(A3DAsmGetFilesPathFromModelFile(sHoopsExchangeLoader.m_psModelFile, &nbFiles, &ppPaths, &nbAssemblyFiles, &ppAssemblyPaths, &nbMissingFiles, &ppMissingPaths)); + + //////////////////////////////////////////////////////////////////////////// + // Check consistency for this sample : if the input file doesn't need this pipeline, export it as a prc and avoid + // the "tree only" export and the reassembly. + //////////////////////////////////////////////////////////////////////////// + const std::string strOutBaseFileName = strOutDir +#ifdef WIN32 + + "\\__" +#else + + "/__" +#endif + + strMainFileName; + + if (nbFiles == 1 && strcmp(ppPaths[0], sSrcFileNameUTF8) == 0) + //The file found is a part or an assembly file. In order to not generate 3 output files (tree only, part + // file and re-assembled file) for one input file, we test this case and avoid the useless work. + { + // test output file writeability + const std::string strOutFileName = strOutBaseFileName + ".prc"; + const A3DStatus eFileOK = TestOutputFile(strOutFileName); + if (eFileOK != A3D_SUCCESS) + return eFileOK; + + CHECK_RET(A3DAsmModelFileDelete(sHoopsExchangeLoader.m_psModelFile)); + sHoopsExchangeLoader.m_psModelFile = NULL; + + sImport.m_sLoadData.m_sIncremental.m_bLoadStructureOnly = false; + + iRet = sHoopsExchangeLoader.Import(sImport); + if (iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS) + CHECK_RET(iRet); + + A3DExport sExport(strOutFileName.c_str()); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + CHECK_RET(sHoopsExchangeLoader.Export(sExport)); + + // + // ### TERMINATE HOOPS EXCHANGE + // + + // Check memory allocations + return (int)ListLeaks(); + } + + ////////////////////////////////////////////////////////////////////////// + // 4- make output path + ////////////////////////////////////////////////////////////////////////// + if (MakePath(strOutDir) == false) + { + fprintf(stderr, "Cannot create output base folder: '%s'.\n", strOutDir.c_str()); + } + + ////////////////////////////////////////////////////////////////////////// + // 5- export main file as an prc assembly + ////////////////////////////////////////////////////////////////////////// + // test output file writability + const std::string strOutMainFileName = strOutBaseFileName + "Structure.prc"; + const A3DStatus eFileOK = TestOutputFile(strOutMainFileName); + if (eFileOK != A3D_SUCCESS) + return eFileOK; + + A3DExport sExport(strOutMainFileName.c_str()); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + CHECK_RET(sHoopsExchangeLoader.Export(sExport)); + CHECK_RET(A3DAsmModelFileDelete(sHoopsExchangeLoader.m_psModelFile)); + sHoopsExchangeLoader.m_psModelFile = NULL; + + ////////////////////////////////////////////////////////////////////////// + // 6- create mapped file names for PRC part files + // export part as PRC + // incremental load for part with multiple configurations + ////////////////////////////////////////////////////////////////////////// + sImport.m_sLoadData.m_sIncremental.m_bLoadStructureOnly = false; + sImport.m_sLoadData.m_sMultiEntries.m_bLoadDefault = false; + + A3DUTF8Char** ppMappedPartPaths = (A3DUTF8Char**)CheckMalloc(size_t(nbFiles) * sizeof(A3DUTF8Char*)); + struct Cleaner + { + size_t uNbFiles_; + A3DUTF8Char** ptr_; + + Cleaner(size_t uNbFiles, A3DUTF8Char** ptr) : + uNbFiles_(uNbFiles), + ptr_(ptr) + {} + + ~Cleaner() + { + Release(); + } + + void Release() + { + for (unsigned ui = 0; ui < uNbFiles_; ++ui) + CheckFree(ptr_[ui]); + CheckFree(ptr_); + uNbFiles_ = 0; + ptr_ = nullptr; + } + } sCleaner(nbFiles, ppMappedPartPaths); + + for (A3DUns32 i = 0; i < nbFiles; ++i) + { + A3DImport sSubImport(ppPaths[i]); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + iRet = sHoopsExchangeLoader.Import(sSubImport); + + A3DAsmModelFile* pCurrentModelFile = sHoopsExchangeLoader.m_psModelFile; + sHoopsExchangeLoader.m_psModelFile = NULL; + + if (iRet == A3D_LOAD_CANNOT_ACCESS_CADFILE || iRet == A3D_LOAD_INVALID_FILE_FORMAT) + { + ppMappedPartPaths[i] = (A3DUTF8Char*)CheckMalloc( 10* sizeof(A3DUTF8Char)); + strcpy(ppMappedPartPaths[i], "INVALID"); + continue; + } + + if (iRet == A3D_LOAD_MULTI_MODELS_CADFILE) //multi config!! + { + A3DAsmModelFileData sModelFileData; + A3D_INITIALIZE_DATA(A3DAsmModelFileData, sModelFileData); + A3DAsmModelFileGet(pCurrentModelFile, &sModelFileData); + A3DAsmProductOccurrence* pPO = sModelFileData.m_ppPOccurrences[0]; + + A3DAsmProductOccurrenceData sData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sData); + A3DAsmProductOccurrenceGet(pPO, &sData); + + for (A3DUns32 uiSonIndex = 0; uiSonIndex < sData.m_uiPOccurrencesSize; uiSonIndex++) + { + A3DImport sImportLocal(ppPaths[i]); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + + //connect the new read product occurrence with the current product occurrence + sImportLocal.m_sLoadData.m_sIncremental.m_uiProductOccurrencesSize = 1; + sImportLocal.m_sLoadData.m_sIncremental.m_ppProductOccurrences = &sData.m_ppPOccurrences[uiSonIndex]; + sImportLocal.m_sLoadData.m_sIncremental.m_pRootProductOccurrence = pPO; + + iRet = sHoopsExchangeLoader.Import(sImportLocal); + TEST_RET(iRet); + } + } + + const std::string strCurrentPRCName = strOutDir +#ifdef WIN32 + + "\\" +#else + + "/" +#endif + + ExtractFileName(ppPaths[i]) + ".prc"; + ppMappedPartPaths[i] = (A3DUTF8Char*)CheckMalloc((strCurrentPRCName.length() + 1) * sizeof(A3DUTF8Char)); + strcpy(ppMappedPartPaths[i], strCurrentPRCName.c_str()); + + A3DExport sSubExport(ppMappedPartPaths[i]); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + sHoopsExchangeLoader.m_psModelFile = pCurrentModelFile; + CHECK_RET(sHoopsExchangeLoader.Export(sSubExport)); + CHECK_RET(A3DAsmModelFileDelete(sHoopsExchangeLoader.m_psModelFile)); + sHoopsExchangeLoader.m_psModelFile = NULL; + } + + ////////////////////////////////////////////////////////////////////////// + // 7 - Rebuild part + ////////////////////////////////////////////////////////////////////////// + A3DAsmModelFile* pOutModelFile = NULL; + A3DRWParamsLoadData sRPartParam; + A3D_INITIALIZE_DATA(A3DRWParamsLoadData, sRPartParam); + sRPartParam.m_sGeneral.m_bReadSolids = true; + sRPartParam.m_sGeneral.m_bReadSurfaces = true; + sRPartParam.m_sGeneral.m_eReadGeomTessMode = kA3DReadGeomAndTess; + sRPartParam.m_sMultiEntries.m_bLoadDefault = true; + // sRPartParam.m_sMultiEntries.m_bLoadDefault = false; + // A3DUTF8Char* pcName = "Full";//"Chassis and Fuel Tank" + // sRPartParam.m_sMultiEntries.m_ppcEntries = &pcName; + // sRPartParam.m_sMultiEntries.m_uiEntriesSize = 1; + + CHECK_RET(A3DAsmModelFileLoadFromMultiplePrcFile(strOutMainFileName.c_str(), + nbFiles, + (const A3DUTF8Char**)ppPaths, + (const A3DUTF8Char**)ppMappedPartPaths, + &sRPartParam, + &pOutModelFile)); + + //////////////////////////////////////////////////////////////////////////// + // 8- Export final file + //////////////////////////////////////////////////////////////////////////// + A3DExport sFinalExport((strOutBaseFileName + "All.prc").c_str()); + sHoopsExchangeLoader.m_psModelFile = pOutModelFile; + CHECK_RET(sHoopsExchangeLoader.Export(sFinalExport)); + + CHECK_RET(A3DAsmGetFilesPathFromModelFile(NULL, &nbFiles, &ppPaths, &nbAssemblyFiles, &ppAssemblyPaths, + &nbMissingFiles, &ppMissingPaths)); + + sCleaner.Release(); + // + // ### TERMINATE HOOPS EXCHANGE + // + + // Check memory allocations + return (int)ListLeaks(); +} + +//###################################################################################################################### +// Recursively creates the folder path if it does not exist +// Returns true if the operation succeeds or if the folder already exists. False otherwise. + +#ifdef _MSC_VER +bool MakePath(const std::string& strPath) +{ + if (CreateDirectoryA(strPath.c_str(), 0) == 0) + { + return GetLastError() == ERROR_ALREADY_EXISTS; + } + return true; +} +#else +#include +#include +bool MakePath(const std::string& strPath) +{ + if (mkdir(strPath.c_str(), ACCESSPERMS) == -1) + { + if (errno == EEXIST) + { + return true; + } + return false; + } + return true; +} +#endif + + +//###################################################################################################################### +std::string ExtractPath(const A3DUTF8Char* pcIn) +{ + const std::string strIn(pcIn); + size_t lastSlash = strIn.rfind("/"); + if (lastSlash == std::string::npos) + lastSlash = strIn.rfind("\\"); + return strIn.substr(0, lastSlash + 1); +} + +//###################################################################################################################### +std::string ExtractFileName(const A3DUTF8Char* pcIn) +{ + const std::string strIn(pcIn); + size_t lastSlash = strIn.rfind("/"); + if (lastSlash == std::string::npos) + lastSlash = strIn.rfind("\\"); + return strIn.substr(lastSlash + 1); +} + +//###################################################################################################################### +A3DStatus TestOutputFile(const std::string& strFileName) +{ + if (FILE* pFile = fopen(strFileName.c_str(), "wb")) + { + fclose(pFile); + return A3D_SUCCESS; + } + else + { + fprintf(stderr, "cannot write output file %s\n", strFileName.c_str()); + return A3D_WRITE_INVALID_FILE_NAME; + } +} diff --git a/exchange/exchangesource/MultiplePRCFiles/MultiplePRCFiles.vcxproj b/exchange/exchangesource/MultiplePRCFiles/MultiplePRCFiles.vcxproj new file mode 100644 index 0000000..730c82a --- /dev/null +++ b/exchange/exchangesource/MultiplePRCFiles/MultiplePRCFiles.vcxproj @@ -0,0 +1,167 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {8B90DC19-E9AC-4D8C-A8E5-5190A986F9A0} + MultiplePRCFiles + Win32Proj + 10.0 + + + + Application + v145 + true + + + Application + v145 + + + Application + v145 + true + + + Application + v145 + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + ..\..\bin;%(AdditionalLibraryDirectories) + true + Console + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + MaxSpeed + true + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + Level4 + ProgramDatabase + false + + + true + Console + true + true + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + MaxSpeed + true + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + Level4 + ProgramDatabase + false + + + true + Console + true + true + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/MultiplePRCFiles/MultiplePRCFiles.vcxproj.filters b/exchange/exchangesource/MultiplePRCFiles/MultiplePRCFiles.vcxproj.filters new file mode 100644 index 0000000..f1b5572 --- /dev/null +++ b/exchange/exchangesource/MultiplePRCFiles/MultiplePRCFiles.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + Source Files + + + \ No newline at end of file diff --git a/exchange/exchangesource/MultiplePRCFiles/MultiplePRCRecurs.cpp b/exchange/exchangesource/MultiplePRCFiles/MultiplePRCRecurs.cpp new file mode 100644 index 0000000..4b45f64 --- /dev/null +++ b/exchange/exchangesource/MultiplePRCFiles/MultiplePRCRecurs.cpp @@ -0,0 +1,476 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file MultiplePrc.cpp + +This file demonstrates how to programmatically create and read multiple PRC files +from a CAD assembly using HOOPS Exchange. +The input is the CAD assembly file path and a directory. +The program generates multiple PRC files from this CAD assembly. + +This mode is supported for the following format: V4, V5, ProE, UG, SLDW. +With other formats, only one PRC file is generated. + +***********************************************************************************************************************/ + +#define _CRT_SECURE_NO_DEPRECATE 1 + +#include +#include +#include +#include +#include +#include + +#define INITIALIZE_A3D_API +#include +#include + + + +//###################################################################################################################### +A3DVoid A3DCheckFree(A3DPtr ptr) +{ + free(ptr); +} + +//###################################################################################################################### +A3DPtr A3DCheckMalloc(size_t uiToAlloc) +{ + return malloc(uiToAlloc); +} + +//###################################################################################################################### +#define CHECK_RET(function_call) {\ + iRet = function_call; if(iRet != A3D_SUCCESS) { std::cout << "Error number=" << iRet << std::endl; return iRet; }\ +} + +//###################################################################################################################### +std::string ExtractFileName(const A3DUTF8Char* pcIn) +{ + std::string strIn(pcIn); + int lastSlash = (int) strIn.rfind("/"); + if(lastSlash < 0) + lastSlash = (int) strIn.rfind("\\"); + std::string tmp = strIn.substr(size_t(lastSlash)+1); + return tmp; +} + +//###################################################################################################################### +std::string ExtractFilePath(const A3DUTF8Char* pcIn) +{ + std::string strIn(pcIn); + int lastSlash = (int) strIn.rfind("/"); + if(lastSlash < 0) + lastSlash = (int) strIn.rfind("\\"); + std::string tmp = strIn.substr(0,size_t(lastSlash)); + return tmp; +} + +//###################################################################################################################### +std::string ExtractRelativePath(const A3DUTF8Char* pcIn,const A3DUTF8Char* pcDirRoot) +{ + std::string strTotalPath = ExtractFilePath(pcIn); + std::string strRootPath(pcDirRoot); + + std::string strRelativePath; + size_t uiTotalPathSize = strTotalPath.size(); + size_t uiRootPathSize = strRootPath.size(); + if(uiTotalPathSize > uiRootPathSize) + { + strRelativePath = strTotalPath.substr(uiRootPathSize); + } + return strRelativePath; +} + +//###################################################################################################################### +bool DirExists(const std::string& dirName_in) +{ + DWORD ftyp = GetFileAttributesA(dirName_in.c_str()); + if (ftyp == INVALID_FILE_ATTRIBUTES) + return false; + + if (ftyp & FILE_ATTRIBUTE_DIRECTORY) + return true; + + return false; +} + +//###################################################################################################################### +std::string ExtractChoreFileName(std::string pcIn) +{ + std::string strIn(pcIn); + int lastPoint = (int) strIn.rfind("."); + std::string tmp = strIn.substr(0, size_t(lastPoint)); + return tmp; +} + +//###################################################################################################################### +int TreatFile(A3DSDKHOOPSExchangeLoader &sHoopsExchangeLoader, + A3DUTF8Char** ppMappedNativePaths, + A3DUTF8Char** ppMappedPRCPaths, + unsigned int &idxmap, + bool bIsAssembly, + char* acUTF8FileName, char* acUTF8InDir, char* acUTF8OutDir) +{ + int iRet; + std::string strMainFileName = acUTF8FileName; + + // --- REREAD the native file without dependencies + if(sHoopsExchangeLoader.m_psModelFile != NULL) + A3DAsmModelFileDelete(sHoopsExchangeLoader.m_psModelFile); + sHoopsExchangeLoader.m_psModelFile = NULL; + A3DImport sImport2(strMainFileName.c_str()); + sImport2.m_sLoadData.m_sIncremental.m_bLoadNoDependencies = true; + iRet = sHoopsExchangeLoader.Import(sImport2); + if(iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS && iRet != A3D_LOAD_MULTI_MODELS_CADFILE) + return iRet; + + // --- EXPORT as PRC + std::string strRelativePath = ExtractRelativePath(strMainFileName.c_str(), acUTF8InDir); + std::string strChorefilename = ExtractFileName(strMainFileName.c_str()); + std::string strOutMainFileName = acUTF8OutDir; + strOutMainFileName += strRelativePath; + + if( DirExists(strOutMainFileName) == false) + { +#ifdef _MSC_VER + _mkdir(strOutMainFileName.c_str()); +#else + mkdir(strOutMainFileName.c_str()); +#endif + } + + strOutMainFileName += "\\__"; + strOutMainFileName += strChorefilename; + strOutMainFileName += ".prc"; + A3DExport sExport(strOutMainFileName.c_str()); + CHECK_RET(sHoopsExchangeLoader.Export(sExport)); + + // update the map NATIVE-PRC + std::string strCurrentPRCName = strMainFileName; + strCurrentPRCName += ".prc"; + ppMappedNativePaths[idxmap] = (A3DUTF8Char*) A3DCheckMalloc(1024 * sizeof(A3DUTF8Char)); + strcpy(ppMappedNativePaths[idxmap], strMainFileName.c_str()); //acUTF8FileName if we don't want the path + ppMappedPRCPaths[idxmap] = (A3DUTF8Char*) A3DCheckMalloc(1024 * sizeof(A3DUTF8Char)); + strcpy(ppMappedPRCPaths[idxmap], strOutMainFileName.c_str()); //strCurrentPRCName.c_str()) if we don't want the path + idxmap++; + + CHECK_RET(A3DAsmModelFileDelete(sHoopsExchangeLoader.m_psModelFile)); + sHoopsExchangeLoader.m_psModelFile = NULL; + + return 0; +} + +//###################################################################################################################### +bool SortByExtensionInPath(const std::string& strExtensionAsm, + const std::string& strExtensionPrt, + const std::string& strTestingPath, + const std::string& strPath, + std::set& a_rsCollectedAsmFilesPath, + std::set& a_rsCollectedPartFilesPath) +{ + char sDrive[256]; + char sDir[256]; + char sFileName[256]; + char sExtension[256]; + _splitpath(strTestingPath.c_str(),sDrive,sDir,sFileName,sExtension); + + std::string szExtension(sExtension); + std::transform(szExtension.begin(), szExtension.end(), szExtension.begin(), ::tolower); + + size_t sAsm = szExtension.find(strExtensionAsm); + size_t sPrt = szExtension.find(strExtensionPrt); + if(sAsm == std::string::npos && sPrt == std::string::npos) + return false; + if(sAsm > sPrt) + a_rsCollectedAsmFilesPath.insert(strPath); + else + a_rsCollectedPartFilesPath.insert(strPath); + return true; +} + +bool SortFilePath(const A3DEModellerType& eType, const std::string& a_rsPath, + std::set& a_rsCollectedAsmFilesPath, + std::set& a_rsCollectedPartFilesPath) +{ + switch(eType) + { + case kA3DModellerProE: + { + std::string szRealPath = a_rsPath; + size_t iDotPos = a_rsPath.find_last_of('.'); + if(iDotPos != std::string::npos) + szRealPath.erase (szRealPath.begin()+iDotPos, szRealPath.end()); + + return SortByExtensionInPath("asm", "prt", szRealPath,a_rsPath,a_rsCollectedAsmFilesPath,a_rsCollectedPartFilesPath); + } + case kA3DModellerSlw: + return SortByExtensionInPath("sldasm", "sldprt",a_rsPath, a_rsPath,a_rsCollectedAsmFilesPath,a_rsCollectedPartFilesPath); + case kA3DModellerCatiaV5: + return SortByExtensionInPath("catproduct", "catpart", a_rsPath,a_rsPath,a_rsCollectedAsmFilesPath,a_rsCollectedPartFilesPath); + case kA3DModellerCatia: + return SortByExtensionInPath("session", "model", a_rsPath,a_rsPath,a_rsCollectedAsmFilesPath,a_rsCollectedPartFilesPath); + case kA3DModellerInventor: + return SortByExtensionInPath("iam", "ipt", a_rsPath,a_rsPath,a_rsCollectedAsmFilesPath,a_rsCollectedPartFilesPath); + case kA3DModellerSE: + return SortByExtensionInPath("asm", "par", a_rsPath,a_rsPath,a_rsCollectedAsmFilesPath,a_rsCollectedPartFilesPath); + default : return false; + } +} + +//###################################################################################################################### +A3DStatus GetAllFileDependenciesFromFilelist(A3DUTF8Char*& a_rpcFilelist, + std::set& a_rsCollectedAsmFilesPath, + std::set& a_rsCollectedPartFilesPath) +{ + std::ifstream oFile; + oFile.open(a_rpcFilelist); + + while (!oFile.eof()) + { + std::string szFilePath; + getline(oFile,szFilePath); + + A3DEModellerType eType; + A3DStatus iRet = A3DGetFileFormat(szFilePath.c_str(), &eType); + if(iRet != A3D_SUCCESS) + return iRet; + + if(!SortFilePath(eType,szFilePath,a_rsCollectedAsmFilesPath, a_rsCollectedPartFilesPath)) + return A3D_LOAD_MISSING_COMPONENTS; + } + + oFile.close(); + + return A3D_SUCCESS; +} + +//###################################################################################################################### +A3DStatus GetAllFileDependencies(std::string& a_rszCurFile, + A3DSDKHOOPSExchangeLoader& a_rsHoopsExchangeLoader, + std::set& a_rsCollectedAsmFilesPath, + std::set& a_rsCollectedPartFilesPath) +{ + // Load file + A3DImport sImport(a_rszCurFile.c_str()); + sImport.m_sLoadData.m_sIncremental.m_bLoadNoDependencies = true; + A3DStatus iRet = a_rsHoopsExchangeLoader.Import(sImport); + if(iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS && iRet != A3D_LOAD_MULTI_MODELS_CADFILE) + return iRet; + + // Extract sub-file names + A3DUns32 i = 0; + A3DUns32 nbPartFiles = 0; + A3DUTF8Char** ppPartPaths = NULL; + A3DUns32 nbAssemblyFiles = 0; + A3DUTF8Char** ppAssemblyPaths = NULL; + A3DUns32 uNbMissingFiles = 0; + A3DUTF8Char** ppMissingFilesPaths = NULL; + CHECK_RET(A3DAsmGetFilesPathFromModelFile(a_rsHoopsExchangeLoader.m_psModelFile, &nbPartFiles, &ppPartPaths, &nbAssemblyFiles, &ppAssemblyPaths, &uNbMissingFiles, &ppMissingFilesPaths)); + for(i = 0; i < nbAssemblyFiles; i ++) + { + a_rsCollectedAsmFilesPath.insert(ppAssemblyPaths[i]); + } + for(i = 0; i < nbPartFiles; i ++) + { + a_rsCollectedPartFilesPath.insert(ppPartPaths[i]); + a_rsCollectedAsmFilesPath.erase(ppPartPaths[i]); + } + + // Free model file + if(a_rsHoopsExchangeLoader.m_psModelFile != NULL) + { + A3DAsmModelFileDelete(a_rsHoopsExchangeLoader.m_psModelFile); + a_rsHoopsExchangeLoader.m_psModelFile = NULL; + } + + // Load Sub assembly files + for(i = 0; i < nbAssemblyFiles; i ++) + { + std::string szSubFileName(ppAssemblyPaths[i]); + if(szSubFileName != a_rszCurFile) + { + GetAllFileDependencies(szSubFileName, a_rsHoopsExchangeLoader, a_rsCollectedAsmFilesPath, a_rsCollectedPartFilesPath); + } + } + + // Free filenames intermediate storage + CHECK_RET(A3DAsmGetFilesPathFromModelFile(NULL, &nbPartFiles, &ppPartPaths, &nbAssemblyFiles, &ppAssemblyPaths, &uNbMissingFiles, &ppMissingFilesPaths)); + + return A3D_SUCCESS; +} + +//###################################################################################################################### +// Main function +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv) +#else +int main(int iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + if(iArgc != 4 && iArgc != 5) + { +#ifdef _MSC_VER + _tprintf(_T("Usage:\n %s \n"), ppcArgv[0]); +#else + printf("Usage:\n %s \n", ppcArgv[0]); +#endif + return A3D_ERROR; + } + + ///////////////////////////////////////////// + // 1- Initialize HOOPS Exchange. + ///////////////////////////////////////////// +#ifdef _MSC_VER +# ifdef _WIN64 + const TCHAR* pcLibPath = _T("..\\..\\..\\..\\bin\\win64\\"); +# else + const TCHAR* pcLibPath = _T("..\\..\\..\\..\\bin\\win32\\"); +# endif + A3DUTF8Char acUTF8FileName[MAX_PATH*4]; + A3DUTF8Char acUTF8InDir[MAX_PATH*4]; + A3DUTF8Char acUTF8OutDir[MAX_PATH*4]; + A3DUTF8Char* acUTF8FileList = NULL; +#else +# ifdef X32 + const A3DUTF8Char* pcLibPath = "../../../../bin/linux32"; +# else + const A3DUTF8Char* pcLibPath = "../../../../bin/linux64"; +# endif + A3DUTF8Char* acUTF8FileName = ppcArgv[1]; + A3DUTF8Char* acUTF8InDir = ppcArgv[2]; + A3DUTF8Char* acUTF8OutDir = ppcArgv[3]; + A3DUTF8Char* acUTF8FileList = ppcArgv[4]; +#endif + + A3DInt32 iRet = A3D_SUCCESS; + + A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(pcLibPath); + if (sHoopsExchangeLoader.m_eSDKStatus!=A3D_SUCCESS) + return sHoopsExchangeLoader.m_eSDKStatus; + +#ifdef _MSC_VER + A3DMiscUnicodeToUTF8((A3DUTF8Char*) ppcArgv[1], acUTF8FileName); + A3DMiscUnicodeToUTF8((A3DUTF8Char*) ppcArgv[2], acUTF8InDir); + A3DMiscUnicodeToUTF8((A3DUTF8Char*) ppcArgv[3], acUTF8OutDir); + if(ppcArgv[4]) + { + acUTF8FileList = new A3DUTF8Char[MAX_PATH*4]; + A3DMiscUnicodeToUTF8((A3DUTF8Char*) ppcArgv[4], acUTF8FileList); + } +#endif + + std::string strMainFileName = ExtractFileName(acUTF8FileName); + std::string strInMainFileName = acUTF8FileName; + + // init map NATIVE-PRC + const int MAXFILES = 100; + A3DUTF8Char** ppMappedNativePaths = (A3DUTF8Char**) A3DCheckMalloc(MAXFILES * sizeof(A3DUTF8Char*)); + A3DUTF8Char** ppMappedPRCPaths = (A3DUTF8Char**) A3DCheckMalloc(MAXFILES * sizeof(A3DUTF8Char*)); + unsigned int idxmap = 0; + + //////////////////////////////////////////////////////////////////////////// + // load the model and get the list of files + //////////////////////////////////////////////////////////////////////////// + + // --- EXTRACT file names for sons + std::set sAsmFilesPath; + std::set sPartFilesPath; + if(acUTF8FileList) + { + iRet = GetAllFileDependenciesFromFilelist(acUTF8FileList, sAsmFilesPath, sPartFilesPath); + if(iRet != A3D_SUCCESS) + return iRet; + } + else + { + iRet = GetAllFileDependencies(strInMainFileName, sHoopsExchangeLoader, sAsmFilesPath, sPartFilesPath); + if(iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS && iRet != A3D_LOAD_MULTI_MODELS_CADFILE) + return iRet; + } + + //////////////////////////////////////////////////////////////////////////// + // 1- build a PRC for each component in the assembly, + // and update the map NATIVE-PRC + //////////////////////////////////////////////////////////////////////////// + + // 1-a Roots + if(sAsmFilesPath.find(acUTF8FileName) == sAsmFilesPath.end()) // add root file if it's not already registered in sAsmFilesPath + { + TreatFile(sHoopsExchangeLoader,ppMappedNativePaths,ppMappedPRCPaths,idxmap , + true, acUTF8FileName, acUTF8InDir, acUTF8OutDir); + } + + //1-b Assemblies + std::set::iterator itAsmPathCur = sAsmFilesPath.begin(); + std::set::iterator itAsmPathEnd = sAsmFilesPath.end(); + for(; itAsmPathCur != itAsmPathEnd; itAsmPathCur++) + { + TreatFile(sHoopsExchangeLoader,ppMappedNativePaths,ppMappedPRCPaths,idxmap , + true, (char*) (*itAsmPathCur).c_str(), acUTF8InDir, acUTF8OutDir); + } + + //1-c Part + std::set::iterator itPartPathCur = sPartFilesPath.begin(); + std::set::iterator itPartPathEnd = sPartFilesPath.end(); + for(; itPartPathCur != itPartPathEnd; itPartPathCur++) + { + TreatFile(sHoopsExchangeLoader,ppMappedNativePaths,ppMappedPRCPaths,idxmap , + false, (char*) (*itPartPathCur).c_str(), acUTF8InDir, acUTF8OutDir); + } + + //////////////////////////////////////////////////////////////////////////// + // 2- now simulate an assembly reconstruction starting from the root file with all PRC chunks + //////////////////////////////////////////////////////////////////////////// + std::string strOutMainFileName = acUTF8OutDir; + strOutMainFileName += "\\__"; + strOutMainFileName += strMainFileName; + strOutMainFileName += ".prc"; + + A3DAsmModelFile* pOutModelFile = NULL; + A3DRWParamsLoadData sRPartParam; + A3D_INITIALIZE_DATA(A3DRWParamsLoadData, sRPartParam); + sRPartParam.m_sGeneral.m_bReadSolids = true; + sRPartParam.m_sGeneral.m_bReadSurfaces = true; + sRPartParam.m_sGeneral.m_bReadWireframes = true; + sRPartParam.m_sGeneral.m_eReadGeomTessMode = kA3DReadGeomAndTess; + sRPartParam.m_sGeneral.m_bReadHiddenObjects = true; + //sRPartParam.m_sMultiEntries.m_bLoadDefault = true; + + CHECK_RET(A3DAsmModelFileLoadFromPRCFiles( + strOutMainFileName.c_str(), + idxmap, + (const A3DUTF8Char**)ppMappedPRCPaths, + (const A3DUTF8Char**)ppMappedNativePaths, + &sRPartParam, + &pOutModelFile)); + + // --- Export the rebuilt assembly to test the result + std::string strOut = acUTF8OutDir; + strOut += "\\__"; + strOut += strMainFileName; + strOut += "AllLoaded.prc"; + A3DExport sFinalExport(strOut.c_str()); + sHoopsExchangeLoader.m_psModelFile = pOutModelFile; + CHECK_RET(sHoopsExchangeLoader.Export(sFinalExport)); + + for(unsigned ui = 0; ui < idxmap; ++ui) + { + A3DCheckFree(ppMappedPRCPaths[ui]); + } + A3DCheckFree(ppMappedPRCPaths); + + delete acUTF8FileList; + acUTF8FileList = NULL; + + return A3D_SUCCESS; +} diff --git a/exchange/exchangesource/NetWrapper/AssemblyInfo.cpp b/exchange/exchangesource/NetWrapper/AssemblyInfo.cpp new file mode 100644 index 0000000..cc46309 --- /dev/null +++ b/exchange/exchangesource/NetWrapper/AssemblyInfo.cpp @@ -0,0 +1,49 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("TechSoft3DExchangeNetWrapper")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("Tech Soft 3D")]; +[assembly:AssemblyProductAttribute("TechSoft3DExchangeNetWrapper")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc.")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("5.2.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + diff --git a/exchange/exchangesource/NetWrapper/ConsoleApplication.csproj b/exchange/exchangesource/NetWrapper/ConsoleApplication.csproj new file mode 100644 index 0000000..59c1d20 --- /dev/null +++ b/exchange/exchangesource/NetWrapper/ConsoleApplication.csproj @@ -0,0 +1,138 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {765D5D20-2470-4597-93CD-25A7E118814D} + Exe + Properties + ConsoleApplication + ConsoleApplication + v4.0 + 512 + + + + + 3.5 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + Win32\Debug\ + DEBUG;TRACE + full + x86 + true + GlobalSuppressions.cs + prompt + + + Win32\Release\ + TRACE + true + pdbonly + x86 + true + GlobalSuppressions.cs + prompt + + + true + x64\Debug\ + DEBUG;TRACE + full + x64 + true + GlobalSuppressions.cs + prompt + + + x64\Release\ + TRACE + true + pdbonly + x64 + true + GlobalSuppressions.cs + prompt + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + + + + + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + true + + + + + {2e7e13b4-0ac4-480f-901f-024cf1938308} + TechSoft3D.Exchange.NetWrapper + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/NetWrapper/ConsoleApplication/Program.cs b/exchange/exchangesource/NetWrapper/ConsoleApplication/Program.cs new file mode 100644 index 0000000..66b1450 --- /dev/null +++ b/exchange/exchangesource/NetWrapper/ConsoleApplication/Program.cs @@ -0,0 +1,196 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Diagnostics; + + +using TechSoft3D.HOOPS; + +namespace ConsoleApplication +{ + class Program + { + static Exchange m_pExchange; + + static string m_pcFileName; + static int m_iProgressBareSize; + static int m_iStart; + + //############################################################################################################## + static void stFCTStart(int i) + { + m_iStart = i; + switch (i) + { + case 1: + { + Console.WriteLine("Start Parsing File: {0}", m_pcFileName); + break; + } + case 2: + { + + Console.WriteLine("Start Writing to Parasolid"); + break; + } + case 3: + { + // m_pExchange.Break(); + Console.WriteLine("Start Reading File {0}", m_pcFileName); + break; + } + default: + break; + } + } + + //############################################################################################################## + static void stFCTitle(string str) + { + m_pcFileName = str; + } + + //############################################################################################################## + static void stFCTSize(int i) + { + m_iProgressBareSize = i; + } + + //############################################################################################################## + static void stFCTIncr(int i) + { + if (m_iProgressBareSize != 0) + { + int iPercentage = (int)(i * 100 / (double)m_iProgressBareSize); + Console.WriteLine("Progress: {0} % ", iPercentage); + } + } + + //############################################################################################################## + static void stFCTEnd() + { + Console.WriteLine("Progress: 100/% "); + m_iProgressBareSize = 0; + + } + + static int stFCTReportMessage(string Msg) + { + Console.Write(Msg); + return 1; + } + + static int stFCTkReportWarning(string Code,string Msg) + { + Console.Write("WARNING " + Code + " " + Msg); + return 1; + } + + static int stFCTReportError(string Code,string Msg) + { + Console.Write("ERROR " + Code + " " + Msg); + return 1; + } + + //############################################################################################################## + static bool stTranslate(string InputCADFile, string OutputXTFile, string LogFile, bool bWriteBlankedEntities) + { + if (m_pExchange == null) + { + m_pExchange = new Exchange(); + + if (!m_pExchange.Init()) + { + Console.WriteLine("Cannot initialize HOOPS Exchange"); + return false; + } + + if (LogFile.Length > 0) + m_pExchange.SetLogFile(LogFile); + + Exchange.CallbackStart pStart = new Exchange.CallbackStart(stFCTStart); + Exchange.CallbackTitle pTitle = new Exchange.CallbackTitle(stFCTitle); + Exchange.CallbackIncrement pIncr = new Exchange.CallbackIncrement(stFCTIncr); + Exchange.CallbackSize pSize = new Exchange.CallbackSize(stFCTSize); + Exchange.CallbackEnd pEnd = new Exchange.CallbackEnd(stFCTEnd); + + Exchange.CallbackReportMessage pMessage = new Exchange.CallbackReportMessage(stFCTReportMessage); + Exchange.CallbackReportWarning pWarning = new Exchange.CallbackReportWarning(stFCTkReportWarning); + Exchange.CallbackReportError pError = new Exchange.CallbackReportError(stFCTReportError); + + m_pExchange.SetCallBackFct(pStart, pTitle, pSize, pIncr, pEnd); + m_pExchange.SetCallBackMessageFct(pMessage, pWarning, pError); + } + + IDictionary sOptions = new Dictionary(); + sOptions.Add("WriteBlankedEntities", bWriteBlankedEntities ? "true" : "false"); + + sOptions.Add("General.ReadSolids", "true"); + sOptions.Add("General.ReadSurfaces", "false"); + sOptions.Add("General.ReadWireframes", "false"); + + //sOptions.Add("General.ReadAttributes", "false"); + //sOptions.Add("General.ReadConstructionAndReferences", "true"); + //sOptions.Add("General.ReadActiveFilter", "true"); + //sOptions.Add("Assembly.UseRootDirectory", "true"); + //sOptions.Add("Assembly.RootDirRecursive", "true"); + //sOptions.Add("Assembly.SearchDir[0].PhysicalPath", "C:\\temp\\"); + //sOptions.Add("Assembly.SearchDir[0].Recursive", "C:\\temp\\"); + //sOptions.Add("Assembly.SearchDir[1].PhysicalPath", "C:\\temp2\\"); + //sOptions.Add("Assembly.SearchDir[1].Recursive", "true"); + + //sOptions.Add("Specifics.CatiaV4.RootDirLogicalName", "LogicalNameSample"); + //sOptions.Add("Specifics.CatiaV4.AllowSearchInOtherLogicalNames", "true"); + + bool bIsProEFile = m_pExchange.IsProEFile(InputCADFile); + //m_pExchange.SetUnit(1.0); means mm + m_pcFileName = InputCADFile; + m_iProgressBareSize = 0; + if (!m_pExchange.ConvertToXT(InputCADFile, OutputXTFile, sOptions)) + { + Console.WriteLine("ConvertToXT failure"); + return false; + } + return true; + } + + //############################################################################################################## + static void Main(string[] args) + { + if (args.Length < 2) + { + String thismodulefilenamestr = System.IO.Path.GetFullPath(System.Reflection.Assembly.GetEntryAssembly().Location); + Console.Write("\nUsage:\n " + thismodulefilenamestr + " [-LogFile logfile] [-WriteBlankedEntities]\n"); + } + else + { + bool bWriteBlankedEntities = false; + string LogFile = ""; + int iArg; + for (iArg = 0; iArg < args.Length; iArg++) + { + if (args[iArg] == "-WriteBlankedEntities") + bWriteBlankedEntities = true; + if (args[iArg] == "-LogFile") + LogFile = args[iArg + 1]; + } + if (stTranslate(args[0], args[1], LogFile, bWriteBlankedEntities)) + Console.Write(args[1] + " has been created.\n"); + else + Console.Write("Error: " + args[1] + " was not created.\n"); + } + } + } +} diff --git a/exchange/exchangesource/NetWrapper/ConsoleApplication/Properties/AssemblyInfo.cs b/exchange/exchangesource/NetWrapper/ConsoleApplication/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c7a8dfd --- /dev/null +++ b/exchange/exchangesource/NetWrapper/ConsoleApplication/Properties/AssemblyInfo.cs @@ -0,0 +1,48 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ConsoleApplication")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Tech Soft 3D")] +[assembly: AssemblyProduct("ConsoleApplication")] +[assembly: AssemblyCopyright("Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc.")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("fb882bdf-689e-498c-9251-5b27e5c06a53")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/exchange/exchangesource/NetWrapper/TechSoft3D.Exchange.NetWrapper.vcxproj b/exchange/exchangesource/NetWrapper/TechSoft3D.Exchange.NetWrapper.vcxproj new file mode 100644 index 0000000..5a5238a --- /dev/null +++ b/exchange/exchangesource/NetWrapper/TechSoft3D.Exchange.NetWrapper.vcxproj @@ -0,0 +1,167 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {2E7E13B4-0AC4-480F-901F-024CF1938308} + TechSoft3DExchangeNetWrapper + ManagedCProj + 10.0 + + + + DynamicLibrary + v145 + true + true + + + DynamicLibrary + v145 + true + + + DynamicLibrary + v145 + true + true + + + DynamicLibrary + v145 + true + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;%(PreprocessorDefinitions) + MultiThreadedDebugDLL + Level4 + ProgramDatabase + false + + + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + true + true + MachineX86 + + + + + X64 + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;%(PreprocessorDefinitions) + MultiThreadedDebugDLL + Level4 + ProgramDatabase + + + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + true + true + MachineX64 + + + + + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;%(PreprocessorDefinitions) + MultiThreadedDLL + true + Level4 + ProgramDatabase + false + + + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + false + MachineX86 + + + + + X64 + + + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;%(PreprocessorDefinitions) + MultiThreadedDLL + true + Level4 + ProgramDatabase + + + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + false + MachineX64 + + + + + true + true + + + true + true + + + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/NetWrapper/TechSoft3D.Exchange.NetWrapper.vcxproj.filters b/exchange/exchangesource/NetWrapper/TechSoft3D.Exchange.NetWrapper.vcxproj.filters new file mode 100644 index 0000000..33e35f7 --- /dev/null +++ b/exchange/exchangesource/NetWrapper/TechSoft3D.Exchange.NetWrapper.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + Source Files + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/exchange/exchangesource/NetWrapper/Translation.cpp b/exchange/exchangesource/NetWrapper/Translation.cpp new file mode 100644 index 0000000..83ecadb --- /dev/null +++ b/exchange/exchangesource/NetWrapper/Translation.cpp @@ -0,0 +1,583 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/* +This sample demonstrates how to use HOOPS Exchange with a .NET wrapper by converting any CAD file to XT. + +***********************************************************************************************************************/ + +#pragma warning(disable: 4505) // "unreferenced local function has been removed" + +#include + +#define INITIALIZE_A3D_API +#include +#include + +#include "Translation.h" + +using namespace System; +using namespace System::Collections::Generic; +using namespace System::Text; +using namespace System::Runtime::InteropServices; + + +// If you're seeing three CS0246 errors right below (concerning unknown namespaces), +// coupled with a few dozens of MSB3258 and MSB3274 warnings in the ConsoleApplication project, +// it's because of a known Visual Studio bug happening when using more recent versions than Visual Studio 2008. +// To properly compile, simply go to the Properties of ConsoleApplication, and in the Application tab, +// select Target Framework and choose ".NET Framework 4.0". +namespace TechSoft3D +{ + namespace HOOPS + { + static bool stBreakTranslation = false; +#define CHECK_CANCEL_OPERATION if(stBreakTranslation) { \ + throw (gcnew System::OperationCanceledException()); } \ + + //############################################################################################################## + char* ConvertString(String^ text) + { + array ^chars = Encoding::ASCII->GetBytes(text); + pin_ptr charsPointer = &(chars[0]); + char *nativeCharsPointer = reinterpret_cast(static_cast(charsPointer)); + std::string ret(nativeCharsPointer, chars->Length); + return _strdup(ret.c_str()); + } + + //############################################################################################################## + bool ConvertString(A3DUTF8Char* pTextUTF8, String^% sUnicode) + { + TCHAR pcUnicode[256]; + A3DMiscUTF8ToUTF16(pTextUTF8, pcUnicode); + StringBuilder^ buf = gcnew StringBuilder(256); + //UTF8Encoding^ utf8 = gcnew UTF8Encoding(); + size_t i, iCharCount = _tcslen(pcUnicode); + + for(i = 0; i < iCharCount; ++i) + buf->Insert(int(i), pcUnicode[i]); + + sUnicode = buf->ToString(); + + return true; + } + + //############################################################################################################## + static A3DInt32 stbreak = 0; + static bool stbA3DLoaded = false; + static FILE* stOut = stdout; + static int stiSize = 0; + + //############################################################################################################## + A3DInt32 ReportMessage(A3DUTF8Char* pMsg) + { + CHECK_CANCEL_OPERATION; + String^ sMsg; + if (Exchange::stm_pFctReportMessage && ConvertString(pMsg, sMsg)) + Exchange::stm_pFctReportMessage(sMsg); + if (stOut) + return fprintf(stOut, "%s", pMsg); + return 0; + } + + //############################################################################################################## + A3DInt32 ReportWarning(A3DUTF8Char* pCode, A3DUTF8Char* pMsg) + { + CHECK_CANCEL_OPERATION; + String^ sMsg; + String^ sCode; + if (Exchange::stm_pFctReportWarning && ConvertString(pCode, sCode) && ConvertString(pMsg, sMsg)) + Exchange::stm_pFctReportWarning(sCode, sMsg); + if (stOut) + return fprintf(stOut, "WARNING(%pCode) %s", pCode, pMsg); + else + return 0; + } + + //############################################################################################################## + A3DInt32 ReportError(A3DUTF8Char* pCode, A3DUTF8Char* pMsg) + { + CHECK_CANCEL_OPERATION; + String^ sMsg; + String^ sCode; + if (Exchange::stm_pFctReportError && ConvertString(pCode, sCode)&& ConvertString(pMsg, sMsg)) + Exchange::stm_pFctReportError(sCode,sMsg); + if (stOut) + return fprintf(stOut, "ERROR(%pCode) %s", pCode, pMsg); + else + return 0; + } + + //############################################################################################################## + void stStartPrg(A3DInt32 i) + { + CHECK_CANCEL_OPERATION; + if(Exchange::stm_pFCTStart) + Exchange::stm_pFCTStart(i); + } + + //############################################################################################################## + void stTitlePrg(A3DUTF8Char* pChar) + { + CHECK_CANCEL_OPERATION; + String^ sTitle; + if(Exchange::stm_pFCTTitle && ConvertString(pChar, sTitle)) + Exchange::stm_pFCTTitle(sTitle); + } + + //############################################################################################################## + void stSizePrg(A3DInt32 i) + { + CHECK_CANCEL_OPERATION; + stiSize = i; + if(Exchange::stm_pFCTSize) + Exchange::stm_pFCTSize(i); + } + + //############################################################################################################## + void stIncPrg(A3DInt32 i) + { + CHECK_CANCEL_OPERATION; + if (i > stiSize) + i = stiSize; + if (Exchange::stm_pFCTIncr) + Exchange::stm_pFCTIncr(i); + } + + //############################################################################################################## + void stEndPrg() + { + CHECK_CANCEL_OPERATION; + stIncPrg(stiSize); + if(Exchange::stm_pFCTEnd) + Exchange::stm_pFCTEnd(); + } + + //############################################################################################################## + A3DStatus ScaleProductOccurence(A3DAsmProductOccurrence* pPOccurrences, double dScale) + { + // accessing the ProductOccurence transformation: + A3DAsmProductOccurrenceData sPOccurrencesData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sPOccurrencesData); + A3DAsmProductOccurrenceGet(pPOccurrences, &sPOccurrencesData); + A3DStatus iRet = A3D_SUCCESS; + if(!sPOccurrencesData.m_pLocation) + { + A3DMiscGeneralTransformationData sData; + A3D_INITIALIZE_DATA(A3DMiscGeneralTransformationData, sData); + sData.m_adCoeff[0] = dScale; + sData.m_adCoeff[5] = dScale; + sData.m_adCoeff[10] = dScale; + sData.m_adCoeff[15] = 1.0; + A3DMiscCartesianTransformation* pNewScaledTransfo; + iRet = A3DMiscGeneralTransformationCreate(&sData,&pNewScaledTransfo); + sPOccurrencesData.m_pLocation = pNewScaledTransfo; + iRet = A3DAsmProductOccurrenceEdit(&sPOccurrencesData, pPOccurrences); + A3DAsmProductOccurrenceGet(NULL, &sPOccurrencesData); + return iRet; + } + + A3DEEntityType eType = kA3DTypeUnknown; + A3DEntityGetType(sPOccurrencesData.m_pLocation, &eType); + + // Two types of transformation exist in HOOPS Exchange: CartesianTransformation and GeneralTransformation + switch (eType) + { + case kA3DTypeMiscCartesianTransformation : + { + // getting the original transformation + A3DMiscCartesianTransformationData sData; + A3D_INITIALIZE_DATA(A3DMiscCartesianTransformationData, sData); + iRet = A3DMiscCartesianTransformationGet(sPOccurrencesData.m_pLocation, &sData); + if(iRet != A3D_SUCCESS) + return iRet; + + // creating a new scaled CartesianTransformation from the existing one + sData.m_sScale.m_dX *= dScale; + sData.m_sScale.m_dY *= dScale; + sData.m_sScale.m_dZ *= dScale; + A3DMiscCartesianTransformation* pNewScaledTransfo; + iRet = A3DMiscCartesianTransformationCreate(&sData, &pNewScaledTransfo); + if(iRet!= A3D_SUCCESS) + return iRet; + iRet = A3DMiscCartesianTransformationGet(NULL, &sData); + if(iRet!= A3D_SUCCESS) + return iRet; + sPOccurrencesData.m_pLocation = pNewScaledTransfo; + } + break; + + case kA3DTypeMiscGeneralTransformation : + { + // getting the original transformation + A3DMiscGeneralTransformationData sData; + A3D_INITIALIZE_DATA(A3DMiscGeneralTransformationData, sData); + iRet = A3DMiscGeneralTransformationGet(sPOccurrencesData.m_pLocation, &sData); + if(iRet != A3D_SUCCESS) + return iRet; + + // creating a new scaled CartesianTransformation from the existing one + sData.m_adCoeff[0] *= dScale; + sData.m_adCoeff[1] *= dScale; + sData.m_adCoeff[2] *= dScale; + sData.m_adCoeff[4] *= dScale; + sData.m_adCoeff[5] *= dScale; + sData.m_adCoeff[6] *= dScale; + sData.m_adCoeff[8] *= dScale; + sData.m_adCoeff[9] *= dScale; + sData.m_adCoeff[10] *= dScale; + + A3DMiscGeneralTransformation* pNewGeneralTransfo; + iRet = A3DMiscGeneralTransformationCreate(&sData, &pNewGeneralTransfo); + if( iRet!= A3D_SUCCESS) + return iRet; + iRet = A3DMiscGeneralTransformationGet(NULL, &sData); + if( iRet!= A3D_SUCCESS) + return iRet; + sPOccurrencesData.m_pLocation = pNewGeneralTransfo; + } + break; + + default : + return A3D_ERROR; + } + iRet = A3DAsmProductOccurrenceEdit(&sPOccurrencesData, pPOccurrences); + A3DAsmProductOccurrenceGet(NULL, &sPOccurrencesData); + return A3D_SUCCESS; + } + + //############################################################################################################## + bool Exchange::Init() + { +# ifdef _WIN64 + const TCHAR* pcLibPath = _T("..\\..\\..\\..\\..\\..\\bin\\win64_v142\\"); +# else + const TCHAR* pcLibPath = _T("..\\..\\..\\..\\..\\..\\bin\\win32_v142\\"); +# endif + + if(!A3DSDKLoadLibrary(pcLibPath)) + { + printf("Cannot load the HOOPS Exchange library\n"); + return false; + } + + A3DLicPutUnifiedLicense(HOOPS_LICENSE); + A3DInt32 iMajorVersion = 0, iMinorVersion = 0; + A3DDllGetVersion(&iMajorVersion, &iMinorVersion); + if(A3DDllInitialize(A3D_DLL_MAJORVERSION, A3D_DLL_MINORVERSION) != A3D_SUCCESS) + { + printf("Cannot initialize the HOOPS Exchange library\n"); + A3DSDKUnloadLibrary(); + return false; + } + + stbA3DLoaded = true; + stbreak = 0; + A3DDllSetCallbacksProgress(stStartPrg, stSizePrg, stIncPrg, stEndPrg, stTitlePrg, &stbreak); + A3DDllSetCallbacksReport(ReportMessage, ReportWarning, ReportError); + + return true; + } + + //############################################################################################################## + void Exchange::SetLogFile(String^ LogFileName) + { + if(stOut && stOut != stdout) + fclose(stOut); + if(fopen_s(&stOut, ConvertString(LogFileName), "w") != 0) + stOut = stdout; + } + + //############################################################################################################## + void Exchange::SetUnit(double dUnit) + { + m_dUnit = dUnit; + } + + //############################################################################################################## + bool Exchange::IsProEFile(String^ FileName) + { + A3DEModellerType sModellerType; + A3DGetFileFormat(ConvertString(FileName),&sModellerType); + return (sModellerType == kA3DModellerProE); + } + + //############################################################################################################## + void Exchange::SetLoadParametersOptions(A3DRWParamsLoadData & sLoadParametersData, IDictionary^ sOptions) + { +#define MACRO_SET_CAT_OPTION_BOOL(CAT,KEY) \ + { \ + String^ sKey = #CAT+"."+#KEY; \ + if(kvp.Key == sKey && kvp.Value == "true") \ + sLoadParametersData.m_s##CAT.m_b##KEY = true; \ + } +#define MACRO_SET_SUBCAT_OPTION_BOOL(CAT,SUBCAT,KEY) \ + { \ + String^ sKey = #CAT+"."+#SUBCAT+"."+#KEY; \ + if(kvp.Key == sKey && kvp.Value == "true") \ + sLoadParametersData.m_s##CAT.m_s##SUBCAT.m_b##KEY = true; \ + } + +#define MACRO_SET_SUBCAT_OPTION_STRING(CAT,SUBCAT,KEY) \ + { \ + String^ sKey = #CAT+"."+#SUBCAT+"."+#KEY; \ + if(kvp.Key == sKey) \ + sLoadParametersData.m_s##CAT.m_s##SUBCAT.m_pc##KEY = ConvertString(kvp.Value); \ + } + + for each(KeyValuePair kvp in sOptions) + { + MACRO_SET_CAT_OPTION_BOOL(General, ReadSolids); + MACRO_SET_CAT_OPTION_BOOL(General, ReadSurfaces); + MACRO_SET_CAT_OPTION_BOOL(General, ReadWireframes); + MACRO_SET_CAT_OPTION_BOOL(General, ReadConstructionAndReferences); + MACRO_SET_CAT_OPTION_BOOL(General, ReadActiveFilter); + MACRO_SET_CAT_OPTION_BOOL(General, ReadAttributes); + + MACRO_SET_CAT_OPTION_BOOL(Assembly, UseRootDirectory); + MACRO_SET_CAT_OPTION_BOOL(Assembly, RootDirRecursive); + + MACRO_SET_SUBCAT_OPTION_BOOL(Specifics, IGES, SewBrepModels); + + MACRO_SET_SUBCAT_OPTION_STRING(Specifics, CatiaV4, RootDirLogicalName); + MACRO_SET_SUBCAT_OPTION_BOOL(Specifics, CatiaV4, AllowSearchInOtherLogicalNames); + + MACRO_SET_SUBCAT_OPTION_BOOL(Specifics, Step, PreferProductName); + MACRO_SET_SUBCAT_OPTION_BOOL(Specifics, Step, PreferFirstColor); + + + if(kvp.Key->Contains("SearchDir") && kvp.Key->Contains("PhysicalPath")) + { + String^ Indice = kvp.Key; + array^chars = {'[',']'}; + array^aIndice = Indice->Split( chars ); + int myInt = System::Convert::ToInt32(aIndice[1]); + unsigned int uSize = sLoadParametersData.m_sAssembly.m_uiSearchDirectoriesSize; + if(uSize == 0) + { + sLoadParametersData.m_sAssembly.m_ppcSearchDirectories = + (A3DRWParamsSearchDirData**) malloc(sizeof(A3DRWParamsSearchDirData*)*(myInt + 1)); + sLoadParametersData.m_sAssembly.m_uiSearchDirectoriesSize = myInt + 1; + sLoadParametersData.m_sAssembly.m_ppcSearchDirectories[0] = NULL; + } + else if((unsigned) myInt >= uSize) + { + sLoadParametersData.m_sAssembly.m_ppcSearchDirectories = + (A3DRWParamsSearchDirData**) realloc(sLoadParametersData.m_sAssembly.m_ppcSearchDirectories, + sizeof(A3DRWParamsSearchDirData*) * (myInt + 1)); + sLoadParametersData.m_sAssembly.m_uiSearchDirectoriesSize = myInt + 1; + sLoadParametersData.m_sAssembly.m_ppcSearchDirectories[myInt] = NULL; + } + if(sLoadParametersData.m_sAssembly.m_ppcSearchDirectories[myInt] == NULL) + { + sLoadParametersData.m_sAssembly.m_ppcSearchDirectories[myInt] = + (A3DRWParamsSearchDirData*) malloc(sizeof(A3DRWParamsSearchDirData)); + A3D_INITIALIZE_DATA(A3DRWParamsSearchDirData, *(sLoadParametersData.m_sAssembly.m_ppcSearchDirectories[myInt])); + } + sLoadParametersData.m_sAssembly.m_ppcSearchDirectories[myInt]->m_pcPhysicalPath = ConvertString(kvp.Value); + } + if(kvp.Key->Contains("SearchDir") && kvp.Key->Contains("Recursive")) + { + String^ Indice = kvp.Key; + array^chars = {'[',']'}; + array^aIndice = Indice->Split(chars); + int myInt = System::Convert::ToInt32(aIndice[1]); + unsigned int uSize = sLoadParametersData.m_sAssembly.m_uiSearchDirectoriesSize; + if(uSize == 0) + { + sLoadParametersData.m_sAssembly.m_ppcSearchDirectories = + (A3DRWParamsSearchDirData**) malloc(sizeof(A3DRWParamsSearchDirData*)*(myInt + 1)); + sLoadParametersData.m_sAssembly.m_uiSearchDirectoriesSize = myInt + 1; + sLoadParametersData.m_sAssembly.m_ppcSearchDirectories[0] = NULL; + + } + else if((unsigned) myInt >= uSize) + { + sLoadParametersData.m_sAssembly.m_ppcSearchDirectories = + (A3DRWParamsSearchDirData**) realloc(sLoadParametersData.m_sAssembly.m_ppcSearchDirectories, + sizeof(A3DRWParamsSearchDirData*) * (myInt + 1)); + sLoadParametersData.m_sAssembly.m_uiSearchDirectoriesSize = myInt + 1; + sLoadParametersData.m_sAssembly.m_ppcSearchDirectories[0] = NULL; + } + if(sLoadParametersData.m_sAssembly.m_ppcSearchDirectories[myInt] == NULL) + { + sLoadParametersData.m_sAssembly.m_ppcSearchDirectories[myInt] = + (A3DRWParamsSearchDirData*) malloc(sizeof(A3DRWParamsSearchDirData)); + A3D_INITIALIZE_DATA(A3DRWParamsSearchDirData, + *(sLoadParametersData.m_sAssembly.m_ppcSearchDirectories[myInt])); + } + sLoadParametersData.m_sAssembly.m_ppcSearchDirectories[myInt]->m_bRecursive = (kvp.Value == "true"); + } + } + } + + //############################################################################################################## + bool Exchange::ConvertToXT(String^ SourceFileName, String^ DestinationFileName, IDictionary^ sOptions) + { + A3DAsmModelFile* modelFile = NULL; + + try + { + A3DRWParamsLoadData sLoadParametersData; + A3D_INITIALIZE_DATA(A3DRWParamsLoadData, sLoadParametersData); + + // default values + sLoadParametersData.m_sGeneral.m_bReadSolids = true; + sLoadParametersData.m_sGeneral.m_bReadSurfaces = true; + sLoadParametersData.m_sGeneral.m_bReadAttributes = true; + sLoadParametersData.m_sGeneral.m_bReadWireframes = true; + sLoadParametersData.m_sAssembly.m_bUseRootDirectory = true; + + // optional values + SetLoadParametersOptions(sLoadParametersData,sOptions); + + // specific syntax + for each(KeyValuePair kvp in sOptions) + { + if(kvp.Key == "WriteBlankedEntities" && kvp.Value == "true") + sLoadParametersData.m_sGeneral.m_bReadHiddenObjects = true; + } + + //if(Exchange::stm_pFCTTitle) + // Exchange::stm_pFCTTitle("A3DAsmModelFileLoadFromFile"); + + A3DStatus status = A3DAsmModelFileLoadFromFile(ConvertString(SourceFileName), &sLoadParametersData, + &modelFile); + if(status == A3D_LOAD_MISSING_COMPONENTS) + { + printf("HOOPS Exchange CAD file missing components\n"); + status = A3D_SUCCESS; + } + if(status) + printf("HOOPS Exchange CAD file loading failure\n"); + + // changing the unit + if(m_dUnit != 1000) // applying a scale + { + A3DAsmModelFileData sModelFileData; + A3D_INITIALIZE_DATA(A3DAsmModelFileData, sModelFileData); + A3DAsmModelFileGet(modelFile, &sModelFileData); + unsigned int uI; + for(uI = 0; uI < sModelFileData.m_uiPOccurrencesSize; uI++) + { + status = ScaleProductOccurence(sModelFileData.m_ppPOccurrences[uI], 1000 / m_dUnit); + if(status) + printf("HOOPS Exchange failed to apply the unit\n"); + } + A3DAsmModelFileGet(NULL, &sModelFileData); + } + + + if(status == A3D_SUCCESS) + { + A3DRWParamsExportParasolidData sExportParameters; + A3D_INITIALIZE_DATA(A3DRWParamsExportParasolidData, sExportParameters); + + // specific syntax + for each(KeyValuePair kvp in sOptions) + { + if(kvp.Key == "WriteBlankedEntities" && kvp.Value == "true") + sExportParameters.m_bWriteBlankedEntities = true; + } + + //if(Exchange::stm_pFCTTitle) + // Exchange::stm_pFCTTitle("A3DAsmModelFileExportToParasolidFile"); + + status = A3DAsmModelFileExportToParasolidFile(modelFile, &sExportParameters, + ConvertString(DestinationFileName)); + if(status) + printf("HOOPS Exchange Parasolid export failure\n"); + + //if(Exchange::stm_pFCTTitle) + // Exchange::stm_pFCTTitle("End"); + + A3DAsmModelFileDelete(modelFile); + + return status == A3D_SUCCESS; + } + + A3DAsmModelFileDelete(modelFile); + + stbreak=0; + return false; + } + catch(OperationCanceledException ^) + { + A3DAsmModelFileDelete(modelFile); + stBreakTranslation = m_bBreakTranslation = false; + Terminate(); + Init(); + return false; + } + } + + //############################################################################################################## + void Exchange::Break() + { + stBreakTranslation = m_bBreakTranslation = true; + } + + //############################################################################################################## + void Exchange::Terminate() + { + if(stbA3DLoaded) + { + A3DDllTerminate(); + A3DSDKUnloadLibrary(); + stbA3DLoaded = false; + } + } + + //############################################################################################################## + void Exchange::SetCallBackFct(CallbackStart^ pFCTStart, CallbackTitle^ pFCTTitle, CallbackSize^ pFCTSize, + CallbackIncrement^ pFCTIncr, CallbackEnd^ pFCTEnd) + { + stm_pFCTStart = pFCTStart; + stm_pFCTTitle = pFCTTitle; + stm_pFCTSize = pFCTSize; + stm_pFCTIncr = pFCTIncr; + stm_pFCTEnd = pFCTEnd; + } + + //############################################################################################################## + void Exchange::SetCallBackMessageFct(CallbackReportMessage^ fctReportMessage,CallbackReportWarning^ fctReportWarning, CallbackReportError^ fctReportError) + { + stm_pFctReportMessage = fctReportMessage; + stm_pFctReportWarning = fctReportWarning; + stm_pFctReportError = fctReportError; + if(stOut == stdout) + stOut = 0; + } + + //############################################################################################################## + Exchange::Exchange() + { + m_dUnit = 1000; + stBreakTranslation = m_bBreakTranslation = false; + } + + //############################################################################################################## + Exchange::!Exchange() + { + if(stOut && stOut != stdout) + fclose(stOut); + stOut = stdout; + Terminate(); + } + + //############################################################################################################## + Exchange::~Exchange() + { + Terminate(); + } + } +} diff --git a/exchange/exchangesource/NetWrapper/Translation.h b/exchange/exchangesource/NetWrapper/Translation.h new file mode 100644 index 0000000..022c178 --- /dev/null +++ b/exchange/exchangesource/NetWrapper/Translation.h @@ -0,0 +1,154 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + + +#pragma once + +using namespace System; +using namespace System::Collections::Generic; + + +namespace TechSoft3D +{ + namespace HOOPS + { + /// + /// Class wrapping the HOOPS Exchange DLL. + /// + public ref class Exchange + { + public: + + /// + /// Callback functions indicating what's starting: iStart == 1: Parsing CAD File + /// iStart == 2: Reading CAD File + /// iStart == 3: Writing Parasolid File + /// + delegate void CallbackStart(int iStart); + + /// + /// Callback function giving the name of the file being converted. Useful when managing assemblies. + /// + delegate void CallbackTitle(String^ sTitle); + + /// + /// Callback function giving the size of the progress bar. + /// + + delegate void CallbackSize(int iSize); + /// + /// Callback function giving the current position in the progress bar the positions relative to iSize (provided by CallbackSize). + /// + delegate void CallbackIncrement(int iIncr); + + /// + /// Callback function indicating the end of a reading/parsing/writing phase. + /// + delegate void CallbackEnd(void); + + /// + /// Callback function reporting messages. + /// + delegate int CallbackReportMessage(String^ pMsg); + + /// + /// Callback function reporting warning messages. + /// + delegate int CallbackReportWarning(String^ pCode,String^ pMsg); + + /// + /// Callback function reporting error messages. + /// + delegate int CallbackReportError(String^ pCode,String^ pMsg); + + /// + /// Load HOOPS Exchange DLL and check if the license is valid. + /// + /// + /// true if DLL has been loaded and the license is valid. + /// + bool Init(); + Exchange(); + ~Exchange(); + !Exchange(); + + /// + /// Determine if a file is a ProeFile + /// + bool IsProEFile(String^ path); + + /// + /// Function setting the unit in mm. The default value is 1000 as Parasolid files are usually in meters. + /// + void SetUnit(double dUnit); + + /// + /// Function to define a log file + /// + void SetLogFile(String^ LogFileName); + + /// + /// Convert any CAD file into XT file. + /// + /// + /// true if both reading and writing succeeded. + /// + bool ConvertToXT(String^ sourceFileName, String^ destinationFileName, IDictionary^ sOptions); + + /// + /// Break the conversion. + /// + void Break(); + + /// + /// Set callback functions to manage a progress bar. + /// + /// + /// fctStart: Function called when the parsing or reading or writing phase of a file is starting. + /// fctTitle: Function called when a new file is being loaded. + /// fctSize: Function called during conversion that gives the size of the progress bar. + /// fctIncr: Function called during conversion that gives the position in the progress bar. + /// + void SetCallBackFct(CallbackStart^ fctStart,CallbackTitle^ fctTitle, CallbackSize^ stm_pFCTSize, CallbackIncrement^ fctIncr, CallbackEnd^ fctEnd); + + /// + /// Set callback functions to manage a progress bar. + /// + /// + /// fctStart: Function called when the parsing or reading or writing phase of a file is starting. + /// fctTitle: Function called when a new file is being loaded. + /// fctSize: Function called during conversion that gives the size of the progress bar. + /// fctIncr: Function called during conversion that gives the position in the progress bar. + /// + void SetCallBackMessageFct(CallbackReportMessage^ fctReportMessage,CallbackReportWarning^ fctReportWarning, CallbackReportError^ fctReportError); + + static CallbackStart^ stm_pFCTStart; + static CallbackTitle^ stm_pFCTTitle; + static CallbackSize^ stm_pFCTSize; + static CallbackIncrement^ stm_pFCTIncr; + static CallbackEnd^ stm_pFCTEnd; + + static CallbackReportMessage^ stm_pFctReportMessage; + static CallbackReportWarning^ stm_pFctReportWarning; + static CallbackReportError^ stm_pFctReportError; + + private: + + void Terminate(); + + void SetLoadParametersOptions(A3DRWParamsLoadData & sLoadParametersData, IDictionary^ sOptions); + + double m_dUnit; + + bool m_bBreakTranslation; + }; + } +} diff --git a/exchange/exchangesource/PRC2IFCXML/PRC2IFCXML.cpp b/exchange/exchangesource/PRC2IFCXML/PRC2IFCXML.cpp new file mode 100644 index 0000000..640b72f --- /dev/null +++ b/exchange/exchangesource/PRC2IFCXML/PRC2IFCXML.cpp @@ -0,0 +1,91 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#define INITIALIZE_A3D_API + +#include + +#include "../common.hpp" + +//###################################################################################################################### +// Main function +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, wchar_t** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + // + // ### COMMAND LINE ARGUMENTS + // + + if (iArgc > 4) + { + MY_PRINTF2("Usage:\n %s [input CAD file] [output XML file] [output LOG file]\n", ppcArgv[0]); + MY_PRINTF(" Default output XML file is [input CAD file].xml\n"); + MY_PRINTF(" Default output LOG file is [output IFCXML file]_Log.txt\n\n"); + return A3D_ERROR; + } + + MY_CHAR acSrcFileName[_MAX_PATH * 2]; + MY_CHAR acDstFileName[_MAX_PATH * 2]; + MY_CHAR acLogFileName[_MAX_PATH * 2]; + + if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]); + else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD); + if (iArgc > 2) MY_STRCPY(acDstFileName, ppcArgv[2]); + else MY_SPRINTF(acDstFileName, "%s.ifcxml", acSrcFileName); + if (iArgc > 3) MY_STRCPY(acLogFileName, ppcArgv[3]); + else MY_SPRINTF(acLogFileName, "%s_Log.txt", acDstFileName); + GetLogFile(acLogFileName); // Initialize log file + + // + // ### INITIALIZE HOOPS EXCHANGE + // + + A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); + CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus); + + // Initialize callbacks + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + // + // ### PROCESS SAMPLE CODE + // + + A3DUTF8Char acUTF8DstFileName[_MAX_PATH * 2]; +#ifdef _MSC_VER + A3DMiscUTF16ToUTF8(acDstFileName, acUTF8DstFileName); +#else + MY_STRCPY(acUTF8DstFileName, acDstFileName); +#endif + + A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + sImport.m_sLoadData.m_sSpecifics.m_sIFC.m_bReadRelationships = true; + + + const A3DStatus iRet = sHoopsExchangeLoader.Import(sImport); + if (iRet != A3D_SUCCESS && iRet != A3D_LOAD_MULTI_MODELS_CADFILE && iRet != A3D_LOAD_MISSING_COMPONENTS) + return iRet; + if (!sHoopsExchangeLoader.m_psModelFile) + return A3D_ERROR; + + TEST_RET(A3DAsmModelFileExportToIfcXMLFile(sHoopsExchangeLoader.m_psModelFile, acUTF8DstFileName)) + + + // + // ### TERMINATE HOOPS EXCHANGE + // + + // Check memory allocations + return (int)ListLeaks(); +} diff --git a/exchange/exchangesource/PRC2IFCXML/PRC2IFCXML.vcxproj b/exchange/exchangesource/PRC2IFCXML/PRC2IFCXML.vcxproj new file mode 100644 index 0000000..ed75203 --- /dev/null +++ b/exchange/exchangesource/PRC2IFCXML/PRC2IFCXML.vcxproj @@ -0,0 +1,176 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {236BB296-3A6D-4CBF-B8C2-4370790211F0} + PRC2IFCXML + 10.0 + + + + Application + v145 + true + + + Application + v145 + + + Application + v145 + true + + + Application + v145 + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + ;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + $(OutDir)$(ProjectName).exe + + + true + Console + false + + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + Disabled + ;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + $(OutDir)$(ProjectName).exe + + + true + Console + false + + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level4 + ProgramDatabase + false + + + $(OutDir)$(ProjectName).exe + ..\..\bin;%(AdditionalLibraryDirectories) + false + Console + true + true + false + + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + ;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level4 + ProgramDatabase + false + + + $(OutDir)$(ProjectName).exe + ..\..\bin;%(AdditionalLibraryDirectories) + false + Console + true + true + false + + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/PRC2IFCXML/PRC2IFCXML.vcxproj.filters b/exchange/exchangesource/PRC2IFCXML/PRC2IFCXML.vcxproj.filters new file mode 100644 index 0000000..ff8cc81 --- /dev/null +++ b/exchange/exchangesource/PRC2IFCXML/PRC2IFCXML.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/exchange/exchangesource/PRC2XML/ExchangeManagement.cpp b/exchange/exchangesource/PRC2XML/ExchangeManagement.cpp new file mode 100644 index 0000000..2e53bef --- /dev/null +++ b/exchange/exchangesource/PRC2XML/ExchangeManagement.cpp @@ -0,0 +1,46 @@ +// +// Created by mathis on 27/05/2016. +// + +#ifdef __APPLE__ +# include "TargetConditionals.h" +# if TARGET_OS_IPHONE == 1 || TARGET_IPHONE_SIMULATOR == 1 +# define INITIALIZE_A3D_API_STATIC +# endif +#endif + +#include "ExchangeManagement.h" + +#include + +#include "PRC2XML.h" + +#ifdef __APPLE__ +# include "TargetConditionals.h" +# if TARGET_OS_IPHONE == 1 || TARGET_IPHONE_SIMULATOR == 1 +# include +# endif +#endif + +ExchangeManagement::ExchangeManagement() { + m_libraryLoadingStatus = A3D_SUCCESS; + + m_sHoopsExchangeLoader = new A3DSDKHOOPSExchangeLoader(NULL); + m_libraryLoadingStatus = m_sHoopsExchangeLoader->m_eSDKStatus; +} + +A3DInt32 ExchangeManagement::convert(const std::string& filename, const std::string& outputPath) { + + A3DInt32 iRet = A3D_ERROR; + if (m_libraryLoadingStatus == A3D_SUCCESS) { + A3DImport sImport(filename.c_str()); + + iRet = ProcessFile(*m_sHoopsExchangeLoader, sImport, filename.c_str(), outputPath.c_str()); + } + return iRet; +} + +ExchangeManagement::~ExchangeManagement() { + delete m_sHoopsExchangeLoader; +} + diff --git a/exchange/exchangesource/PRC2XML/ExchangeManagement.h b/exchange/exchangesource/PRC2XML/ExchangeManagement.h new file mode 100644 index 0000000..edd3565 --- /dev/null +++ b/exchange/exchangesource/PRC2XML/ExchangeManagement.h @@ -0,0 +1,23 @@ +// +// Created by mathis on 27/05/2016. +// + +#ifndef PRC2XML_EXCHANGEMANAGEMENT_H +#define PRC2XML_EXCHANGEMANAGEMENT_H + +#include +#include + +class ExchangeManagement { +public: + ExchangeManagement(); + ~ExchangeManagement(); + + A3DInt32 convert(const std::string& filename, const std::string& outputPath); + +protected: + A3DInt32 m_libraryLoadingStatus; + A3DSDKHOOPSExchangeLoader* m_sHoopsExchangeLoader; +}; + +#endif //PRC2XML_EXCHANGEMANAGEMENT_H diff --git a/exchange/exchangesource/PRC2XML/PRC2XML.cpp b/exchange/exchangesource/PRC2XML/PRC2XML.cpp new file mode 100644 index 0000000..07ec5cd --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XML.cpp @@ -0,0 +1,212 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include // for exception-throwing new + +#ifdef __ANDROID__ +# include +# include + +# define INITIALIZE_A3D_API +# include +# undef INITIALIZE_A3D_API + +# define JNI_LOG_TAG "SAMPLE PRC 2 XML" +# define LOGI(...) __android_log_print(ANDROID_LOG_INFO, JNI_LOG_TAG, __VA_ARGS__) +# define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, JNI_LOG_TAG, __VA_ARGS__) +#endif // __ANDROID__ + +#ifdef __APPLE__ +# include "TargetConditionals.h" +# if TARGET_OS_IPHONE == 1 || TARGET_IPHONE_SIMULATOR == 1 +# define APPLE_IOS +# include +# endif +#endif + +#include "PRC2XML.h" + +#ifndef _MAX_PATH +# ifdef _MSC_VER +# define _MAX_PATH 260 +# else +# define _MAX_PATH 4096 +# endif +#endif + +//###################################################################################################################### +// reads the PRC file and dumps information into XML format +A3DStatus ReadFile(A3DSDKHOOPSExchangeLoader& sHoopsExchangeLoader, A3DImport& sImport, _TiXmlElement* treatment) +{ + const A3DStatus iRet = sHoopsExchangeLoader.Import(sImport); + if(iRet != A3D_SUCCESS && iRet != A3D_LOAD_MULTI_MODELS_CADFILE && iRet != A3D_LOAD_MISSING_COMPONENTS) + return iRet; + + A3DAsmModelFile* pModelFile = sHoopsExchangeLoader.m_psModelFile; + + // Retrieve physical properties + A3DPhysicalPropertiesData sPhysPropsData; + A3D_INITIALIZE_DATA(A3DPhysicalPropertiesData, sPhysPropsData); + A3DStatus iRetP = A3DComputeModelFilePhysicalProperties(pModelFile, &sPhysPropsData); + + + std::unique_ptr<_TiXmlElement> physicalprops(new _TiXmlElement("ComputePhysicalProps")); + + if (iRetP == A3D_SUCCESS) + { + physicalprops->SetDoubleAttribute("m_sGravityCenter.m_dX", sPhysPropsData.m_sGravityCenter.m_dX); + physicalprops->SetDoubleAttribute("m_sGravityCenter.m_dY", sPhysPropsData.m_sGravityCenter.m_dY); + physicalprops->SetDoubleAttribute("m_sGravityCenter.m_dZ", sPhysPropsData.m_sGravityCenter.m_dZ); + physicalprops->SetDoubleAttribute("m_dSurface", sPhysPropsData.m_dSurface); + physicalprops->SetDoubleAttribute("m_bVolumeComputed", sPhysPropsData.m_bVolumeComputed); + physicalprops->SetDoubleAttribute("m_dVolume", sPhysPropsData.m_dVolume); + } + else + { + physicalprops->SetAttribute("error", iRetP); + } + + treatment->LinkEndChild(physicalprops.release()); + +#ifndef APPLE_IOS // the following code triggers a SIGSTOP on iOS + // Retrieve files path from model files + A3DUns32 nbFiles = 0, nbAssemblyFiles = 0, nbMissingFiles = 0; + A3DUTF8Char** ppPaths = NULL, ** ppAssemblyPaths = NULL, ** ppMissingPaths = NULL; + + struct ModelFileGuard + { + A3DAsmModelFile*& m_psModelFile; + explicit ModelFileGuard(A3DAsmModelFile*& pModelFile): m_psModelFile(pModelFile) {} + ~ModelFileGuard() + { + A3DAsmModelFileDelete(m_psModelFile); + m_psModelFile = NULL; + } + } const sGuard(sHoopsExchangeLoader.m_psModelFile); + +#ifdef __ANDROID__ + try { +#endif + CHECK_RET(A3DAsmGetFilesPathFromModelFile( + sHoopsExchangeLoader.m_psModelFile, + &nbFiles, + &ppPaths, + &nbAssemblyFiles, + &ppAssemblyPaths, + &nbMissingFiles, + &ppMissingPaths)); +#ifdef __ANDROID__ + } catch(std::exception const& e) { + LOGE("%s\n", e.what()); + return iRet; + } +#endif + + std::unique_ptr<_TiXmlElement> allFilesPaths(new _TiXmlElement("A3DAsmFilesPathFromModelFile")); + allFilesPaths->SetAttribute("nbFiles" , (int)nbFiles); + allFilesPaths->SetAttribute("nbAssemblyFiles", (int)nbAssemblyFiles); + allFilesPaths->SetAttribute("nbMissingFiles" , (int)nbMissingFiles); + + for (A3DUns32 ui = 0; ui < nbFiles; ui++) + { + std::unique_ptr<_TiXmlElement> filePaths(new _TiXmlElement("Filepaths")); + filePaths->SetAttribute("m_FilePaths", ppPaths[ui]); + allFilesPaths->LinkEndChild(filePaths.release()); + } + + for (A3DUns32 uj = 0; uj < nbAssemblyFiles; uj++) + { + std::unique_ptr<_TiXmlElement> assemblyFilePaths(new _TiXmlElement("AssemblyFilePaths")); + assemblyFilePaths->SetAttribute("m_AssemblyFilePaths", ppAssemblyPaths[uj]); + allFilesPaths->LinkEndChild(assemblyFilePaths.release()); + } + + for (A3DUns32 uk = 0; uk < nbMissingFiles; uk++) + { + std::unique_ptr<_TiXmlElement> missingFilePaths(new _TiXmlElement("MissingFilePaths")); + missingFilePaths->SetAttribute("m_nbMissingFiles", ppMissingPaths[uk]); + allFilesPaths->LinkEndChild(missingFilePaths.release()); + } + + treatment->LinkEndChild(allFilesPaths.release()); + + CHECK_RET(A3DAsmGetFilesPathFromModelFile(NULL, &nbFiles, &ppPaths, &nbAssemblyFiles, &ppAssemblyPaths, &nbMissingFiles, &ppMissingPaths)); +#endif // !defined(APPLE_IOS) + + A3DGlobal* pGlobal = NULL; + CHECK_RET(A3DGlobalGetPointer(&pGlobal)); + + traverseGlobal(pGlobal, treatment); + traverseModel(pModelFile, treatment); + traverseFonts(treatment); + return iRet; +} + +//###################################################################################################################### +A3DVoid _InitializeFontsArray(); + +//###################################################################################################################### +A3DVoid _TerminateFontsArray(); + +//###################################################################################################################### +A3DStatus ProcessFile( + A3DSDKHOOPSExchangeLoader& sHoopsExchangeLoader, + A3DImport& sImport, + const MY_CHAR* pcPRCFile, + const MY_CHAR* pcXMLFile) +{ + A3DUTF8Char sPRCFileUTF8[_MAX_PATH]; + A3DUTF8Char sXMLFileUTF8[_MAX_PATH]; +#ifdef _MSC_VER + A3DMiscUTF16ToUTF8(pcPRCFile, sPRCFileUTF8); + A3DMiscUTF16ToUTF8(pcXMLFile, sXMLFileUTF8); +#else + MY_STRCPY(sPRCFileUTF8, pcPRCFile); + MY_STRCPY(sXMLFileUTF8, pcXMLFile); +#endif + + std::unique_ptr<_TiXmlDocument> doc; + try + { + doc.reset(new _TiXmlDocument); + doc->SetCondenseWhiteSpace(false); + + std::unique_ptr<_TiXmlComment> comment(new _TiXmlComment("XML dump from PRC file")); + doc->LinkEndChild(comment.release()); + + A3DInt32 iMajorVersion = 0, iMinorVersion = 0; + CHECK_RET(A3DDllGetVersion(&iMajorVersion, &iMinorVersion)); + + std::unique_ptr<_TiXmlElement> treatment(new _TiXmlElement("TREATMENT")); + treatment->SetAttribute("MajorVersion", iMajorVersion); + treatment->SetAttribute("MinorVersion", iMinorVersion); + treatment->SetAttribute("PRCFile" , sPRCFileUTF8); + + _InitializeFontsArray(); + + TEST_RET(ReadFile(sHoopsExchangeLoader, sImport, treatment.get())) + + doc->LinkEndChild(treatment.release()); + doc->SaveFile(sXMLFileUTF8); + + _TerminateFontsArray(); + return A3D_SUCCESS; + } + catch(const std::bad_alloc&) + { + PrintLogError(NULL, "std::bad_alloc exception caught\n"); + if (doc.get()) + // try to save what has already been generated + doc->SaveFile(sXMLFileUTF8); + return A3D_ERROR; + } +} diff --git a/exchange/exchangesource/PRC2XML/PRC2XML.h b/exchange/exchangesource/PRC2XML/PRC2XML.h new file mode 100644 index 0000000..dd4370a --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XML.h @@ -0,0 +1,219 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef __A3DTESTERREAD_H__ +#define __A3DTESTERREAD_H__ + +#include + +#ifdef WIN32 +# pragma warning (disable:4090) +# define _CRT_SECURE_NO_DEPRECATE 1 +# ifdef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES +# undef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES +# define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1 +# endif +#else +#define sprintf_s(buf, buf_size, ...) sprintf((buf), __VA_ARGS__) +#endif + +#ifdef __APPLE__ +# include "TargetConditionals.h" +# if TARGET_OS_IPHONE == 1 || TARGET_IPHONE_SIMULATOR == 1 +# include "tinyxml.h" +# include "common.hpp" +# else +# include +# include +# include "../common.hpp" +# endif +#elif defined(__ANDROID__) +# include +# include "common.hpp" +#else +# include +# include +# include "../common.hpp" +#endif + +//###################################################################################################################### +A3DStatus ProcessFile( + A3DSDKHOOPSExchangeLoader& sHoopsExchangeLoader, + A3DImport& sImport, + const MY_CHAR* pcPRCFile, + const MY_CHAR* pcXMLFile); + +//###################################################################################################################### +void _SetAttributePtr(_TiXmlElement* psElement, const A3DUTF8Char* pcAttribName, void* pValue); + +//###################################################################################################################### +void _SetDoubleAttribute(_TiXmlElement* psElement, const char* name, double val); + +//###################################################################################################################### +int traverseDoubles(const A3DUTF8Char* name, const A3DUns32 uiSize, const A3DDouble* pd, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseUInts(const A3DUTF8Char* name, const A3DUns32 uiSize, const A3DUns32* pui, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseUChars(const A3DUTF8Char* name, const A3DUns32 uiSize, const A3DUns8* pui, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseBools(const A3DUTF8Char* name, const A3DUns32 uiSize, const A3DBool* pb, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseVoids(const A3DUTF8Char* name, const A3DUns32 uiSize, const A3DVoid** pp, _TiXmlElement* setting); + +//###################################################################################################################### +int traversePoint2d(const A3DUTF8Char* name, const A3DVector2dData& sData, _TiXmlElement* setting); + +//###################################################################################################################### +int traversePoint(const A3DUTF8Char* name, const A3DVector3dData& sData, _TiXmlElement* setting); + +//###################################################################################################################### +int traversePoints(const A3DUTF8Char* name, const A3DUns32 uiSize, const A3DVector3dData* pv, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseInterval(const A3DIntervalData* pData, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseDomain(const A3DDomainData* pData, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseBoundingBox(const A3DBoundingBoxData* pData, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseParam(const A3DParameterizationData* pData, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseUVParam(const A3DUVParameterizationData* pData, _TiXmlElement* setting); + +//###################################################################################################################### +A3DStatus traverseTransformation(const A3DMiscTransformation* pTrsf, _TiXmlElement *setting); + +//###################################################################################################################### +A3DStatus traverseCartesianTransformationData(const A3DMiscCartesianTransformationData& oTrsf, _TiXmlElement* setting); + +//###################################################################################################################### +A3DStatus traverseCartesianTransformation(const A3DMiscCartesianTransformation* pTransfo3d, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseSource(const A3DEntity* pEntity, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseGlobal(const A3DGlobal* pGlobal, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseModel(const A3DAsmModelFile* pModelFile, _TiXmlElement* setting); + +//###################################################################################################################### +int dumpRelationships(const A3DBIMData* pBimData, _TiXmlElement* model); + +//###################################################################################################################### +int traverseFonts(_TiXmlElement* setting); + +//###################################################################################################################### +int traverseCurve(const A3DCrvBase* pCrv, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseSurface(const A3DSurfBase* pSrf, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseSrfPlane(const A3DSurfPlane* pSrf, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseAnnotation(const A3DMkpAnnotationEntity* pAnnot, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseMarkup(const A3DMkpMarkup* pMarkup, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseLeader(const A3DMkpLeader* pLeader, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseLinkedItem(const A3DMiscMarkupLinkedItem* pMkpLinkedItem, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseEntityReference(const A3DMiscEntityReference* pEntityReference, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseSingleWireBody(const A3DTopoSingleWireBody* pSingleWireBody, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseTopoContext(const A3DTopoContext* pContext, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseBodyContent(const A3DTopoBody* pBody, _TiXmlElement* setting,unsigned char &ucBehav); + +//###################################################################################################################### +int traverseBrepData(const A3DTopoBrepData* pBrepData, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseTessBase(const A3DTessBase* pTess, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseView(const A3DMkpView* pView, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseRepItem(const A3DRiRepresentationItem* pRepItem, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseCSys(const A3DRiCoordinateSystem* pCSys, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseTextureApplication(const A3DGraphTextureApplicationData& sData, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseTextureDefinition(const A3DGraphTextureDefinitionData& sData, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseMarkupTess(const A3DTessMarkup* pMarkupTess, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseMarkupDefinition(const A3DMkpMarkup* pMarkup, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseMarkupText(const A3DMarkupText* pA3DMarkup, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseMarkupRichText(const A3DMarkupRichText* pA3DMarkup, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseMarkupDatum(const A3DMarkupDatum* pA3DMarkup, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseMarkupTextProperties(const A3DMDTextProperties* pA3DTextProperties, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseMarkupGDT(const A3DMarkupGDT* psMarkup, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseMarkupDimension(const A3DMarkupDimension* pMarkup, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseDrawing(const A3DDrawingModel * pDrawing, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseMaterial(const A3DGraphMaterialData& sData, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseMaterialProperties(const A3DEntity* pEntity, _TiXmlElement* xmlfather); + +//###################################################################################################################### +A3DVoid traverseFeatureTree(const A3DFRMTree* pFeatFeatureTree, _TiXmlElement* xmlfather); + +//###################################################################################################################### +int traverseToleranceSizeValue(const A3DMDToleranceSizeValue* pToleranceSizeValue, _TiXmlElement* setting); + +//###################################################################################################################### +int traverseConstraint(const A3DAsmConstraint* pAsmConstraint, _TiXmlElement* xmlfather); + +#endif /* __A3DTESTERREAD_H__ */ diff --git a/exchange/exchangesource/PRC2XML/PRC2XML.vcxproj b/exchange/exchangesource/PRC2XML/PRC2XML.vcxproj new file mode 100644 index 0000000..e932039 --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XML.vcxproj @@ -0,0 +1,199 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {C3C57200-3B1F-465F-8631-E948A935D645} + PRC2XML + Win32Proj + 10.0 + + + + Application + v145 + true + + + Application + v145 + + + Application + v145 + true + + + Application + v145 + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + .\TinyXML;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + ..\..\bin\;%(AdditionalLibraryDirectories) + true + Console + false + + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + Disabled + .\TinyXML;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + ..\..\bin\;%(AdditionalLibraryDirectories) + true + Console + false + + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + .\TinyXML;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level4 + ProgramDatabase + false + + + ..\..\bin;%(AdditionalLibraryDirectories) + false + Console + true + true + false + + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + .\TinyXML;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level4 + ProgramDatabase + false + + + ..\..\bin;%(AdditionalLibraryDirectories) + false + Console + true + true + false + + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/PRC2XML/PRC2XML.vcxproj.filters b/exchange/exchangesource/PRC2XML/PRC2XML.vcxproj.filters new file mode 100644 index 0000000..665aae1 --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XML.vcxproj.filters @@ -0,0 +1,111 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {634f85a6-9600-4a43-8d89-3c2302e081bd} + + + {a36c30af-97fd-42f2-bc06-58067f37adf5} + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {87964168-4c28-4b2d-9caa-a9d6ef35afc7} + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files\TinyXML + + + Source Files\TinyXML + + + Source Files\TinyXML + + + Source Files\TinyXML + + + Source Files\pmi + + + Source Files\pmi + + + Source Files\pmi + + + Source Files\pmi + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files\TinyXML + + + Header Files\TinyXML + + + \ No newline at end of file diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLConstraint.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLConstraint.cpp new file mode 100644 index 0000000..2fb58a3 --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLConstraint.cpp @@ -0,0 +1,172 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "PRC2XML.h" + +//###################################################################################################################### +static void sttraverseConstraintType(EA3DConstraintType eType, _TiXmlElement* xml) +{ + switch (eType) + { + default: + case kA3DConstraintType_None: xml->SetAttribute("m_eType", "None"); break; + case kA3DConstraintType_Set: xml->SetAttribute("m_eType", "Set"); break; + case kA3DConstraintType_Fix: xml->SetAttribute("m_eType", "Fix"); break; + case kA3DConstraintType_FixTogether: xml->SetAttribute("m_eType", "FixTogether"); break; + case kA3DConstraintType_Contact: xml->SetAttribute("m_eType", "Contact"); break; + case kA3DConstraintType_Distance: xml->SetAttribute("m_eType", "Distance"); break; + case kA3DConstraintType_Angle: xml->SetAttribute("m_eType", "Angle"); break; + case kA3DConstraintType_Perpendicular: xml->SetAttribute("m_eType", "Perpendicular"); break; + case kA3DConstraintType_Parallel: xml->SetAttribute("m_eType", "Parallel"); break; + }; +} + +//###################################################################################################################### +static void sttraverseConstraintLinkedItemType(EA3DConstraintLinkType eLinkType, _TiXmlElement* xml) +{ + switch (eLinkType) + { + default: + case kA3DConstraintLink_None: xml->SetAttribute("m_eType", "None"); break; + case kA3DConstraintLink_Axis: xml->SetAttribute("m_eType", "Axis"); break; + case kA3DConstraintLink_Center: xml->SetAttribute("m_eType", "Center"); break; + }; +} + +//###################################################################################################################### +static void sttraverseConstraintStatus(EA3DConstraintStatus eStatus, _TiXmlElement* xml) +{ + switch (eStatus) + { + case kA3DConstraintStatus_OK: xml->SetAttribute("m_eStatus", "OK"); break; + case kA3DConstraintStatus_Disabled: xml->SetAttribute("m_eStatus", "Disable"); break; + default: + case kA3DConstraintStatus_Error: xml->SetAttribute("m_eStatus", "Error"); break; + }; +} + +//###################################################################################################################### +static A3DVoid sttraverseSetNameAttribute(const A3DEntity* entity, _TiXmlElement* xmlnode) +{ + A3DRootBaseData sData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sData); + if (A3DRootBaseGet(entity, &sData) == A3D_SUCCESS) + { + if (sData.m_pcName && sData.m_pcName[0] != '\0') + xmlnode->SetAttribute("Name", sData.m_pcName); + if (sData.m_uiPersistentId) + xmlnode->SetAttribute("PersistentId", sData.m_uiPersistentId); + A3DRootBaseGet(NULL, &sData); + } +} + +//###################################################################################################################### +static A3DVoid sttraverseMiscConstraintLinkedItem(const A3DMiscConstraintLinkedItem* pConstraintLinkedItem, _TiXmlElement* xmlfather) +{ + + _TiXmlElement* xml = new _TiXmlElement("A3DMiscConstraintLinkedItem"); + A3DMiscConstraintLinkedItemData sData; + A3D_INITIALIZE_DATA(A3DMiscConstraintLinkedItemData, sData); + + traverseSource(pConstraintLinkedItem, xml); + + A3DInt32 iRet = A3DMiscConstraintLinkedItemGet(pConstraintLinkedItem, &sData); + if (iRet == A3D_SUCCESS) + { + traverseEntityReference((A3DMiscEntityReference*)pConstraintLinkedItem, xml); + sttraverseConstraintLinkedItemType(sData.m_eType, xml); + if (sData.m_pTargetProductOccurrence != NULL) + _SetAttributePtr(xml, "m_pTargetProductOccurrence", (void*)sData.m_pTargetProductOccurrence); + A3DMiscConstraintLinkedItemGet(NULL, &sData); + } + else + xml->SetAttribute("error", iRet); + + xmlfather->LinkEndChild(xml); +} + +const char* GetContactTypeEnumString(A3DUns32 uiContactType) +{ + switch (uiContactType) + { + case 0: return "UNDEFINED"; + case 1: return "SURFACE"; + case 2: return "ANNULAR"; + case 3: return "LINE"; + case 4: return "POINT"; + }; + return "UNDEFINED"; +} + +const char* GetOrientationEnumString(A3DUns32 uiOrientation) +{ + switch (uiOrientation) + { + case 0: return "UNDEFINED"; + case 1: return "SAME"; + case 2: return "OPPOSITE"; + } + return "UNDEFINED"; +} + +//###################################################################################################################### +static void sttraverseAdditionalData(A3DGenericTypeFieldData & sFielData, _TiXmlElement* a_pElement) +{ + if (!sFielData.m_pacFieldName) + a_pElement->SetAttribute("FieldName", "Missing"); + else + { + switch (sFielData.m_sData.m_eType) + { + case kA3DGenericTypeUns32: + if (!strcmp(sFielData.m_pacFieldName, "ContactType")) + a_pElement->SetAttribute(sFielData.m_pacFieldName, GetContactTypeEnumString(sFielData.m_sData.m_sValue.m_uiUns32)); + else if (!strcmp(sFielData.m_pacFieldName, "Orientation")) + a_pElement->SetAttribute(sFielData.m_pacFieldName, GetOrientationEnumString(sFielData.m_sData.m_sValue.m_uiUns32)); + else + a_pElement->SetAttribute(sFielData.m_pacFieldName, sFielData.m_sData.m_sValue.m_uiUns32); + break; + + default: a_pElement->SetAttribute(sFielData.m_pacFieldName, "NotImplementedType"); break; + } + } +} + +//###################################################################################################################### +int traverseConstraint(const A3DAsmConstraint* pAsmConstraint, _TiXmlElement* xmlfather) +{ + _TiXmlElement* xml = new _TiXmlElement("A3DAsmConstraint"); + sttraverseSetNameAttribute(pAsmConstraint, xml); + + A3DAsmConstraintData sData; + A3D_INITIALIZE_DATA(A3DAsmConstraintData, sData); + if (A3DAsmConstraintGet(pAsmConstraint, &sData) == A3D_SUCCESS) + { + sttraverseConstraintType(sData.m_eType, xml); + sttraverseConstraintStatus(sData.m_eStatus, xml); + + A3DUns32 ui; + for (ui = 0; ui < sData.m_uiAdditionalDataArraySize; ++ui) + sttraverseAdditionalData(sData.m_pAdditionalDataArray[ui], xml); + + for (ui = 0; ui < sData.m_uiSubConstraintsSize; ++ui) + traverseConstraint(sData.m_ppSubConstraints[ui], xml); + + for (ui = 0; ui < sData.m_uiConstrainedElementsSize; ++ui) + sttraverseMiscConstraintLinkedItem(sData.m_ppConstrainedElements[ui], xml); + + A3DAsmConstraintGet(NULL, &sData); + } + xmlfather->LinkEndChild(xml); + + return A3D_SUCCESS; +} diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLFeature.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLFeature.cpp new file mode 100644 index 0000000..85e6100 --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLFeature.cpp @@ -0,0 +1,256 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "PRC2XML.h" + +static A3DVoid sttraverseSetNameAttribute(const A3DEntity* entity, + _TiXmlElement* xmlnode) +{ + { + A3DRootBaseData sData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sData); + if (A3DRootBaseGet(entity, &sData) == A3D_SUCCESS) + { + if (sData.m_pcName && sData.m_pcName[0] != '\0') + xmlnode->SetAttribute("Name", sData.m_pcName); + if (sData.m_uiPersistentId) + xmlnode->SetAttribute("PersistentId", sData.m_uiPersistentId); + A3DRootBaseGet(NULL, &sData); + } + } + { + A3DRootBaseWithGraphicsData sData; + A3D_INITIALIZE_DATA(A3DRootBaseWithGraphicsData, sData); + if (A3DRootBaseWithGraphicsGet(entity, &sData) == A3D_SUCCESS) + { + if (sData.m_pGraphics) + { + A3DGraphicsData sGraphicsData; + A3D_INITIALIZE_DATA(A3DGraphicsData, sGraphicsData); + if (A3DGraphicsGet(sData.m_pGraphics, &sGraphicsData) == A3D_SUCCESS) + { + xmlnode->SetAttribute("Layer", sGraphicsData.m_uiLayerIndex); + xmlnode->SetAttribute("Style", sGraphicsData.m_uiStyleIndex); + xmlnode->SetAttribute("Behaviour", sGraphicsData.m_usBehaviour); + } + } + } + } +} + +static A3DVoid sttraverseXmlText(const char* ac, + _TiXmlElement* xmlfather) +{ + if (ac[0] != '\0') { + char acUTF8[2048]; + sprintf(acUTF8, "%s ", ac); + _TiXmlText* xml = new _TiXmlText(acUTF8); + xmlfather->LinkEndChild(xml); + } +} + +static A3DVoid sttraverseXmlText(double d, + _TiXmlElement* xmlfather) +{ + char acUTF8[2048]; + sprintf(acUTF8, "%g", d); + sttraverseXmlText(acUTF8, xmlfather); +} + + +static A3DVoid sttraverseFRMFeatureLinkedItem(const A3DFRMLinkedItem* pFeatureLinkedItem, _TiXmlElement* xmlfather) +{ + + _TiXmlElement* xml = new _TiXmlElement("A3DFRMLinkedItem"); + A3DFRMLinkedItemData sData; + A3D_INITIALIZE_DATA(A3DFRMLinkedItemData, sData); + + traverseSource(pFeatureLinkedItem, xml); + + A3DInt32 iRet = A3DFRMLinkedItemGet(pFeatureLinkedItem, &sData); + if (iRet == A3D_SUCCESS) + { + traverseEntityReference((A3DMiscEntityReference*)pFeatureLinkedItem, xml); + xml->SetAttribute("m_eType", sData.m_eType); + if (sData.m_pTargetProductOccurrence != NULL) + _SetAttributePtr(xml, "m_pTargetProductOccurrence", (void*)sData.m_pTargetProductOccurrence); + A3DFRMLinkedItemGet(NULL, &sData); + } + else + xml->SetAttribute("error", iRet); + + xmlfather->LinkEndChild(xml); +} + +static A3DVoid sttraverseFRMParameter(const A3DFRMParameter* pFeatParameter, _TiXmlElement* xmlfather); + +static A3DVoid sttraverseFRMFeature(const A3DFRMFeature* pFeature, _TiXmlElement* xmlfather) + +{ + _TiXmlElement* xml = new _TiXmlElement("A3DFRMFeature"); + sttraverseSetNameAttribute(pFeature, xml); + xmlfather->LinkEndChild(xml); + + A3DUTF8Char* pcFeatureType = NULL; + A3DFRMFeatureGetTypeAsString(pFeature, &pcFeatureType); + if(pcFeatureType) + xml->SetAttribute("Type", pcFeatureType); + + A3DFRMFeatureGetTypeAsString(nullptr, &pcFeatureType); + + A3DFRMFeatureData sData; + A3D_INITIALIZE_DATA(A3DFRMFeatureData, sData); + A3DStatus iErr = A3DFRMFeatureGet(pFeature, &sData); + if (iErr != A3D_SUCCESS) + return ; + char acName[30]; + + switch (sData.m_eDataType) + { + case kA3DFRMDataInteger: + A3DFRMIntegerData sIntegerData; + A3D_INITIALIZE_DATA(A3DFRMIntegerData, sIntegerData); + A3DFRMIntegerDataGet(pFeature, &sIntegerData); + for (A3DUns32 i = 0; i < sIntegerData.m_uiValuesSize; ++i) + { + sprintf_s(acName,sizeof(acName)-1, "value_%d", i); + xml->SetAttribute(acName, sIntegerData.m_piValues[i]); + } + A3DFRMIntegerDataGet(NULL, &sIntegerData); + break; + case kA3DFRMDataDouble: + A3DFRMDoubleData sDoubleData; + A3D_INITIALIZE_DATA(A3DFRMDoubleData, sDoubleData); + A3DFRMDoubleDataGet(pFeature, &sDoubleData); + for (A3DUns32 i = 0; i < sDoubleData.m_uiValuesSize; ++i) + { + sprintf_s(acName, sizeof(acName) - 1, "value_%d", i); + xml->SetDoubleAttribute(acName, sDoubleData.m_pdValues[i]); + } + A3DFRMDoubleDataGet(NULL, &sDoubleData); + break; + case kA3DFRMDataString: + A3DFRMStringData sStringData; + A3D_INITIALIZE_DATA(A3DFRMStringData, sStringData); + A3DFRMStringDataGet(pFeature, &sStringData); + for (A3DUns32 i = 0; i < sStringData.m_uiValuesSize; ++i) + { + sprintf(acName, "value_%d", i); + if (sStringData.m_ppcValues[i] != NULL) + xml->SetAttribute(acName, sStringData.m_ppcValues[i]); + else + xml->SetAttribute(acName, ""); + } + A3DFRMStringDataGet(NULL, &sStringData); + break; + case kA3DFRMDataEnum: + { + A3DInt32 iEnumValue; + A3DUTF8Char* pcValueAsString = NULL; + A3DFRMEnumDataGet(pFeature, &iEnumValue, &pcValueAsString); + if (pcValueAsString) + xml->SetAttribute("Value", pcValueAsString); + else + xml->SetAttribute("Value", iEnumValue); + A3DFRMEnumDataGet(NULL, &iEnumValue, &pcValueAsString); + } + break; + default: + break; + } + + for (A3DUns32 ui = 0; uiLinkEndChild(xml); + + A3DFRMParameterData sData; + A3D_INITIALIZE_DATA(A3DFRMParameterData, sData); + A3DStatus iErr = A3DFRMParameterGet(pParameter, &sData); + if (iErr != A3D_SUCCESS) + return; + switch (sData.m_eType) + { + case kA3DParameterType_Information: + { + xml->SetAttribute("Type", "INFORMATION"); + break; + } + case kA3DParameterType_Type: + { + xml->SetAttribute("Type", "TYPE"); + break; + } + case kA3DParameterType_Specification: + { + xml->SetAttribute("Type", "SPECIFICATION"); + break; + } + case kA3DParameterType_FeatureDefinition: + { + xml->SetAttribute("Type", "FEATURE DEFINITION"); + break; + } + case kA3DParameterType_Definition: + { + xml->SetAttribute("Type", "DEFINITION"); + break; + } + case kA3DParameterType_Container: + { + xml->SetAttribute("Type", "CONTAINER"); + break; + } + case kA3DParameterType_ContainerInternal: + { + xml->SetAttribute("Type", "INTERNAL CONTAINER"); + break; + } + case kA3DParameterType_Data: + { + xml->SetAttribute("Type", "DATA"); + break; + } + default: + break; + } + for (A3DUns32 ui = 0; uiLinkEndChild(xml); +} \ No newline at end of file diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLGeometryCrv.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLGeometryCrv.cpp new file mode 100644 index 0000000..8bb0b4f --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLGeometryCrv.cpp @@ -0,0 +1,353 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +#include +#include "PRC2XML.h" + + + +//###################################################################################################################### +static int sttraverseCrvLine(const A3DCrvLine* pCrv, _TiXmlElement* setting) +{ + A3DCrvLineData sData; + A3D_INITIALIZE_DATA(A3DCrvLineData, sData); + + _TiXmlElement* crv = new _TiXmlElement("A3DCrvLineData"); + traverseSource(pCrv, crv); + + A3DInt32 iRet = A3DCrvLineGet(pCrv, &sData); + if(iRet == A3D_SUCCESS) + { + setting->SetAttribute("m_bIs2D", (int)sData.m_bIs2D); + traverseCartesianTransformationData(sData.m_sTrsf, crv); + traverseParam(&sData.m_sParam, crv); + A3DCrvLineGet(NULL, &sData); + } + else + { + crv->SetAttribute("error", iRet); + } + + setting->LinkEndChild(crv); + return iRet; +} + +//###################################################################################################################### +static int sttraverseCrvCircle(const A3DCrvCircle* pCrv, _TiXmlElement* setting) +{ + A3DCrvCircleData sData; + A3D_INITIALIZE_DATA(A3DCrvCircleData, sData); + + _TiXmlElement* crv = new _TiXmlElement("A3DCrvCircleData"); + traverseSource(pCrv, crv); + + A3DInt32 iRet = A3DCrvCircleGet(pCrv, &sData); + if(iRet == A3D_SUCCESS) + { + setting->SetAttribute("m_bIs2D", (int)sData.m_bIs2D); + traverseCartesianTransformationData(sData.m_sTrsf, crv); + traverseParam(&sData.m_sParam, crv); + _SetDoubleAttribute(crv,"m_dRadius", sData.m_dRadius); + A3DCrvCircleGet(NULL, &sData); + } + else + { + crv->SetAttribute("error", iRet); + } + + setting->LinkEndChild(crv); + return iRet; +} + +//###################################################################################################################### +static int sttraverseCrvEllipse(const A3DCrvEllipse* pCrv, _TiXmlElement* setting) +{ + A3DCrvEllipseData sData; + A3D_INITIALIZE_DATA(A3DCrvEllipseData, sData); + + _TiXmlElement* crv = new _TiXmlElement("A3DCrvEllipseData"); + traverseSource(pCrv, crv); + + A3DInt32 iRet = A3DCrvEllipseGet(pCrv, &sData); + if(iRet == A3D_SUCCESS) + { + setting->SetAttribute("m_bIs2D", (int)sData.m_bIs2D); + traverseCartesianTransformationData(sData.m_sTrsf, crv); + traverseParam(&sData.m_sParam, crv); + _SetDoubleAttribute(crv,"m_dXRadius", sData.m_dXRadius); + _SetDoubleAttribute(crv,"m_dYRadius", sData.m_dYRadius); + A3DCrvEllipseGet(NULL, &sData); + } + else + { + crv->SetAttribute("error", iRet); + } + + setting->LinkEndChild(crv); + return iRet; +} + +//###################################################################################################################### +static int sttraverseCrvParabola(const A3DCrvParabola* pCrv, _TiXmlElement* setting) +{ + A3DCrvParabolaData sData; + A3D_INITIALIZE_DATA(A3DCrvParabolaData, sData); + + _TiXmlElement* crv = new _TiXmlElement("A3DCrvParabolaData"); + traverseSource(pCrv, crv); + + A3DInt32 iRet = A3DCrvParabolaGet(pCrv, &sData); + if(iRet == A3D_SUCCESS) + { + setting->SetAttribute("m_bIs2D", (int)sData.m_bIs2D); + traverseCartesianTransformationData(sData.m_sTrsf, crv); + traverseParam(&sData.m_sParam, crv); + _SetDoubleAttribute(crv,"m_dFocal", sData.m_dFocal); + crv->SetAttribute("m_cParamType", (int) sData.m_cParamType); + A3DCrvParabolaGet(NULL, &sData); + } + else + { + crv->SetAttribute("error", iRet); + } + + setting->LinkEndChild(crv); + return iRet; +} + +//###################################################################################################################### +static int sttraverseCrvHyperbola(const A3DCrvHyperbola* pCrv, _TiXmlElement* setting) +{ + A3DCrvHyperbolaData sData; + A3D_INITIALIZE_DATA(A3DCrvHyperbolaData, sData); + + _TiXmlElement* crv = new _TiXmlElement("A3DCrvHyperbolaData"); + traverseSource(pCrv, crv); + + A3DInt32 iRet = A3DCrvHyperbolaGet(pCrv, &sData); + if(iRet == A3D_SUCCESS) + { + setting->SetAttribute("m_bIs2D", (int)sData.m_bIs2D); + traverseCartesianTransformationData(sData.m_sTrsf, crv); + traverseParam(&sData.m_sParam, crv); + _SetDoubleAttribute(crv,"m_dSemiAxis", sData.m_dSemiAxis); + _SetDoubleAttribute(crv,"m_dSemiImageAxis", sData.m_dSemiImageAxis); + crv->SetAttribute("m_cParamType", (int) sData.m_cParamType); + A3DCrvHyperbolaGet(NULL, &sData); + } + else + { + crv->SetAttribute("error", iRet); + } + + setting->LinkEndChild(crv); + return iRet; +} + +//###################################################################################################################### +static int sttraverseCrvHelix(const A3DCrvHelix* pCrv, _TiXmlElement* setting) +{ + A3DCrvHelixData sData; + A3D_INITIALIZE_DATA(A3DCrvHelixData, sData); + + _TiXmlElement* crv = new _TiXmlElement("A3DCrvHelixData"); + traverseSource(pCrv, crv); + + A3DInt32 iRet = A3DCrvHelixGet(pCrv, &sData); + if(iRet == A3D_SUCCESS) + { + setting->SetAttribute("m_bIs2D", (int)sData.m_bIs2D); + A3DCrvHelixGet(NULL, &sData); + } + else + { + crv->SetAttribute("error", iRet); + } + + setting->LinkEndChild(crv); + return iRet; +} + +//###################################################################################################################### +static int sttraverseCrvPolyLine(const A3DCrvPolyLine* pCrv, _TiXmlElement* setting) +{ + A3DCrvPolyLineData sData; + A3D_INITIALIZE_DATA(A3DCrvPolyLineData, sData); + + _TiXmlElement* crv = new _TiXmlElement("A3DCrvPolyLineData"); + traverseSource(pCrv, crv); + + A3DInt32 iRet = A3DCrvPolyLineGet(pCrv, &sData); + if(iRet == A3D_SUCCESS) + { + setting->SetAttribute("m_bIs2D", (int)sData.m_bIs2D); + traverseCartesianTransformationData(sData.m_sTrsf, crv); + traverseParam(&sData.m_sParam, crv); + traversePoints("m_pPts", sData.m_uiSize, sData.m_pPts, crv); + + A3DCrvPolyLineGet(NULL, &sData); + } + else + { + crv->SetAttribute("error", iRet); + } + + setting->LinkEndChild(crv); + return iRet; +} + +//###################################################################################################################### +static int sttraverseCrvComposite(const A3DCrvComposite* pCrv, _TiXmlElement* setting) +{ + A3DCrvCompositeData sData; + A3D_INITIALIZE_DATA(A3DCrvCompositeData, sData); + + _TiXmlElement* crv = new _TiXmlElement("A3DCrvCompositeData"); + traverseSource(pCrv, crv); + + A3DInt32 iRet = A3DCrvCompositeGet(pCrv, &sData); + if(iRet == A3D_SUCCESS) + { + setting->SetAttribute("m_bIs2D", (int)sData.m_bIs2D); + traverseCartesianTransformationData(sData.m_sTrsf, crv); + traverseParam(&sData.m_sParam, crv); + crv->SetAttribute("m_bClosed", (int) sData.m_bClosed); + traverseBools("m_pbSenses", sData.m_uiSize, sData.m_pbSenses, crv); + + A3DUns32 ui, uiSize = sData.m_uiSize; + for(ui = 0; ui < uiSize; ++ui) + traverseCurve(sData.m_ppCurves[ui], crv); + + A3DCrvCompositeGet(NULL, &sData); + } + else + { + crv->SetAttribute("error", iRet); + } + + setting->LinkEndChild(crv); + return iRet; +} + +//###################################################################################################################### +static int sttraverseCrvNurbsData(const A3DCrvNurbsData& sData, _TiXmlElement* setting) +{ + setting->SetAttribute("m_bIs2D", (int) sData.m_bIs2D); + setting->SetAttribute("m_bRational", (int) sData.m_bRational); + setting->SetAttribute("m_eKnotType", (int) sData.m_eKnotType); + setting->SetAttribute("m_eCurveForm", (int) sData.m_eCurveForm); + setting->SetAttribute("m_uiDegree", (int) sData.m_uiDegree); + traverseDoubles("m_pdKnots",sData.m_uiKnotSize, sData.m_pdKnots, setting); + traversePoints("m_pCtrlPts",sData.m_uiCtrlSize, sData.m_pCtrlPts, setting); + + if(sData.m_bRational) + traverseDoubles("m_pdWeights", sData.m_uiWeightSize, sData.m_pdWeights, setting); + + return A3D_SUCCESS; +} + +//###################################################################################################################### +static int sttraverseCrvNurbs(const A3DCrvNurbs* pCrv, _TiXmlElement* setting) +{ + A3DCrvNurbsData sData; + A3D_INITIALIZE_DATA(A3DCrvNurbsData, sData); + + _TiXmlElement* crv = new _TiXmlElement("A3DCrvNurbsData"); + traverseSource(pCrv, crv); + + A3DInt32 iRet = A3DCrvNurbsGet(pCrv, &sData); + if(iRet == A3D_SUCCESS) + { + sttraverseCrvNurbsData(sData, crv); + CHECK_RET(A3DCrvNurbsGet(NULL, &sData)); + } + else + { + crv->SetAttribute("error", iRet); + } + + setting->LinkEndChild(crv); + return iRet; +} + +//###################################################################################################################### +static int sttraverseCrvAsNurbs(const A3DCrvBase* pCrv, _TiXmlElement* setting) +{ + A3DCrvNurbsData sData; + A3D_INITIALIZE_DATA(A3DCrvNurbsData, sData); + + A3DDouble dTolerance=1e-3; + A3DInt32 iRet = A3DCrvBaseGetAsNurbs(pCrv, dTolerance, true, &sData); + if(iRet == A3D_SUCCESS) + { + sttraverseCrvNurbsData(sData, setting); + CHECK_RET(A3DCrvNurbsGet(NULL, &sData)); + } + else + { + setting->SetAttribute("error", iRet); + } + + return iRet; +} + +//###################################################################################################################### +int traverseCurve(const A3DCrvBase* pCrv, _TiXmlElement* setting) +{ + _TiXmlElement* crv = new _TiXmlElement("A3DCrvBase"); + traverseSource(pCrv, crv); + + A3DEEntityType eType; + A3DInt32 iRet = A3DEntityGetType(pCrv,&eType); + if(iRet == A3D_SUCCESS) + { + switch(eType) + { + case kA3DTypeCrvNurbs: + iRet = sttraverseCrvNurbs(pCrv, crv); + break; + case kA3DTypeCrvLine: + iRet = sttraverseCrvLine(pCrv, crv); + break; + case kA3DTypeCrvCircle: + iRet = sttraverseCrvCircle(pCrv, crv); + break; + case kA3DTypeCrvEllipse: + iRet = sttraverseCrvEllipse(pCrv, crv); + break; + case kA3DTypeCrvParabola: + iRet = sttraverseCrvParabola(pCrv, crv); + break; + case kA3DTypeCrvHyperbola: + iRet = sttraverseCrvHyperbola(pCrv, crv); + break; + case kA3DTypeCrvHelix: + iRet = sttraverseCrvHelix(pCrv, crv); + break; + case kA3DTypeCrvPolyLine: + iRet = sttraverseCrvPolyLine(pCrv, crv); + break; + case kA3DTypeCrvComposite: + iRet = sttraverseCrvComposite(pCrv, crv); + break; + default: + iRet = sttraverseCrvAsNurbs(pCrv, crv); + break; + } + } + A3DIntervalData oInterval; + A3D_INITIALIZE_DATA(A3DIntervalData, oInterval); + A3DCrvGetInterval(pCrv, &oInterval); + _SetDoubleAttribute(crv, "m_dMin", oInterval.m_dMin); + _SetDoubleAttribute(crv, "m_dMax", oInterval.m_dMax); + + setting->LinkEndChild(crv); + return iRet; +} diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLGeometrySrf.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLGeometrySrf.cpp new file mode 100644 index 0000000..c153944 --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLGeometrySrf.cpp @@ -0,0 +1,142 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "PRC2XML.h" + + + +//###################################################################################################################### +static int sttraverseSrfNurbsData(const A3DSurfNurbsData& sData, _TiXmlElement* setting) +{ + setting->SetAttribute("m_eKnotType", (int) sData.m_eKnotType); + setting->SetAttribute("m_eSurfaceForm", (int) sData.m_eSurfaceForm); + setting->SetAttribute("m_uiUDegree", (int) sData.m_uiUDegree); + setting->SetAttribute("m_uiVDegree", (int) sData.m_uiVDegree); + + traverseDoubles("m_pdUKnots", sData.m_uiUKnotSize, sData.m_pdUKnots, setting); + traverseDoubles("m_pdVKnots", sData.m_uiVKnotSize, sData.m_pdVKnots, setting); + traversePoints("m_pCtrlPts", sData.m_uiUCtrlSize*sData.m_uiVCtrlSize, sData.m_pCtrlPts, setting); + + if(sData.m_pdWeights) + traverseDoubles("m_pdWeights", sData.m_uiUCtrlSize*sData.m_uiVCtrlSize, sData.m_pdWeights, setting); + + return A3D_SUCCESS; +} + +//###################################################################################################################### +static int sttraverseSrfNurbs(const A3DSurfNurbs* pSrf, _TiXmlElement* setting) +{ + A3DSurfNurbsData sData; + A3D_INITIALIZE_DATA(A3DSurfNurbsData, sData); + + _TiXmlElement* srf = new _TiXmlElement("A3DSurfNurbsData"); + traverseSource(pSrf, srf); + + A3DInt32 iRet = A3DSurfNurbsGet(pSrf, &sData); + if(iRet == A3D_SUCCESS) + { + sttraverseSrfNurbsData(sData, srf); + CHECK_RET(A3DSurfNurbsGet(NULL, &sData)); + } + else + { + srf->SetAttribute("error", iRet); + } + + setting->LinkEndChild(srf); + return iRet; +} + +//###################################################################################################################### +static int sttraverseSrfAsNurbs(const A3DSurfBase* pSrf, _TiXmlElement* setting) +{ + A3DSurfNurbsData sData; + A3D_INITIALIZE_DATA(A3DSurfNurbsData, sData); + + A3DDouble dTolerance = 1e-3; + A3DInt32 iRet = A3DSurfBaseGetAsNurbs(pSrf,dTolerance, false, &sData); + if(iRet == A3D_SUCCESS) + { + sttraverseSrfNurbsData(sData, setting); + CHECK_RET(A3DSurfNurbsGet(NULL, &sData)); + } + else + { + setting->SetAttribute("error", iRet); + } + + return iRet; +} + +//###################################################################################################################### +int traverseSrfPlane(const A3DSurfPlane* pSrf, _TiXmlElement* setting) +{ + A3DSurfPlaneData sData; + A3D_INITIALIZE_DATA(A3DSurfPlaneData, sData); + + _TiXmlElement* srf = new _TiXmlElement("A3DSurfPlaneData"); + traverseSource(pSrf, srf); + + A3DInt32 iRet = A3DSurfPlaneGet(pSrf, &sData); + if(iRet == A3D_SUCCESS) + { + traverseCartesianTransformationData(sData.m_sTrsf, srf); + traverseUVParam(&sData.m_sParam, srf); + + CHECK_RET(A3DSurfPlaneGet(NULL, &sData)); + } + else + { + srf->SetAttribute("error", iRet); + } + + setting->LinkEndChild(srf); + return iRet; +} + +//###################################################################################################################### +int traverseSurface(const A3DSurfBase* pSrf, _TiXmlElement* setting) +{ + _TiXmlElement* srf = new _TiXmlElement("A3DSurfBase"); + traverseSource(pSrf, srf); + + A3DEEntityType eType; + A3DInt32 iRet = A3DEntityGetType(pSrf, &eType); + if(iRet == A3D_SUCCESS) + { + switch(eType) + { + case kA3DTypeSurfNurbs: + iRet = sttraverseSrfNurbs(pSrf, srf); + break; + case kA3DTypeSurfPlane: + iRet = traverseSrfPlane(pSrf, srf); + break; + default: + break; + } + } + else if(iRet == A3D_NOT_IMPLEMENTED) + iRet = sttraverseSrfAsNurbs(pSrf, srf); + + A3DDomainData oDomain; + A3D_INITIALIZE_DATA(A3DDomainData, oDomain); + CHECK_RET(A3DSurfGetDomain(pSrf, &oDomain)); + _SetDoubleAttribute(srf, "m_sMin.m_dX", oDomain.m_sMin.m_dX); + _SetDoubleAttribute(srf, "m_sMin.m_dY", oDomain.m_sMin.m_dY); + _SetDoubleAttribute(srf, "m_sMax.m_dX", oDomain.m_sMax.m_dX); + _SetDoubleAttribute(srf, "m_sMax.m_dY", oDomain.m_sMax.m_dY); + + setting->LinkEndChild(srf); + + return iRet; +} diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLGlobal.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLGlobal.cpp new file mode 100644 index 0000000..80818d2 --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLGlobal.cpp @@ -0,0 +1,407 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "PRC2XML.h" + +int traverseUnit(A3DMiscAttributeUnit* const pUnit, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + A3DMiscAttributeUnitData sDataUnit; + A3D_INITIALIZE_DATA(A3DMiscAttributeUnitData, sDataUnit); + + _TiXmlElement* unit = new _TiXmlElement("A3DMiscAttributeUnit"); + + CHECK_RET(A3DGlobalGetUnitData(pUnit, &sDataUnit)); + + if (sDataUnit.m_pcName && sDataUnit.m_pcName[0] != '\0') + unit->SetAttribute("m_pcName", sDataUnit.m_pcName); + + for (auto uj = 0u; uj < sDataUnit.m_uiBasicUnitSize; uj++) + { + _TiXmlElement* basicunit = new _TiXmlElement("A3DMiscAttributeBasicUnit"); + basicunit->SetAttribute("m_eUnit", (int)sDataUnit.m_ppBasicUnits[uj]->m_eUnit); + basicunit->SetAttribute("m_iExponent", (int)sDataUnit.m_ppBasicUnits[uj]->m_iExponent); + basicunit->SetAttribute("m_dFactor", (int)sDataUnit.m_ppBasicUnits[uj]->m_dFactor); + unit->LinkEndChild(basicunit); + } + A3DGlobalGetUnitData(NULL, &sDataUnit); + + setting->LinkEndChild(unit); + + return iRet; +} + +//###################################################################################################################### +int traverseDottingPattern(const A3DGraphDottingPatternData& sData, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + + _TiXmlElement* pattern = new _TiXmlElement("A3DGraphDottingPatternData"); + + _SetDoubleAttribute(pattern, "m_dPitch", (double) sData.m_dPitch); + pattern->SetAttribute("m_bZigZag", (int) sData.m_bZigZag); + pattern->SetAttribute("m_uiColorIndex", (int) sData.m_uiColorIndex); + pattern->SetAttribute("m_uiNextPatternIndex", (int) sData.m_uiNextPatternIndex); + + setting->LinkEndChild(pattern); + return iRet; +} + +//###################################################################################################################### +int traverseHatchingPattern(const A3DGraphHatchingPatternData& sData, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + + _TiXmlElement *pattern= new _TiXmlElement("A3DGraphHatchingPatternData"); + + A3DUns32 ui, uiSize = sData.m_uiSize; + for(ui = 0; ui < uiSize; ++ui) + { + _TiXmlElement* hatchline = new _TiXmlElement("A3DGraphHatchingPatternLineData"); + _SetDoubleAttribute(hatchline, "m_dAngle", (double) sData.m_psHatchLines[ui].m_dAngle); + hatchline->SetAttribute("m_uiStyleIndex", (int) sData.m_psHatchLines[ui].m_uiStyleIndex); + traversePoint2d("m_sStart" , sData.m_psHatchLines[ui].m_sStart, hatchline); + traversePoint2d("m_sOffset", sData.m_psHatchLines[ui].m_sOffset, hatchline); + pattern->LinkEndChild(hatchline); + } + pattern->SetAttribute("m_uiNextPatternIndex", (int) sData.m_uiNextPatternIndex); + + setting->LinkEndChild(pattern); + return iRet; +} + +//###################################################################################################################### +int traverseSolidPattern(const A3DGraphSolidPatternData& sData, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + + _TiXmlElement* pattern = new _TiXmlElement("A3DGraphSolidPatternData"); + + pattern->SetAttribute("m_bMaterial", (int) sData.m_bMaterial); + pattern->SetAttribute("m_uiRgbColorIndex", (int) sData.m_uiRgbColorIndex); + pattern->SetAttribute("m_uiNextPatternIndex", (int) sData.m_uiNextPatternIndex); + + setting->LinkEndChild(pattern); + return iRet; +} + +//###################################################################################################################### +int traverseVPicturePattern(const A3DGraphVPicturePatternData& sData, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + + _TiXmlElement* pattern = new _TiXmlElement("A3DGraphVPicturePatternData"); + pattern->SetAttribute("m_uiNextPatternIndex", (int) sData.m_uiNextPatternIndex); + + traverseMarkupTess(sData.m_pMarkupTess, pattern); + + setting->LinkEndChild(pattern); + return iRet; +} + +//###################################################################################################################### +//static bool stMakeFileWithBinarydata(A3DUns32 uiSize, A3DUns8* const pucBinaryData, const A3DUTF8Char* psFileName) +//{ +// FILE* psFile = fopen(psFileName, "wb"); +// if(psFile != NULL) +// { +// int iFileSize = uiSize; +// fwrite(pucBinaryData, sizeof(char), size_t(iFileSize), psFile); +// fclose(psFile); +// return true; +// } +// return false; +//} + +//###################################################################################################################### +int traversePicture(const A3DGraphPictureData& sData, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + + _TiXmlElement* picture = new _TiXmlElement("A3DGraphPictureData"); + + picture->SetAttribute("m_eFormat", (int) sData.m_eFormat); + picture->SetAttribute("m_uiPixelWidth", (int) sData.m_uiPixelWidth); + picture->SetAttribute("m_uiPixelHeight", (int) sData.m_uiPixelHeight); + //stMakeFileWithBinarydata(sData.m_uiSize,sData.m_pucBinaryData,"myfilename"); + + setting->LinkEndChild(picture); + return iRet; +} + +//###################################################################################################################### +int traverseMaterial(const A3DGraphMaterialData& sData, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + + _TiXmlElement* material = new _TiXmlElement("A3DGraphMaterialData"); + + _SetDoubleAttribute(material, "m_dAmbientAlpha", sData.m_dAmbientAlpha); + _SetDoubleAttribute(material, "m_dDiffuseAlpha", sData.m_dDiffuseAlpha); + _SetDoubleAttribute(material, "m_dEmissiveAlpha", sData.m_dEmissiveAlpha); + _SetDoubleAttribute(material, "m_dSpecularAlpha", sData.m_dSpecularAlpha); + _SetDoubleAttribute(material, "m_dShininess", sData.m_dShininess); + + material->SetAttribute("m_uiAmbient", (int) sData.m_uiAmbient); + material->SetAttribute("m_uiDiffuse", (int) sData.m_uiDiffuse); + material->SetAttribute("m_uiEmissive", (int) sData.m_uiEmissive); + material->SetAttribute("m_uiSpecular", (int) sData.m_uiSpecular); + + setting->LinkEndChild(material); + return iRet; +} + +//###################################################################################################################### +int traverseLinePattern(const A3DGraphLinePatternData& sData, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + + _TiXmlElement* linepattern = new _TiXmlElement("A3DGraphLinePatternData"); + traverseDoubles("m_pdLengths", sData.m_uiNumberOfLengths, sData.m_pdLengths, linepattern); + _SetDoubleAttribute(linepattern, "m_dPhase", sData.m_dPhase); + linepattern->SetAttribute("m_bRealLength", (int) sData.m_bRealLength); + + setting->LinkEndChild(linepattern); + return iRet; +} + +//###################################################################################################################### +int traverseStyle(const A3DGraphStyleData& sStyleData, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + + _TiXmlElement* style = new _TiXmlElement("A3DGraphStyleData"); + + style->SetAttribute("m_bMaterial", (int) sStyleData.m_bMaterial); + style->SetAttribute("m_uiRgbColorIndex", (int) sStyleData.m_uiRgbColorIndex); + style->SetAttribute("m_bVPicture", (int) sStyleData.m_bVPicture); + style->SetAttribute("m_uiLinePatternIndex", (int) sStyleData.m_uiLinePatternIndex); + + if(sStyleData.m_bIsTransparencyDefined) + style->SetAttribute("m_ucTransparency", (int) sStyleData.m_ucTransparency); + + _SetDoubleAttribute(style, "m_dWidth", sStyleData.m_dWidth); + + style->SetAttribute("m_bSpecialCulling", (int)sStyleData.m_bSpecialCulling); + style->SetAttribute("m_bFrontCulling", (int)sStyleData.m_bFrontCulling); + style->SetAttribute("m_bBackCulling", (int)sStyleData.m_bBackCulling); + style->SetAttribute("m_bNoLight", (int)sStyleData.m_bNoLight); + style->SetAttribute("m_eRenderingMode", (int)sStyleData.m_eRenderingMode); + + setting->LinkEndChild(style); + return iRet; +} + +//###################################################################################################################### +int traverseGlobal(const A3DGlobal* pGlobal, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + A3DGlobalData sData; + A3D_INITIALIZE_DATA(A3DGlobalData, sData); + + _TiXmlElement* global = new _TiXmlElement("A3DGlobalData"); + + iRet = A3DGlobalGet(pGlobal, &sData); + if(iRet == A3D_SUCCESS) + { + int traverseBase(const A3DEntity* pEntity, _TiXmlElement* setting); + A3DUns32 ui, uiSize = sData.m_uiColorsSize; + if(uiSize) + { + A3DGraphRgbColorData sColorData; + A3D_INITIALIZE_DATA(A3DGraphRgbColorData, sColorData); + A3DDouble* pdAllColors = (A3DDouble*) malloc(size_t(uiSize) * 3 * sizeof(A3DDouble)); + if (pdAllColors) + { + for(ui = 0; ui < uiSize; ++ui) + { + CHECK_RET(A3DGlobalGetGraphRgbColorData(ui*3, &sColorData)); + pdAllColors[3*ui] = sColorData.m_dRed; + pdAllColors[3*ui+1] = sColorData.m_dGreen; + pdAllColors[3*ui+2] = sColorData.m_dBlue; + } + traverseDoubles("Colors", uiSize*3, pdAllColors, global); + free(pdAllColors); + } + } + + if(sData.m_uiStylesSize) + { + uiSize = sData.m_uiStylesSize; + A3DGraphStyleData sStyleData; + A3D_INITIALIZE_DATA(A3DGraphStyleData, sStyleData); + for(ui = 0; ui < uiSize; ++ui) + { + CHECK_RET(A3DGlobalGetGraphStyleData(ui, &sStyleData)); + traverseStyle(sStyleData, global); + A3DGlobalGetGraphStyleData(A3D_DEFAULT_STYLE_INDEX, &sStyleData); + } + } + + if(sData.m_uiLinePatternsSize) + { + uiSize = sData.m_uiLinePatternsSize; + A3DGraphLinePatternData sLinePatternData; + A3D_INITIALIZE_DATA(A3DGraphLinePatternData, sLinePatternData); + + for(ui = 0; ui < uiSize; ++ui) + { + CHECK_RET(A3DGlobalGetGraphLinePatternData(ui, &sLinePatternData)); + traverseLinePattern(sLinePatternData, global); + A3DGlobalGetGraphLinePatternData(A3D_DEFAULT_LINEPATTERN_INDEX, &sLinePatternData); + } + } + + if(sData.m_uiMaterialsSize) + { + uiSize= sData.m_uiMaterialsSize; + + A3DBool bIsTexture; + for(ui = 0; ui < uiSize; ++ui) + { + CHECK_RET(A3DGlobalIsMaterialTexture(ui, &bIsTexture)); + + if(bIsTexture) + { + A3DGraphTextureApplicationData sTextureApplicationData; + A3D_INITIALIZE_DATA(A3DGraphTextureApplicationData, sTextureApplicationData); + CHECK_RET(A3DGlobalGetGraphTextureApplicationData(ui, &sTextureApplicationData)); + traverseTextureApplication(sTextureApplicationData, global); + A3DGlobalGetGraphTextureApplicationData(A3D_DEFAULT_MATERIAL_INDEX, &sTextureApplicationData); + } + else + { + _TiXmlElement* material = new _TiXmlElement("A3DGraphMaterial"); + material->SetAttribute("index", ui); + + A3DEntity* pMaterial = NULL; + CHECK_RET(A3DMiscPointerFromIndexGet(ui, kA3DTypeGraphMaterial, &pMaterial)) + if (pMaterial) + traverseBase(pMaterial, material); + + A3DGraphMaterialData sMaterialData; + A3D_INITIALIZE_DATA(A3DGraphMaterialData, sMaterialData); + CHECK_RET(A3DGlobalGetGraphMaterialData(ui, &sMaterialData)); + traverseMaterial(sMaterialData, material); + A3DGlobalGetGraphMaterialData(A3D_DEFAULT_MATERIAL_INDEX, &sMaterialData); + + global->LinkEndChild(material); + } + } + } + + if(sData.m_uiTextureDefinitionsSize) + { + uiSize = sData.m_uiTextureDefinitionsSize; + A3DGraphTextureDefinitionData sTextureDefinitionData; + A3D_INITIALIZE_DATA(A3DGraphTextureDefinitionData, sTextureDefinitionData); + for(ui = 0; ui < uiSize; ++ui) + { + CHECK_RET(A3DGlobalGetGraphTextureDefinitionData(ui, &sTextureDefinitionData)); + traverseTextureDefinition(sTextureDefinitionData, global); + A3DGlobalGetGraphTextureDefinitionData(A3D_DEFAULT_TEXTURE_DEFINITION_INDEX, &sTextureDefinitionData); + } + } + + if(sData.m_uiPicturesSize) + { + uiSize = sData.m_uiPicturesSize; + A3DGraphPictureData sPictureData; + A3D_INITIALIZE_DATA(A3DGraphPictureData, sPictureData); + + for(ui = 0; ui < uiSize; ++ui) + { + _TiXmlElement* picture = new _TiXmlElement("A3DGraphPicture"); + picture->SetAttribute("index", ui); + + A3DEntity* pPicture = NULL; + CHECK_RET(A3DMiscPointerFromIndexGet(ui, kA3DTypeGraphPicture, &pPicture)) + if (pPicture) + traverseBase(pPicture, picture); + + CHECK_RET(A3DGlobalGetGraphPictureData(ui, &sPictureData)); + traversePicture(sPictureData, picture); + A3DGlobalGetGraphPictureData(A3D_DEFAULT_MATERIAL_INDEX, &sPictureData); + + global->LinkEndChild(picture); + } + } + + if(sData.m_uiFillPatternsSize) + { + uiSize = sData.m_uiFillPatternsSize; + A3DEEntityType ePatternType; + for(ui = 0; ui < uiSize; ++ui) + { + CHECK_RET(A3DGlobalGetFillPatternType(ui, &ePatternType)); + + switch(ePatternType) + { + case kA3DTypeGraphHatchingPattern: + A3DGraphHatchingPatternData sHatchingPatternData; + A3D_INITIALIZE_DATA(A3DGraphHatchingPatternData, sHatchingPatternData); + CHECK_RET(A3DGlobalGetGraphHatchingPatternData(ui, &sHatchingPatternData)); + iRet = traverseHatchingPattern(sHatchingPatternData, global); + A3DGlobalGetGraphHatchingPatternData(A3D_DEFAULT_PATTERN_INDEX, &sHatchingPatternData); + break; + + case kA3DTypeGraphSolidPattern: + A3DGraphSolidPatternData sSolidPatternData; + A3D_INITIALIZE_DATA(A3DGraphSolidPatternData, sSolidPatternData); + CHECK_RET(A3DGlobalGetGraphSolidPatternData(ui, &sSolidPatternData)); + iRet = traverseSolidPattern(sSolidPatternData, global); + A3DGlobalGetGraphSolidPatternData(A3D_DEFAULT_PATTERN_INDEX, &sSolidPatternData); + break; + + case kA3DTypeGraphDottingPattern: + A3DGraphDottingPatternData sDottingPatternData; + A3D_INITIALIZE_DATA(A3DGraphDottingPatternData, sDottingPatternData); + CHECK_RET(A3DGlobalGetGraphDottingPatternData(ui, &sDottingPatternData)); + iRet = traverseDottingPattern(sDottingPatternData, global); + A3DGlobalGetGraphDottingPatternData(A3D_DEFAULT_PATTERN_INDEX, &sDottingPatternData); + break; + + case kA3DTypeGraphVPicturePattern: + A3DGraphVPicturePatternData sVPicturePatternData; + A3D_INITIALIZE_DATA(A3DGraphVPicturePatternData, sVPicturePatternData); + CHECK_RET(A3DGlobalGetGraphVPicturePatternData(ui, &sVPicturePatternData)); + iRet = traverseVPicturePattern(sVPicturePatternData, global); + A3DGlobalGetGraphVPicturePatternData(A3D_DEFAULT_PATTERN_INDEX, &sVPicturePatternData); + break; + + default: + break; + } + } + } + + if (sData.m_uiUnitsSize) + { + uiSize = sData.m_uiUnitsSize; + + for (ui = 0; ui < uiSize; ++ui) + { + A3DMiscAttributeUnit *pUnit = nullptr; + CHECK_RET(A3DGlobalGetUnit(ui, &pUnit)); + + traverseUnit(pUnit, global); + } + } + } + else + { + global->SetAttribute("error", iRet); + } + + setting->LinkEndChild(global); + return iRet; +} diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLIfcRelationships.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLIfcRelationships.cpp new file mode 100644 index 0000000..be36e7c --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLIfcRelationships.cpp @@ -0,0 +1,215 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "PRC2XML.h" + + +//###################################################################################################################### +void sttraverseIFCRootEntity(A3DBIMRoot* pRoot, _TiXmlElement* element) +{ + A3DBIMRootData sData; + A3D_INITIALIZE_DATA(A3DBIMRootData, sData); + A3DInt32 iRet = A3DBIMRootGet(pRoot, &sData); + _TiXmlElement* root = new _TiXmlElement(sData.m_pcIfcClassName ? sData.m_pcIfcClassName : "Element"); + element->LinkEndChild(root); + + if (iRet == A3D_SUCCESS) + { + if (sData.m_pcGUID) + root->SetAttribute("global_id", sData.m_pcGUID); + else + root->SetAttribute("global_id", "error"); + if (sData.m_pcName) + root->SetAttribute("name", sData.m_pcName); + if (sData.m_pcDescription) + root->SetAttribute("description", sData.m_pcDescription); + if (sData.m_pEntityReference) + { + _TiXmlElement* entity = new _TiXmlElement("Corresponding_A3D"); + root->LinkEndChild(entity); + traverseEntityReference(sData.m_pEntityReference, entity); + } + else + root->SetAttribute("Corresponding_A3D", "error"); + iRet = A3DBIMRootGet(nullptr, &sData); + } +} + +//********************************************************************************************************************** + +void dumpRelationship(A3DBIMRoot* pRelating, A3DUns32 uiRelatedElementSize, A3DBIMRoot** ppRelatedElements, _TiXmlElement* rel) +{ + if (rel == nullptr) + return; + _TiXmlElement* relating = new _TiXmlElement("Relating"); + rel->LinkEndChild(relating); + if (pRelating) + sttraverseIFCRootEntity(pRelating, relating); + else + relating->SetAttribute("relating", "error"); + _TiXmlElement* related = new _TiXmlElement("Related"); + rel->LinkEndChild(related); + char attribName[2048]; + if (uiRelatedElementSize > 0) + { + for (A3DUns32 uj = 0; uj < uiRelatedElementSize; ++uj) + { + if (ppRelatedElements[uj] == nullptr) + { + sprintf(attribName, "related_%d", uj); + related->SetAttribute(attribName, "error"); + continue; + } + sttraverseIFCRootEntity(ppRelatedElements[uj], related); + } + } + else + { + related->SetAttribute("related", "error"); + } +} +//###################################################################################################################### +int dumpRelationships(const A3DBIMData* pBimData, _TiXmlElement* model) +{ + if (pBimData == nullptr || model == nullptr) + return A3D_SUCCESS; + + char attribName[2048]; + A3DUns32 ui; + A3DBIMDataData sBIMData; + A3D_INITIALIZE_DATA(A3DBIMDataData, sBIMData); + CHECK_RET(A3DBIMDataGet(pBimData, &sBIMData)); + _TiXmlElement* bim = new _TiXmlElement("BIM"); + model->LinkEndChild(bim); + for (ui = 0; ui < sBIMData.m_uiRelationshipSize; ++ui) + { + + A3DEEntityType eType = kA3DTypeUnknown; + if( A3DEntityGetType(sBIMData.m_ppRelationships[ui], &eType) != A3D_SUCCESS) + { + bim->SetAttribute("Ifc_relationship", "error: unknown type"); + continue; + } + if (eType == kA3DTypeBIMRelContainedInSpatialStructure) + { + A3DBIMRelContainedInSpatialStructureData sRelData; + A3D_INITIALIZE_DATA(A3DBIMRelContainedInSpatialStructureData, sRelData); + if (A3DBIMRelContainedInSpatialStructureGet(sBIMData.m_ppRelationships[ui], &sRelData) == A3D_SUCCESS) + { + _TiXmlElement* rel = new _TiXmlElement("A3DBIMRelContainedInSpatialStructure"); + bim->LinkEndChild(rel); + dumpRelationship(sRelData.m_pRelating, sRelData.m_uiRelatedElementSize, sRelData.m_ppRelatedElements, rel); + A3DBIMRelContainedInSpatialStructureGet(nullptr, &sRelData); + } + else + { + sprintf(attribName, "kA3DTypeBIMRelContainedInSpatialStructure_%d", ui); + bim->SetAttribute(attribName, "error"); + } + + } + else if (eType == kA3DTypeBIMRelAggregates) + { + A3DBIMRelAggregatesData sRelData; + A3D_INITIALIZE_DATA(A3DBIMRelAggregatesData, sRelData); + if (A3DBIMRelAggregatesGet(sBIMData.m_ppRelationships[ui], &sRelData) == A3D_SUCCESS) + { + _TiXmlElement* rel = new _TiXmlElement("A3DBIMRelAggregates"); + bim->LinkEndChild(rel); + dumpRelationship(sRelData.m_pRelating, sRelData.m_uiRelatedElementSize, sRelData.m_ppRelatedElements, rel); + A3DBIMRelAggregatesGet(nullptr, &sRelData); + } + else + { + sprintf(attribName, "kA3DTypeBIMRelAggregates_%d", ui); + bim->SetAttribute(attribName, "error"); + } + } + else if (eType == kA3DTypeBIMRelFillsElement) + { + A3DBIMRelFillsElementData sRelData; + A3D_INITIALIZE_DATA(A3DBIMRelFillsElementData, sRelData); + if (A3DBIMRelFillsElementGet(sBIMData.m_ppRelationships[ui], &sRelData) == A3D_SUCCESS) + { + _TiXmlElement* rel = new _TiXmlElement("A3DBIMRelFillsElement"); + bim->LinkEndChild(rel); + dumpRelationship(sRelData.m_pRelating, sRelData.m_uiRelatedElementSize, sRelData.m_ppRelatedElements, rel); + A3DBIMRelFillsElementGet(nullptr, &sRelData); + } + else + { + sprintf(attribName, "kA3DTypeBIMRelFillsElement_%d", ui); + bim->SetAttribute(attribName, "error"); + } + } + else if (eType == kA3DTypeBIMRelVoidsElement) + { + A3DBIMRelVoidsElementData sRelData; + A3D_INITIALIZE_DATA(A3DBIMRelVoidsElementData, sRelData); + if (A3DBIMRelVoidsElementGet(sBIMData.m_ppRelationships[ui], &sRelData) == A3D_SUCCESS) + { + _TiXmlElement* rel = new _TiXmlElement("A3DBIMRelVoidsElement"); + bim->LinkEndChild(rel); + dumpRelationship(sRelData.m_pRelating, sRelData.m_uiRelatedElementSize, sRelData.m_ppRelatedElements, rel); + A3DBIMRelVoidsElementGet(nullptr, &sRelData); + } + else + { + sprintf(attribName, "kA3DTypeBIMRelVoidsElement_%d", ui); + bim->SetAttribute(attribName, "error"); + } + } + else if (eType == kA3DTypeBIMRelSpaceBoundary) + { + A3DBIMRelSpaceBoundaryData sRelData; + A3D_INITIALIZE_DATA(A3DBIMRelSpaceBoundaryData, sRelData); + if (A3DBIMRelSpaceBoundaryGet(sBIMData.m_ppRelationships[ui], &sRelData) == A3D_SUCCESS) + { + _TiXmlElement* rel = new _TiXmlElement("A3DBIMRelSpaceBoundary"); + bim->LinkEndChild(rel); + dumpRelationship(sRelData.m_pRelating, sRelData.m_uiRelatedElementSize, sRelData.m_ppRelatedElements, rel); + A3DBIMRelSpaceBoundaryGet(nullptr, &sRelData); + } + else + { + sprintf(attribName, "kA3DTypeBIMRelSpaceBoundary_%d", ui); + bim->SetAttribute(attribName, "error"); + } + } + else if (eType == kA3DTypeBIMRelConnectsPathElements) + { + A3DBIMRelConnectsPathElementsData sRelData; + A3D_INITIALIZE_DATA(A3DBIMRelConnectsPathElementsData, sRelData); + if (A3DBIMRelConnectsPathElementsGet(sBIMData.m_ppRelationships[ui], &sRelData) == A3D_SUCCESS) + { + _TiXmlElement* rel = new _TiXmlElement("A3DBIMRelConnectsPathElementsData"); + bim->LinkEndChild(rel); + dumpRelationship(sRelData.m_pRelating, sRelData.m_uiRelatedElementSize, sRelData.m_ppRelatedElements, rel); + A3DBIMRelConnectsPathElementsGet(nullptr, &sRelData); + } + else + { + sprintf(attribName, "kA3DTypeBIMRelConnectsPathElements_%d", ui); + bim->SetAttribute(attribName, "error"); + } + } + else + { + bim->SetAttribute("Ifc_relationship", "error: new type"); + bim->SetAttribute(attribName, "error"); + } + + } + CHECK_RET(A3DBIMDataGet(nullptr, &sBIMData)); + return A3D_SUCCESS; +} + diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLMarkup.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLMarkup.cpp new file mode 100644 index 0000000..eb9a7d5 --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLMarkup.cpp @@ -0,0 +1,928 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include +#include "PRC2XML.h" + +//###################################################################################################################### +static int stTraverseAnnotationSet(const A3DMkpAnnotationSet* pAnnot, _TiXmlElement* setting) +{ + A3DMkpAnnotationSetData sData; + A3D_INITIALIZE_DATA(A3DMkpAnnotationSetData, sData); + + _TiXmlElement* annotset = new _TiXmlElement("A3DMkpAnnotationSetData"); + traverseSource(pAnnot, annotset); + + A3DInt32 iRet = A3DMkpAnnotationSetGet(pAnnot, &sData); + if(iRet == A3D_SUCCESS) + { + for(A3DUns32 ui = 0; ui < sData.m_uiAnnotationsSize; ++ui) + traverseAnnotation(sData.m_ppAnnotations[ui], annotset); + + A3DMkpAnnotationSetGet(NULL, &sData); + } + else + { + annotset->SetAttribute("error", iRet); + } + setting->LinkEndChild(annotset); + return iRet; +} + +//###################################################################################################################### +static int stTraverseAnnotationReference(const A3DMkpAnnotationReference* pAnnot, _TiXmlElement* setting) +{ + A3DMkpAnnotationReferenceData sData; + A3D_INITIALIZE_DATA(A3DMkpAnnotationReferenceData, sData); + + _TiXmlElement* ref = new _TiXmlElement("A3DMkpAnnotationReferenceData"); + traverseSource(pAnnot, ref); + + A3DInt32 iRet = A3DMkpAnnotationReferenceGet(pAnnot, &sData); + if(iRet == A3D_SUCCESS) + { + for(A3DUns32 ui = 0; ui < sData.m_uiLinkedItemsSize; ++ui) + traverseLinkedItem(sData.m_ppLinkedItems[ui], ref); // => very very useful + + A3DMkpAnnotationReferenceGet(NULL, &sData); + } + else + { + ref->SetAttribute("error", iRet); + } + setting->LinkEndChild(ref); + return iRet; +} + +//###################################################################################################################### +static int stTraverseAnnotationItem(const A3DMkpAnnotationItem* pAnnot, _TiXmlElement* setting) +{ + A3DMkpAnnotationItemData sData; + A3D_INITIALIZE_DATA(A3DMkpAnnotationItemData, sData); + + _TiXmlElement* annotitem = new _TiXmlElement("A3DMkpAnnotationItemData"); + traverseSource(pAnnot, annotitem); + + A3DInt32 iRet = A3DMkpAnnotationItemGet(pAnnot, &sData); + if(iRet == A3D_SUCCESS) + { + traverseMarkup(sData.m_pMarkup, annotitem); + A3DMkpAnnotationItemGet(NULL, &sData); + } + else + { + annotitem->SetAttribute("error", iRet); + } + setting->LinkEndChild(annotitem); + return iRet; +} + +//###################################################################################################################### +int traverseAnnotation(const A3DMkpAnnotationEntity* pAnnot, _TiXmlElement* setting) +{ + A3DEEntityType eType; + A3DInt32 iRet = A3DEntityGetType(pAnnot, &eType); + if(iRet == A3D_SUCCESS) + { + switch(eType) + { + case kA3DTypeMkpAnnotationSet: + return stTraverseAnnotationSet(pAnnot,setting); + case kA3DTypeMkpAnnotationReference: + return stTraverseAnnotationReference(pAnnot,setting); + case kA3DTypeMkpAnnotationItem: + return stTraverseAnnotationItem(pAnnot,setting); + default: + break; + } + } + return A3D_NOT_IMPLEMENTED; +} + +//###################################################################################################################### +int traverseAmbientLight(const A3DGraphAmbientLight *pLight, _TiXmlElement* setting) +{ + if (!pLight) + { + setting->SetAttribute("Light", "Bad cast"); + return -1; + } + _TiXmlElement* light = new _TiXmlElement("A3DGraphAmbientLightData"); + A3DStatus iRet; + A3DGraphAmbientLightData oLight; + A3D_INITIALIZE_DATA(A3DGraphAmbientLightData, oLight); + if ((iRet = A3DGraphAmbientLightGet(pLight, &oLight)) == A3D_SUCCESS) + { + + light->SetAttribute("m_uiAmbientColorIndex", oLight.m_uiAmbientColorIndex); /*!< Ambient color index. */ + light->SetAttribute("m_uiDiffuseColorIndex", oLight.m_uiDiffuseColorIndex); /*!< Diffuse color index. */ + light->SetAttribute("m_uiSpecularColorIndex", oLight.m_uiSpecularColorIndex); /*!< Specular color index. */ + A3DGraphAmbientLightGet(NULL, &oLight); + } + else + { + light->SetAttribute("Error", iRet); + } + setting->LinkEndChild(light); + return 0; +} + +//###################################################################################################################### +int traversePointLight(const A3DGraphPointLight* pLight, _TiXmlElement* setting) +{ + if (!pLight) + { + setting->SetAttribute("Light", "Bad cast"); + return -1; + } + + _TiXmlElement* light = new _TiXmlElement("A3DGraphPointLightData"); + A3DStatus iRet; + A3DGraphPointLightData oLight; + A3D_INITIALIZE_DATA(A3DGraphPointLightData, oLight); + if ((iRet = A3DGraphPointLightGet(pLight, &oLight)) == A3D_SUCCESS) + { + light->SetAttribute("m_uiAmbientColorIndex", oLight.m_uiAmbientColorIndex); /*!< Ambient color index. */ + light->SetAttribute("m_uiDiffuseColorIndex", oLight.m_uiDiffuseColorIndex); /*!< Diffuse color index. */ + light->SetAttribute("m_uiSpecularColorIndex", oLight.m_uiSpecularColorIndex); /*!< Specular color index. */ + traversePoint("m_sLocation", oLight.m_sLocation, light); /*!< Location. \version 2.1 */ + light->SetDoubleAttribute("m_dConstantAttenuation", oLight.m_dConstantAttenuation); /*!< Constant attenuation. \version 2.1 */ + light->SetDoubleAttribute("m_dLinearAttenuation", oLight.m_dLinearAttenuation); /*!< Linear attenuation. \version 2.1 */ + light->SetDoubleAttribute("m_dQuadraticAttenuation", oLight.m_dQuadraticAttenuation); /*!< Quadratic attenuation. \version 2.1 */ + A3DGraphPointLightGet(NULL, &oLight); + } + else + { + light->SetAttribute("Error", iRet); + } + setting->LinkEndChild(light); + return 0; +} + +//###################################################################################################################### +int traverseSpotLight(const A3DGraphSpotLight* pLight, _TiXmlElement* setting) +{ + if (!pLight) + { + setting->SetAttribute("Light", "Bad cast"); + return -1; + } + + _TiXmlElement* light = new _TiXmlElement("A3DGraphSpotLightData"); + A3DStatus iRet; + A3DGraphSpotLightData oLight; + A3D_INITIALIZE_DATA(A3DGraphSpotLightData, oLight); + if ((iRet = A3DGraphSpotLightGet(pLight, &oLight)) == A3D_SUCCESS) + { + light->SetAttribute("m_uiAmbientColorIndex", oLight.m_uiAmbientColorIndex); /*!< Ambient color index. */ + light->SetAttribute("m_uiDiffuseColorIndex", oLight.m_uiDiffuseColorIndex); /*!< Diffuse color index. */ + light->SetAttribute("m_uiSpecularColorIndex", oLight.m_uiSpecularColorIndex); /*!< Specular color index. */ + traversePoint("m_sDirection", oLight.m_sDirection, light); /*!< Direction. */ + light->SetDoubleAttribute("m_dFallOffAngle", oLight.m_dFallOffAngle); /*!< Fall-off angle.*/ + light->SetDoubleAttribute("m_dFallOffExponent", oLight.m_dFallOffExponent); /*!< Fall-off exponent. */ + traversePoint("m_sLocation", oLight.m_sLocation, light); /*!< Location. \version 2.1 */ + light->SetDoubleAttribute("m_dConstantAttenuation", oLight.m_dConstantAttenuation); /*!< Constant attenuation. \version 2.1 */ + light->SetDoubleAttribute("m_dLinearAttenuation", oLight.m_dLinearAttenuation); /*!< Linear attenuation. \version 2.1 */ + light->SetDoubleAttribute("m_dQuadraticAttenuation", oLight.m_dQuadraticAttenuation); /*!< Quadratic attenuation. \version 2.1 */ + A3DGraphSpotLightGet(NULL, &oLight); + } + else + { + light->SetAttribute("Error", iRet); + } + setting->LinkEndChild(light); + return 0; +} + +//###################################################################################################################### +int traverseDirectionalLight(const A3DGraphDirectionalLight* pLight, _TiXmlElement* setting) +{ + if (!pLight) + { + setting->SetAttribute("Light", "Bad cast"); + return -1; + } + + _TiXmlElement* light = new _TiXmlElement("A3DGraphDirectionalLightData"); + A3DStatus iRet; + A3DGraphDirectionalLightData oLight; + A3D_INITIALIZE_DATA(A3DGraphDirectionalLightData, oLight); + if ((iRet = A3DGraphDirectionalLightGet(pLight, &oLight)) == A3D_SUCCESS) + { + light->SetAttribute("m_uiAmbientColorIndex", oLight.m_uiAmbientColorIndex); /*!< Ambient color index. */ + light->SetAttribute("m_uiDiffuseColorIndex", oLight.m_uiDiffuseColorIndex); /*!< Diffuse color index. */ + light->SetAttribute("m_uiSpecularColorIndex", oLight.m_uiSpecularColorIndex); /*!< Specular color index. */ + light->SetDoubleAttribute("m_dIntensity", oLight.m_dIntensity); /*!< Density. */ + traversePoint("m_sDirection", oLight.m_sDirection, light); /*!< Direction. */ + A3DGraphDirectionalLightGet(NULL, &oLight); + } + else + { + light->SetAttribute("Error", iRet); + } + setting->LinkEndChild(light); + return 0; +} + +//###################################################################################################################### +int traverseLight(const A3DGraphLight* pLight, _TiXmlElement* setting) +{ + + if (!pLight) + { + setting->SetAttribute("Light", "empty"); + return -1; + } + + A3DEEntityType eType = kA3DTypeUnknown; + A3DEntityGetType(pLight, &eType); + switch (eType) + { + case kA3DTypeGraphAmbientLight: + traverseAmbientLight(pLight, setting); + break; + case kA3DTypeGraphPointLight: + traversePointLight(pLight, setting); + break; + case kA3DTypeGraphSpotLight: + traverseSpotLight(pLight, setting); + break; + case kA3DTypeGraphDirectionalLight: + traverseDirectionalLight(pLight, setting); + break; + default: + setting->SetAttribute("Light", "Unknown Type"); + break; + } + return 0; +} + +//###################################################################################################################### +int traverseCamera(const A3DGraphCamera* pCamera, _TiXmlElement* setting) +{ + _TiXmlElement* camera = new _TiXmlElement("A3DGraphCameraData"); + if (pCamera) + { + traverseSource(pCamera, camera); + A3DGraphCameraData oData; + A3D_INITIALIZE_DATA(A3DGraphCameraData, oData); + A3DStatus iRet = A3DGraphCameraGet(pCamera, &oData); + + if (iRet == A3D_SUCCESS) + { + camera->SetAttribute("m_bOrthographic", oData.m_bOrthographic ? "true" : "false"); + traversePoint("m_sLocation", oData.m_sLocation, camera); + traversePoint("m_sLookAt", oData.m_sLookAt, camera); + traversePoint("m_sUp", oData.m_sUp, camera); + camera->SetDoubleAttribute("m_dXFovy", oData.m_dXFovy); + camera->SetDoubleAttribute("m_dYFovy", oData.m_dYFovy); + camera->SetDoubleAttribute("m_dAspectRatio", oData.m_dAspectRatio); + camera->SetDoubleAttribute("m_dZNear", oData.m_dZNear); + camera->SetDoubleAttribute("m_dZFar", oData.m_dZFar); + camera->SetDoubleAttribute("m_dZoomFactor", oData.m_dZoomFactor); + } + else + { + camera->SetAttribute("Error", iRet); + } + A3DGraphCameraGet(NULL, &oData); + } + setting->LinkEndChild(camera); + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traverseGraphScene(const A3DGraphSceneDisplayParametersData& sData, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + _TiXmlElement* graphscene = new _TiXmlElement("A3DGraphSceneDisplayParametersData"); + graphscene->SetAttribute("NumberOfPlanes", sData.m_uiPlaneSize); + + for (A3DUns32 ui = 0; ui < sData.m_uiPlaneSize; ui++) + traverseSrfPlane(sData.m_ppClippingPlanes[ui], graphscene); + + graphscene->SetAttribute("m_bActive", sData.m_bIsActive); + traverseCamera(sData.m_pCamera, graphscene); + + graphscene->SetAttribute("NumberOfLights", sData.m_uiLightSize); + for (A3DUns32 ui = 0; ui < sData.m_uiLightSize; ui++) + traverseLight(sData.m_ppLights[ui], graphscene); + + graphscene->SetAttribute("m_bHasRotationCenter", sData.m_bHasRotationCenter ? "true" : "false"); + if (sData.m_bHasRotationCenter) + traversePoint("m_sRotationCenter", sData.m_sRotationCenter, graphscene); + + graphscene->SetAttribute("m_uiBackgroundStyleIndex", sData.m_uiBackgroundStyleIndex); + graphscene->SetAttribute("m_uiDefaultStyleIndex", sData.m_uiDefaultStyleIndex); + + A3DUns32 i, iMax = sData.m_uiDefaultPerTypeIndexSize; + graphscene->SetAttribute("NumberOfDefaultStyleIndexesPerType", iMax); + for (i = 0; i < iMax; i++) + { + graphscene->SetAttribute("TypesOfDefaultStyleIndexes", sData.m_puiTypesOfDefaultStyleIndexes[i]); + graphscene->SetAttribute("DefaultStyleIndexesPerType", sData.m_puiDefaultStyleIndexesPerType[i]); + } + + setting->LinkEndChild(graphscene); + return iRet; +} + +//###################################################################################################################### +int traverseGraphScene(const A3DGraphSceneDisplayParameters * pGraphSceneParam, _TiXmlElement* setting) +{ + A3DGraphSceneDisplayParametersData sData; + A3D_INITIALIZE_DATA(A3DGraphSceneDisplayParametersData, sData); + A3DInt32 iRet = A3DGraphSceneDisplayParametersGet(pGraphSceneParam, &sData); + + traverseGraphScene(sData, setting); + + A3DGraphSceneDisplayParametersGet(NULL, &sData); + return iRet; +} + +//###################################################################################################################### +int traverseDisplayFilter(A3DAsmFilter* pFilter, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + _TiXmlElement* filter = new _TiXmlElement("A3DAsmFilterData"); + + traverseSource(pFilter, filter); + setting->LinkEndChild(filter); + if (!pFilter) + { + filter->SetAttribute("Filter", "empty"); + return -1; + } + + A3DAsmFilterData oData; + A3D_INITIALIZE_DATA(A3DAsmFilterData, oData); + CHECK_RET(A3DAsmFilterGet(pFilter, &oData)); + + filter->SetAttribute("m_bIsActive", oData.m_bIsActive); + + A3DUns32 i, iMax = oData.m_sLayerFilterItem.m_uiSize; + if (iMax > 0) + { + _TiXmlElement* layerFilter = new _TiXmlElement("LayerFilters"); + layerFilter->SetAttribute("m_sLayerFilterItem.m_bIsInclusive", oData.m_sLayerFilterItem.m_bIsInclusive); + + std::ostringstream indexes; + + indexes << '[' << oData.m_sLayerFilterItem.m_puiLayerIndexes[0]; + A3DUns32 first = oData.m_sLayerFilterItem.m_puiLayerIndexes[0]; + A3DUns32 last = oData.m_sLayerFilterItem.m_puiLayerIndexes[0]; + for (i = 1; i < iMax; i++) + { + if (oData.m_sLayerFilterItem.m_puiLayerIndexes[i] == last + 1) + { + last ++; + continue; + } + if (first != last) + { + indexes << " - "<< last; + } + indexes << ", " << oData.m_sLayerFilterItem.m_puiLayerIndexes[i]; + first = oData.m_sLayerFilterItem.m_puiLayerIndexes[i]; + last = oData.m_sLayerFilterItem.m_puiLayerIndexes[i]; + } + if (first != last) + { + indexes << " - " << last; + } + indexes << ']'; + layerFilter->SetAttribute("m_sLayerFilterItem.m_puiLayerIndexes", indexes.str().c_str()); + + filter->LinkEndChild(layerFilter); + } + + iMax = oData.m_sEntityFilterItem.m_uiSize; + if (iMax > 0) + { + _TiXmlElement* entityFilter = new _TiXmlElement("EntityFilters"); + entityFilter->SetAttribute("m_sEntityFilterItem.m_bIsInclusive", oData.m_sEntityFilterItem.m_bIsInclusive); + for (i = 0; i < iMax; i++) + { + + std::ostringstream title; title << "sEntityFilterItem" << "_" << i; + _TiXmlElement* entityFilterItem = new _TiXmlElement(title.str().c_str()); + traverseEntityReference(oData.m_sEntityFilterItem.m_ppEntities[i], entityFilterItem); + entityFilter->LinkEndChild(entityFilterItem); + } + filter->LinkEndChild(entityFilter); + } + + A3DAsmFilterGet(NULL, &oData); + return iRet; +} + +//###################################################################################################################### +int traverseDisplayFilters(A3DUns32 uiSize,A3DAsmFilter** ppFilters , _TiXmlElement* setting) +{ + for (A3DUns32 uk = 0; uk < uiSize; ++uk) + traverseDisplayFilter(ppFilters[uk], setting); + return 0; +} + +//###################################################################################################################### +int traverseView(const A3DMkpView* pView, _TiXmlElement* setting) +{ + A3DMkpViewData sData; + A3D_INITIALIZE_DATA(A3DMkpViewData, sData); + + _TiXmlElement* view = new _TiXmlElement("A3DMkpViewData"); + traverseSource(pView, view); + + A3DInt32 iRet = A3DMkpViewGet(pView, &sData); + if(iRet == A3D_SUCCESS) + { + view->SetAttribute("m_bIsAnnotationView", sData.m_bIsAnnotationView); + view->SetAttribute("m_bIsDefaultView", sData.m_bIsDefaultView); + traverseVoids("m_ppAnnotations", sData.m_uiAnnotationsSize, (const A3DVoid**)sData.m_ppAnnotations, view); + traverseSrfPlane(sData.m_pPlane, view); + traverseGraphScene(sData.m_pSceneDisplayParameters, view); + + _TiXmlElement* displayfilters = new _TiXmlElement("DisplayFilters"); + traverseDisplayFilters(sData.m_uiDisplayFilterSize, sData.m_ppDisplayFilters, displayfilters); + view->LinkEndChild(displayfilters); + + _TiXmlElement* markupref = new _TiXmlElement("LinkedItems"); + for (A3DUns32 uk = 0; uk < sData.m_uiLinkedItemsSize; ++uk) + traverseLinkedItem(sData.m_ppLinkedItems[uk], markupref); + view->LinkEndChild(markupref); + + A3DMkpViewGet(NULL, &sData); + } + setting->LinkEndChild(view); + + return A3D_SUCCESS; +} + +//###################################################################################################################### +#define EnumValueToXmlAttribute(ENUM_VAL, ATT_TYPE, ATT_VALUE) \ + case ENUM_VAL: \ + setting->SetAttribute(ATT_TYPE, ATT_VALUE); \ + break; + +//###################################################################################################################### +static void stTraverseMarkupTypeAndSubType(const A3DEMarkupType& eType, const A3DEMarkupSubType& eSubType, _TiXmlElement* setting) +{ + switch(eType) + { + EnumValueToXmlAttribute(kA3DMarkupTypeUnknown, "m_eType", "Unknown"); + EnumValueToXmlAttribute(kA3DMarkupTypeText, "m_eType", "Plain text"); + EnumValueToXmlAttribute(kA3DMarkupTypeDimension, "m_eType", "Dimension"); + EnumValueToXmlAttribute(kA3DMarkupTypeArrow, "m_eType", "Arrow"); + EnumValueToXmlAttribute(kA3DMarkupTypeBalloon, "m_eType", "Balloon"); + EnumValueToXmlAttribute(kA3DMarkupTypeCircleCenter, "m_eType", "Center of circle"); + EnumValueToXmlAttribute(kA3DMarkupTypeCoordinate, "m_eType", "Coordinate"); + EnumValueToXmlAttribute(kA3DMarkupTypeDatum, "m_eType", "Datum"); + EnumValueToXmlAttribute(kA3DMarkupTypeFastener, "m_eType", "Fastener"); + EnumValueToXmlAttribute(kA3DMarkupTypeGdt, "m_eType", "GDT"); + EnumValueToXmlAttribute(kA3DMarkupTypeLocator, "m_eType", "Locator"); + EnumValueToXmlAttribute(kA3DMarkupTypeMeasurementPoint, "m_eType", "Point"); + EnumValueToXmlAttribute(kA3DMarkupTypeRoughness, "m_eType", "Roughness"); + EnumValueToXmlAttribute(kA3DMarkupTypeWelding, "m_eType", "Welding"); + EnumValueToXmlAttribute(kA3DMarkupTypeTable, "m_eType", "Table"); + EnumValueToXmlAttribute(kA3DMarkupTypeOther, "m_eType", "Other"); + default: + setting->SetAttribute("m_eType", "Unexpected"); + break; + } + + if(eType == kA3DMarkupTypeDatum) + { + switch(eSubType) + { + EnumValueToXmlAttribute(kA3DMarkupSubTypeDatumIdent, "m_eSubType", "Datum ident"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDatumTarget, "m_eSubType", "Datum target"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDatumEnumMax, "m_eSubType", "Datum max value. \version 2.2"); + default: + setting->SetAttribute("Datum_m_eSubType", "Unexpected"); + break; + } + } + else if(eType == kA3DMarkupTypeDimension) + { + switch(eSubType) + { + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionDistance, "m_eSubType", "Dimension distance"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionDistanceOffset, "m_eSubType", "Dimension distance offset"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionDistanceCumulate, "m_eSubType", "Dimension distance cumulate"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionChamfer, "m_eSubType", "Dimension chamfer"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionSlope, "m_eSubType", "Dimension slope"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionOrdinate, "m_eSubType", "Dimension ordinate"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionRadius, "m_eSubType", "Dimension radius"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionRadiusTangent, "m_eSubType", "Dimension radius tangent"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionRadiusCylinder, "m_eSubType", "Dimension radius cylinder"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionRadiusEdge, "m_eSubType", "Dimension radius edge"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionDiameter, "m_eSubType", "Dimension diameter"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionDiameterTangent, "m_eSubType", "Dimension diameter tangent"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionDiameterCylinder, "m_eSubType", "Dimension diameter cylinder"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionDiameterEdge, "m_eSubType", "Dimension diameter edge"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionDiameterCone, "m_eSubType", "Dimension diameter cone"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionLength, "m_eSubType", "Dimension length"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionLengthCurvilinear, "m_eSubType", "Dimension length curvilinear"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionLengthCircular, "m_eSubType", "Dimension length circular"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionAngle, "m_eSubType", "Dimension angle"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeDimensionEnumMax, "m_eSubType", "Dimension max value. \version 2.2"); + default: + setting->SetAttribute("Dimension_m_eSubType", "Unexpected"); + break; + } + } + else if(eType == kA3DMarkupTypeGdt) + { + switch(eSubType) + { + EnumValueToXmlAttribute(kA3DMarkupSubTypeGdtFcf, "m_eSubType", "GDT feature control frame subtype"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeGdtEnumMax, "m_eSubType", "GDT max value. \version 2.2"); + default: + setting->SetAttribute("Gdt_m_eSubType", "Unexpected"); + break; + } + } + else if(eType == kA3DMarkupTypeWelding) + { + switch(eSubType) + { + EnumValueToXmlAttribute(kA3DMarkupSubTypeWeldingLine, "m_eSubType", "Line welding subtype"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeWeldingSpot, "m_eSubType", "Spot welding subtype"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeWeldingEnumMax, "m_eSubType", "welding max value. \version 2.2"); + default: + setting->SetAttribute("welding_m_eSubType", "Unexpected"); + break; + } + } + else if(eType == kA3DMarkupTypeOther) + { + switch(eSubType) + { + EnumValueToXmlAttribute(kA3DMarkupSubTypeOtherSymbolUser, "m_eSubType", "SymbolUser other subtype"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeOtherSymbolUtility, "m_eSubType", "SymbolUtility other subtype"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeOtherSymbolCustom, "m_eSubType", "SymbolCustom other subtype"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeOtherGeometricReference, "m_eSubType", "GeometricReference other subtype"); + EnumValueToXmlAttribute(kA3DMarkupSubTypeOtherRegion, "m_eSubType", "Region"); + default: + setting->SetAttribute("other_symbol_m_eSubType", "Unexpected"); + break; + } + } +} + +//###################################################################################################################### +int traverseMarkup(const A3DMkpMarkup* pMarkup, _TiXmlElement* setting) +{ + A3DMkpMarkupData sData; + A3D_INITIALIZE_DATA(A3DMkpMarkupData, sData); + + _TiXmlElement* markup = new _TiXmlElement("A3DMkpMarkupData"); + traverseSource(pMarkup, markup); + + A3DInt32 iRet = A3DMkpMarkupGet(pMarkup, &sData); + A3DRootBaseData sBaseData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sBaseData); + iRet = A3DRootBaseGet(pMarkup, &sBaseData); + iRet = A3DRootBaseGet(NULL, &sBaseData); + if(iRet == A3D_SUCCESS) + { + stTraverseMarkupTypeAndSubType(sData.m_eType, sData.m_eSubType, markup); + traverseMarkupDefinition(pMarkup, markup); + + _TiXmlElement* leaders = new _TiXmlElement("Leaders"); + leaders->SetAttribute("size", (int)sData.m_uiLeadersSize); + for(A3DUns32 ui = 0; ui < sData.m_uiLeadersSize; ++ui) + traverseLeader(sData.m_ppLeaders[ui], leaders); + markup->LinkEndChild(leaders); + + _TiXmlElement* linkedItems = new _TiXmlElement("LinkedItems"); + linkedItems->SetAttribute("size", (int)sData.m_uiLinkedItemsSize); + for(A3DUns32 uj = 0; uj < sData.m_uiLinkedItemsSize; ++uj) + traverseLinkedItem(sData.m_ppLinkedItems[uj], linkedItems); + markup->LinkEndChild(linkedItems); + + // parse the references + A3DUns32 uiLinkedItemsSize = 0; + A3DMiscMarkupLinkedItem** ppLinkedItems = NULL; + iRet = A3DMkpLinkForMarkupReferenceGet(pMarkup, &uiLinkedItemsSize, &ppLinkedItems); + if (iRet == A3D_SUCCESS && ppLinkedItems) + { + _TiXmlElement* markupref = new _TiXmlElement("LinksForMarkupReference"); + markupref->SetAttribute("size", (int) uiLinkedItemsSize); + for (A3DUns32 uk = 0; uk < uiLinkedItemsSize; ++uk) + traverseLinkedItem(ppLinkedItems[uk], markupref); + markup->LinkEndChild(markupref); + A3DMkpLinkForMarkupReferenceGet(NULL, &uiLinkedItemsSize, &ppLinkedItems); + } + + // parse the additional references + A3DUns32 uiAdditionalLinkedItemsSize = 0; + A3DMiscMarkupLinkedItem** ppAdditionnalLinkedItems = NULL; + iRet = A3DMkpLinkForAdditionalMarkupReferenceGet(pMarkup, &uiAdditionalLinkedItemsSize, &ppAdditionnalLinkedItems); + if (iRet == A3D_SUCCESS) + { + if (ppAdditionnalLinkedItems) + { + _TiXmlElement* additionalMarkupref = new _TiXmlElement("LinksForAdditionalMarkupReference"); + linkedItems->SetAttribute("size", (int)uiAdditionalLinkedItemsSize); + for (A3DUns32 uk = 0; uk < uiAdditionalLinkedItemsSize; ++uk) + traverseLinkedItem(ppAdditionnalLinkedItems[uk], additionalMarkupref); + markup->LinkEndChild(additionalMarkupref); + } + A3DMkpLinkForAdditionalMarkupReferenceGet(NULL, &uiAdditionalLinkedItemsSize, &ppAdditionnalLinkedItems); + } + + traverseTessBase(sData.m_pTessellation, markup); + + A3DMkpMarkupGet(NULL, &sData); + } + else + markup->SetAttribute("error", iRet); + + setting->LinkEndChild(markup); + + return iRet; +} + +//###################################################################################################################### +void setLeaderSymbolType(_TiXmlElement* setting, const char* name, const A3DMDLeaderSymbolType value) +{ + switch(value) + { + EnumValueToXmlAttribute(KA3DMDLeaderSymbolNotUsed, name, "Not used"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolCross, name, "Cross"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolPlus, name, "Plus"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolConcentric, name, "Concentric"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolCoincident, name, "Coincident"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolFullCircle, name, "FullCircle"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolFullSquare, name, "FullSquare"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolStar, name, "Star"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolDot, name, "Dot"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolSmallDot, name, "SmallDot"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolMisc1, name, "Misc1"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolMisc2, name, "Misc2"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolFullCircle2, name, "FullCircle2"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolFullSquare2, name, "FullSquare2"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolOpenArrow, name, "OpenArrow"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolUnfilledArrow, name, "UnfilledArrow"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolBlankedArrow, name, "BlankedArrow"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolFilledArrow, name, "FilledArrow"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolUnfilledCircle, name, "UnfilledCircle"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolBlankedCircle, name, "BlankedCircle"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolFilledCircle, name, "FilledCircle"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolCrossedCircle, name, "CrossedCircle"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolBlankedSquare, name, "BlankedSquare"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolFilledSquare, name, "FilledSquare"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolBlankedTriangle, name, "BlankedTriangle"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolFilledTriangle, name, "FilledTriangle"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolManipulatorSquare, name, "ManipulatorSquare"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolMamipulatorDiamond, name, "MamipulatorDiamond"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolManipulatorCircle, name, "ManipulatorCircle"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolManipulatorTriangle, name, "ManipulatorTriangle"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolDoubleOpenArrow, name, "DoubleOpenArrow"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolWave, name, "Wave"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolSegment, name, "Segment"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolDoubleFilledArrow, name, "DoubleFilledArrow"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolDoubleClosedArrow, name, "DoubleClosedArrow"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolHalfOpenArrowUp, name, "HalfOpenArrowUp"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolHalfOpenArrowDown, name, "HalfOpenArrowDown"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolHalfFilledArrowUp, name, "HalfFilledArrowUp"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolHalfFilledArrowDown, name, "HalfFilledArrowDown"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolSlash, name, "Slash"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolDoubleBlankedArrow, name, "DoubleBlankedArrow"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolIntegral, name, "Integral"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolZoneGlobalAllAround, name, "ZoneGlobalAllAround"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolZonePartialAllAround, name, "ZonePartialAllAround"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolZoneGlobalAllAboutWithHorizontalAxisIndicator, name, "ZoneGlobalAllAboutWithHorizontalAxisIndicator"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolZoneGlobalAllAboutWithVerticalAxisIndicator, name, "ZoneGlobalAllAboutWithVerticalAxisIndicator"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolZonePartialAllAboutWithHorizontalAxisIndicator, name, "ZonePartialAllAboutWithHorizontalAxisIndicator"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolZonePartialAllAboutWithVerticalAxisIndicator, name, "ZonePartialAllAboutWithVerticalAxisIndicator"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolZoneGlobalAllOver, name, "ZoneGlobalAllOver"); + EnumValueToXmlAttribute(KA3DMDLeaderSymbolZonePartialAllOver, name, "ZonePartialAllOver"); + default: + setting->SetAttribute(name, "Unexpected"); + break; + } +} + +//###################################################################################################################### +int stTraverseLeaderSymbol(const A3DMDLeaderSymbol* pSymbol, _TiXmlElement* setting) +{ + A3DMDLeaderSymbolData sData; + A3D_INITIALIZE_DATA(A3DMDLeaderSymbolData, sData); + + _TiXmlElement* symbol = new _TiXmlElement("A3DMDLeaderSymbolData"); + + A3DInt32 iRet = A3DMDLeaderSymbolGet(pSymbol, &sData); + if(iRet == A3D_SUCCESS) + { + symbol->SetDoubleAttribute("m_dAdditionalParameter", sData.m_dAdditionalParameter); + symbol->SetDoubleAttribute("m_dLength" , sData.m_dLength); + setLeaderSymbolType(symbol, "m_eHeadSymbol", sData.m_eHeadSymbol); + A3DMDLeaderSymbolGet(NULL, &sData); + } + setting->LinkEndChild(symbol); + return iRet; +} + +//###################################################################################################################### +int stTraverseLeaderStub(const A3DMDMarkupLeaderStub* pStub, _TiXmlElement* setting) +{ + A3DMDMarkupLeaderStubData sData; + A3D_INITIALIZE_DATA(A3DMDMarkupLeaderStubData, sData); + + _TiXmlElement* stub = new _TiXmlElement("A3DMDMarkupLeaderStubData"); + + A3DInt32 iRet = A3DMDMarkupLeaderStubGet(pStub, &sData); + if(iRet == A3D_SUCCESS) + { + traverseDoubles("m_pdValues" , sData.m_uiValuesAndAnchorTypesSize, sData.m_pdValues , stub); + traverseUInts ("m_piAnchorTypes", sData.m_uiValuesAndAnchorTypesSize, sData.m_piAnchorTypes, stub); + A3DMDMarkupLeaderStubGet(NULL, &sData); + } + setting->LinkEndChild(stub); + return iRet; +} + +//###################################################################################################################### +int stTraverseMDPosition2D(const A3DMDPosition2D* pPos, _TiXmlElement* setting) +{ + A3DMDPosition2DData sData; + A3D_INITIALIZE_DATA(A3DMDPosition2DData, sData); + + _TiXmlElement* pos = new _TiXmlElement("A3DMDPosition2DData"); + + A3DInt32 iRet = A3DMDPosition2DGet(pPos, &sData); + if(iRet == A3D_SUCCESS) + { + pos->SetDoubleAttribute("m_dOffset", sData.m_dOffset); + traverseSrfPlane(sData.m_pPlane, pos); + traversePoint2d("m_sPosition", sData.m_sPosition, pos); + A3DMDPosition2DGet(NULL, &sData); + } + setting->LinkEndChild(pos); + return iRet; +} + +//###################################################################################################################### +int stTraverseMDPosition3D(const A3DMDPosition3D* pPos, _TiXmlElement* setting) +{ + A3DMDPosition3DData sData; + A3D_INITIALIZE_DATA(A3DMDPosition3DData, sData); + + _TiXmlElement* pos = new _TiXmlElement("A3DMDPosition3DData"); + + A3DInt32 iRet = A3DMDPosition3DGet(pPos, &sData); + if(iRet == A3D_SUCCESS) + { + traversePoint("m_sPosition", sData.m_sPosition, pos); + A3DMDPosition3DGet(NULL, &sData); + } + setting->LinkEndChild(pos); + return iRet; +} + +//###################################################################################################################### +int stTraverseMDPositionReference(const A3DMDPositionReference* pPos, _TiXmlElement* setting) +{ + A3DMDPositionReferenceData sData; + A3D_INITIALIZE_DATA(A3DMDPositionReferenceData, sData); + + _TiXmlElement* pos = new _TiXmlElement("A3DMDPositionReferenceData"); + + A3DInt32 iRet = A3DMDPositionReferenceGet(pPos, &sData); + if(iRet == A3D_SUCCESS) + { + // traverseLinkedItem(sData.m_psLinkedItem, pos); // avoid recursive visitation... + pos->SetAttribute("m_eAttachType", sData.m_eAttachType); + traversePoint2d("m_sOffsetToReference", sData.m_sOffsetToReference, pos); + A3DMDPositionReferenceGet(NULL, &sData); + } + setting->LinkEndChild(pos); + return iRet; +} + +//###################################################################################################################### +int stTraverseMDPosition(const A3DMDPosition* pPos, _TiXmlElement* setting) +{ + A3DEEntityType eType = kA3DTypeUnknown; + A3DInt32 iRet = A3DEntityGetType(pPos, &eType); + if(iRet == A3D_SUCCESS) + { + switch(eType) + { + case kA3DTypeMDPosition2D: + iRet = stTraverseMDPosition2D(pPos, setting); + break; + case kA3DTypeMDPosition3D: + iRet = stTraverseMDPosition3D(pPos, setting); + break; + case kA3DTypeMDPositionReference: + iRet = stTraverseMDPositionReference(pPos, setting); + break; + default: + iRet = A3D_INVALID_ENTITY_TYPE; + break; + } + } + return iRet; +} + +//###################################################################################################################### +int stTraverseLeaderDefinition(const A3DMDLeaderDefinition* pLeaderDef, _TiXmlElement* setting) +{ + A3DMDLeaderDefinitionData sData; + A3D_INITIALIZE_DATA(A3DMDLeaderDefinitionData, sData); + + _TiXmlElement* definition = new _TiXmlElement("A3DMDLeaderDefinitionData"); + + A3DInt32 iRet = A3DMDLeaderDefinitionGet(pLeaderDef, &sData); + if(iRet == A3D_SUCCESS) + { + setLeaderSymbolType(definition, "m_eTailSymbol", sData.m_eTailSymbol); + traverseDoubles("m_pdGapList", sData.m_uiNbGapsElements, sData.m_pdGapList, definition); + + if(sData.m_pHeadSymbol != NULL) + stTraverseLeaderSymbol(sData.m_pHeadSymbol, definition); + + _TiXmlElement* positions = new _TiXmlElement("PathLeaderPositions"); + positions->SetAttribute("size", (int)sData.m_uiNumberOfPathLeaderPositions); + for(A3DUns32 ui = 0; ui < sData.m_uiNumberOfPathLeaderPositions; ++ui) + stTraverseMDPosition(sData.m_ppsPathLeaderPositions[ui], positions); + definition->LinkEndChild(positions); + + if(sData.m_pStub != NULL) + stTraverseLeaderStub(sData.m_pStub, definition); + + definition->SetAttribute("m_uAnchorFrame", sData.m_uAnchorFrame); + definition->SetAttribute("m_uAnchorPoint", sData.m_uAnchorPoint); + + if(sData.m_pNextLeader != NULL) + stTraverseLeaderDefinition(sData.m_pNextLeader, definition); + + A3DMDLeaderDefinitionGet(NULL, &sData); + } + setting->LinkEndChild(definition); + return iRet; +} + +//###################################################################################################################### +int traverseLeader(const A3DMkpLeader* pLeader, _TiXmlElement* setting) +{ + A3DMkpLeaderData sData; + A3D_INITIALIZE_DATA(A3DMkpLeaderData, sData); + + _TiXmlElement* leader = new _TiXmlElement("A3DMkpLeaderData"); + traverseSource(pLeader, leader); + + A3DInt32 iRet = A3DMkpLeaderGet(pLeader, &sData); + if(iRet == A3D_SUCCESS) + { + traverseLinkedItem(sData.m_pLinkedItem, leader); + traverseTessBase(sData.m_pTessellation, leader); + stTraverseLeaderDefinition(pLeader, leader); + A3DMkpLeaderGet(NULL, &sData); + } + else + leader->SetAttribute("error", iRet); + + setting->LinkEndChild(leader); + return iRet; +} + +//###################################################################################################################### +int traverseLinkedItem(const A3DMiscMarkupLinkedItem* pMkpLinkedItem, _TiXmlElement* setting) +{ + A3DMiscMarkupLinkedItemData sData; + A3D_INITIALIZE_DATA(A3DMiscMarkupLinkedItemData, sData); + + _TiXmlElement* mkplinkeditem = new _TiXmlElement("A3DMiscMarkupLinkedItemData"); + traverseSource(pMkpLinkedItem, mkplinkeditem); + + A3DInt32 iRet = A3DMiscMarkupLinkedItemGet(pMkpLinkedItem, &sData); + if(pMkpLinkedItem && iRet == A3D_SUCCESS) + { + traverseEntityReference((A3DMiscEntityReference*)pMkpLinkedItem, mkplinkeditem); + mkplinkeditem->SetAttribute("m_bMarkupShowControl", sData.m_bMarkupShowControl); + mkplinkeditem->SetAttribute("m_bMarkupDeleteControl", sData.m_bMarkupDeleteControl); + mkplinkeditem->SetAttribute("m_bLeaderShowControl", sData.m_bLeaderShowControl); + mkplinkeditem->SetAttribute("m_bLeaderDeleteControl", sData.m_bLeaderDeleteControl); + if(sData.m_pTargetProductOccurrence != NULL) + _SetAttributePtr(mkplinkeditem, "m_pTargetProductOccurrence", (void*) sData.m_pTargetProductOccurrence); + A3DMiscMarkupLinkedItemGet(NULL, &sData); + } + else + mkplinkeditem->SetAttribute("error", pMkpLinkedItem ? iRet : A3D_INVALID_ENTITY_NULL); + + setting->LinkEndChild(mkplinkeditem); + return iRet; +} diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLMarkupDefinition.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLMarkupDefinition.cpp new file mode 100644 index 0000000..04d65be --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLMarkupDefinition.cpp @@ -0,0 +1,93 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "PRC2XML.h" + + + +//###################################################################################################################### +int traverseMarkupDefinition(const A3DMkpMarkup* pMarkup, _TiXmlElement* setting) +{ + A3DMarkupDefinitionData sData; + A3D_INITIALIZE_DATA(A3DMarkupDefinitionData, sData); + + A3DEEntityType eType = kA3DTypeUnknown; + A3DStatus iRet = A3DEntityGetType(pMarkup, &eType); + + + _TiXmlElement* markup = NULL; + iRet = A3DMarkupDefinitionGet((A3DMarkupDefinition*)pMarkup, &sData); + if(iRet != A3D_SUCCESS) + { + markup->SetAttribute("error", iRet); + return iRet; + } + + A3DMDPosition2DData sPosition; + A3DVector2dData sOffsetAnchorPoint; + A3DBool bIsScreenLocation=FALSE; + A3D_INITIALIZE_DATA(A3DMDPosition2DData, sPosition); + A3D_INITIALIZE_DATA(A3DVector2dData, sOffsetAnchorPoint); + A3DMarkupPositionIsScreenLocation((A3DMarkupDefinition*)pMarkup, + &bIsScreenLocation, + &sPosition, + &sOffsetAnchorPoint); + if(bIsScreenLocation) + { + markup = new _TiXmlElement("A3DMkpMarkupDefinitionData"); + setting->LinkEndChild(markup); + markup->SetAttribute("PositionIsScreenLocation", bIsScreenLocation); + markup->SetDoubleAttribute("position2Dx ", sPosition.m_sPosition.m_dX); + markup->SetDoubleAttribute("position2Dy ", sPosition.m_sPosition.m_dY); + markup->SetDoubleAttribute("offsetAnchorPoint2Dx ", sOffsetAnchorPoint.m_dX); + markup->SetDoubleAttribute("offsetAnchorPoint2Dy ", sOffsetAnchorPoint.m_dY); + } + A3DMarkupDefinitionGet(NULL, &sData); + + if(eType == kA3DTypeMkpMarkup) + { + setting->SetAttribute("data", "no definition"); + return A3D_SUCCESS; + } + + if(!bIsScreenLocation) + { + markup = new _TiXmlElement("A3DMkpMarkupDefinitionData"); + setting->LinkEndChild(markup); + } + + if(eType == kA3DTypeMarkupText) + { + return traverseMarkupText(pMarkup, markup); + } + else if(eType == kA3DTypeMarkupRichText) + { + return traverseMarkupRichText(pMarkup, markup); + } + else if(eType == kA3DTypeMarkupDatum) + { + return traverseMarkupDatum(pMarkup, markup); + } + else if(eType == kA3DTypeMarkupGDT) + { + return traverseMarkupGDT(pMarkup, markup); + } + else if(eType == kA3DTypeMarkupDimension) + { + return traverseMarkupDimension(pMarkup, markup); + } + else + { + markup->SetAttribute("specific_data", "not yet implemented"); + return A3D_NOT_IMPLEMENTED; + } +} diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLMarkupDimension.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLMarkupDimension.cpp new file mode 100644 index 0000000..526d0fb --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLMarkupDimension.cpp @@ -0,0 +1,593 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "PRC2XML.h" + + + +//###################################################################################################################### +static void sttraverseDimensionType(int iDimensionType, _TiXmlElement* setting) +{ + switch(iDimensionType) + { + case KEA3DMDDimensionTypeDistance: setting->SetAttribute("m_eType", "KEA3DMDDimensionTypeDistance"); break; + case KEA3DMDDimensionTypeDistanceOffset: setting->SetAttribute("m_eType", "KEA3DMDDimensionTypeDistanceOffset"); break; + case KEA3DMDDimensionTypeLength: setting->SetAttribute("m_eType", "KEA3DMDDimensionTypeLength"); break; + case KEA3DMDDimensionTypeLengthCurvilinear: setting->SetAttribute("m_eType", "KEA3DMDDimensionTypeLengthCurvilinear"); break; + case KEA3DMDDimensionTypeAngle: setting->SetAttribute("m_eType", "KEA3DMDDimensionTypeAngle"); break; + case KEA3DMDDimensionTypeRadius: setting->SetAttribute("m_eType", "KEA3DMDDimensionTypeRadius"); break; + case KEA3DMDDimensionTypeRadiusTangent: setting->SetAttribute("m_eType", "KEA3DMDDimensionTypeRadiusTangent"); break; + case KEA3DMDDimensionTypeRadiusCylinder: setting->SetAttribute("m_eType", "KEA3DMDDimensionTypeRadiusCylinder"); break; + case KEA3DMDDimensionTypeRadiusEdge: setting->SetAttribute("m_eType", "KEA3DMDDimensionTypeRadiusEdge"); break; + case KEA3DMDDimensionTypeDiameter: setting->SetAttribute("m_eType", "KEA3DMDDimensionTypeDiameter"); break; + case KEA3DMDDimensionTypeDiameterTangent: setting->SetAttribute("m_eType", "KEA3DMDDimensionTypeDiameterTangent"); break; + case KEA3DMDDimensionTypeDiameterCylinder: setting->SetAttribute("m_eType", "KEA3DMDDimensionTypeDiameterCylinder"); break; + case KEA3DMDDimensionTypeDiameterEdge: setting->SetAttribute("m_eType", "KEA3DMDDimensionTypeDiameterEdge"); break; + case KEA3DMDDimensionTypeDiameterCone: setting->SetAttribute("m_eType", "KEA3DMDDimensionTypeDiameterCone"); break; + case KEA3DMDDimensionTypeChamfer: setting->SetAttribute("m_eType", "KEA3DMDDimensionTypeChamfer"); break; + case KEA3DMDDimensionTypeSlope: setting->SetAttribute("m_eType", "KEA3DMDDimensionTypeSlope"); break; + default: setting->SetAttribute("m_eType", "unexpected"); break; + } +} + +//###################################################################################################################### + +static void sttraverseDimensionValueFormat(const A3DMDDimensionValueFormat* psValueFormat, _TiXmlElement* setting) +{ + if(psValueFormat == NULL) + { + setting->SetAttribute("psValueFormat", "NULL"); + return; + } + + A3DMDDimensionValueFormatData sValueFormatData; + A3D_INITIALIZE_DATA(A3DMDDimensionValueFormatData, sValueFormatData); + + _TiXmlElement* markup_dimvalueformat = new _TiXmlElement("A3DMDDimensionValueFormatData"); + setting->LinkEndChild(markup_dimvalueformat); + + A3DStatus iRet = A3DMDDimensionValueFormatGet(psValueFormat, &sValueFormatData); + if(iRet != A3D_SUCCESS) + { + markup_dimvalueformat->SetAttribute("error", iRet); + return; + } + + markup_dimvalueformat->SetAttribute("m_pcName", sValueFormatData.m_pcName?sValueFormatData.m_pcName:"dimension"); + markup_dimvalueformat->SetAttribute("m_iType", sValueFormatData.m_iType); + markup_dimvalueformat->SetAttribute("m_iUnit", sValueFormatData.m_iUnit); + markup_dimvalueformat->SetDoubleAttribute("m_dGlobFact", sValueFormatData.m_dGlobFact); + markup_dimvalueformat->SetAttribute("m_iNulFac_1", sValueFormatData.m_iNulFac_1); + markup_dimvalueformat->SetAttribute("m_iNulFac_2", sValueFormatData.m_iNulFac_2); + markup_dimvalueformat->SetAttribute("m_iExise", sValueFormatData.m_iExise); + markup_dimvalueformat->SetAttribute("m_iSep1000", sValueFormatData.m_iSep1000); + markup_dimvalueformat->SetDoubleAttribute("m_dFact_1", sValueFormatData.m_dFact_1); + markup_dimvalueformat->SetDoubleAttribute("m_dFact_2", sValueFormatData.m_dFact_2); + markup_dimvalueformat->SetDoubleAttribute("m_dFact_3", sValueFormatData.m_dFact_3); + markup_dimvalueformat->SetDoubleAttribute("m_dValPos_1", sValueFormatData.m_dValPos_1); + markup_dimvalueformat->SetDoubleAttribute("m_dValPos_2", sValueFormatData.m_dValPos_2); + markup_dimvalueformat->SetDoubleAttribute("m_dValPos_3", sValueFormatData.m_dValPos_3); + markup_dimvalueformat->SetAttribute("m_pcSepar_1", + sValueFormatData.m_pcSepar_1 ? sValueFormatData.m_pcSepar_1 : "null"); + markup_dimvalueformat->SetAttribute("m_pcSepar_1", + sValueFormatData.m_pcSepar_2 ? sValueFormatData.m_pcSepar_2 : "null"); + markup_dimvalueformat->SetAttribute("m_pcSepar_1", + sValueFormatData.m_pcSepar_3 ? sValueFormatData.m_pcSepar_3 : "null"); + markup_dimvalueformat->SetDoubleAttribute("m_dSepScl_1", sValueFormatData.m_dSepScl_1); + markup_dimvalueformat->SetDoubleAttribute("m_dSepScl_2", sValueFormatData.m_dSepScl_2); + markup_dimvalueformat->SetDoubleAttribute("m_dSepScl_3", sValueFormatData.m_dSepScl_3); + markup_dimvalueformat->SetDoubleAttribute("m_dSepPos_1", sValueFormatData.m_dSepPos_1); + markup_dimvalueformat->SetDoubleAttribute("m_dSepPos_2", sValueFormatData.m_dSepPos_2); + markup_dimvalueformat->SetDoubleAttribute("m_dSepPos_3", sValueFormatData.m_dSepPos_3); + markup_dimvalueformat->SetDoubleAttribute("m_dRestY", sValueFormatData.m_dRestY); + markup_dimvalueformat->SetAttribute("m_iFinZer", sValueFormatData.m_iFinZer); + markup_dimvalueformat->SetAttribute("m_iSepNum", sValueFormatData.m_iSepNum); + markup_dimvalueformat->SetAttribute("m_iTypFrac", sValueFormatData.m_iTypFrac); + markup_dimvalueformat->SetAttribute("m_iSepDen", sValueFormatData.m_iSepDen); + markup_dimvalueformat->SetDoubleAttribute("m_dOperY", sValueFormatData.m_dOperY); + markup_dimvalueformat->SetAttribute("m_iNulOther", sValueFormatData.m_iNulOther); + markup_dimvalueformat->SetDoubleAttribute("m_dResScl", sValueFormatData.m_dResScl); + markup_dimvalueformat->SetAttribute("m_iFact", sValueFormatData.m_iFact); + markup_dimvalueformat->SetDoubleAttribute("m_dRestX", sValueFormatData.m_dRestX); + + A3DMDDimensionValueFormatGet(NULL, &sValueFormatData); +} + +//###################################################################################################################### +static void sttraverseDimensionToleranceSimpleFormat(const A3DMDDimensionSimpleToleranceFormat* psToleranceFormat, + _TiXmlElement* setting) +{ + if(psToleranceFormat == NULL) + { + setting->SetAttribute("psToleranceFormat", "NULL"); + return; + } + A3DMDDimensionSimpleToleranceFormatData sFormatData; + A3D_INITIALIZE_DATA(A3DMDDimensionSimpleToleranceFormatData, sFormatData); + + _TiXmlElement* markup_dimtolformat = new _TiXmlElement("A3DMDDimensionSimpleToleranceFormat"); + setting->LinkEndChild(markup_dimtolformat); + + A3DStatus iRet = A3DMDDimensionSimpleToleranceFormatGet(psToleranceFormat, &sFormatData); + if(iRet != A3D_SUCCESS) + { + markup_dimtolformat->SetAttribute("error", iRet); + return; + } + + markup_dimtolformat->SetAttribute("m_pcName", (sFormatData.m_pcName && sFormatData.m_pcName[0]!=0)?sFormatData.m_pcName:"no name"); + markup_dimtolformat->SetAttribute("m_iType", sFormatData.m_iType); + markup_dimtolformat->SetAttribute("m_iSepar_1", sFormatData.m_iSepar_1); + markup_dimtolformat->SetAttribute("m_iSepar_2", sFormatData.m_iSepar_2); + markup_dimtolformat->SetDoubleAttribute("m_dSymbolH", sFormatData.m_dSymbolH); + markup_dimtolformat->SetAttribute("m_iSepTo_1", sFormatData.m_iSepTo_1); + markup_dimtolformat->SetAttribute("m_iSepTo_2", sFormatData.m_iSepTo_2); + markup_dimtolformat->SetAttribute("m_iSepTo_3", sFormatData.m_iSepTo_3); + markup_dimtolformat->SetAttribute("m_iTrailing", sFormatData.m_iTrailing); + markup_dimtolformat->SetAttribute("m_iFractLine", sFormatData.m_iFractLine); + markup_dimtolformat->SetAttribute("m_iPtOnValue", sFormatData.m_iPtOnValue); + markup_dimtolformat->SetAttribute("m_iAnchorPt", sFormatData.m_iAnchorPt); + markup_dimtolformat->SetDoubleAttribute("m_dIntX", sFormatData.m_dIntX); + markup_dimtolformat->SetDoubleAttribute("m_dIntY", sFormatData.m_dIntY); + markup_dimtolformat->SetDoubleAttribute("m_dExtX", sFormatData.m_dExtX); + markup_dimtolformat->SetDoubleAttribute("m_dExtY", sFormatData.m_dExtY); + + markup_dimtolformat->SetAttribute("m_iMergeSame", sFormatData.m_iMergeSame); + markup_dimtolformat->SetAttribute("m_iShowNull", sFormatData.m_iShowNull); + + markup_dimtolformat->SetDoubleAttribute("m_dScale", sFormatData.m_dScale); + + A3DMDDimensionSimpleToleranceFormatGet(NULL, &sFormatData); +} + +//###################################################################################################################### +static void sttraverseDimensionToleranceFormat(const A3DMDDimensionToleranceFormat* psToleranceFormat, + _TiXmlElement* setting) +{ + A3DEEntityType eType = kA3DTypeUnknown; + if(psToleranceFormat == NULL) + { + setting->SetAttribute("psToleranceFormat", "NULL"); + return; + } + + A3DStatus iRet = A3DEntityGetType(psToleranceFormat, &eType); + if(iRet != A3D_SUCCESS) + { + setting->SetAttribute("psToleranceFormat", "type error"); + return; + } + + if(eType == kA3DTypeMDDimensionSimpleToleranceFormat) + { + sttraverseDimensionToleranceSimpleFormat((A3DMDDimensionSimpleToleranceFormat*)psToleranceFormat, setting); + } + else if(eType == kA3DTypeMDDimensionCombinedToleranceFormat) + { + A3DMDDimensionCombinedToleranceFormatData sFormatData; + A3D_INITIALIZE_DATA(A3DMDDimensionCombinedToleranceFormatData, sFormatData); + + _TiXmlElement* markup_dimtolformat = new _TiXmlElement("A3DMDDimensionCombinedToleranceFormatData"); + setting->LinkEndChild(markup_dimtolformat); + + iRet = A3DMDDimensionCombinedToleranceFormatGet(psToleranceFormat, &sFormatData); + if(iRet != A3D_SUCCESS) + { + markup_dimtolformat->SetAttribute("psToleranceFormat", "NULL"); + return; + } + + markup_dimtolformat->SetAttribute("m_pcName", (sFormatData.m_pcName && sFormatData.m_pcName[0]!=0)?sFormatData.m_pcName:"no name"); + markup_dimtolformat->SetAttribute("m_iType", sFormatData.m_iType); + sttraverseDimensionToleranceSimpleFormat(sFormatData.m_pToleranceFormat1, markup_dimtolformat); + markup_dimtolformat->SetDoubleAttribute("m_dExtX1", sFormatData.m_dExtX1); + markup_dimtolformat->SetDoubleAttribute("m_dExtY1", sFormatData.m_dExtY1); + markup_dimtolformat->SetAttribute("m_iAnchorPt1", sFormatData.m_iAnchorPt1); + markup_dimtolformat->SetAttribute("m_iPtOnValue1", sFormatData.m_iPtOnValue1); + markup_dimtolformat->SetAttribute("m_iSepar_1", sFormatData.m_iSepar_1); + sttraverseDimensionToleranceSimpleFormat(sFormatData.m_pToleranceFormat2, markup_dimtolformat); + markup_dimtolformat->SetDoubleAttribute("m_dExtX2", sFormatData.m_dExtX2); + markup_dimtolformat->SetDoubleAttribute("m_dExtY2", sFormatData.m_dExtY2); + markup_dimtolformat->SetAttribute("m_iAnchorPt2", sFormatData.m_iAnchorPt2); + markup_dimtolformat->SetAttribute("m_iPtOnValue2", sFormatData.m_iPtOnValue2); + markup_dimtolformat->SetAttribute("m_iSepar_2", sFormatData.m_iSepar_2); + A3DMDDimensionCombinedToleranceFormatGet(NULL, &sFormatData); + } + else + setting->SetAttribute("A3DMDDimensionToleranceFormat", "unexpected type"); +} + +//###################################################################################################################### +static void sttraverseDimensionValue(const A3DMDDimensionValue* psValue, _TiXmlElement* setting) +{ + A3DMDDimensionValueData sValueData; + A3D_INITIALIZE_DATA(A3DMDDimensionValueData, sValueData); + + _TiXmlElement* markup_dimvalue = new _TiXmlElement("A3DMDDimensionValueData"); + setting->LinkEndChild(markup_dimvalue); + + A3DStatus iRet = A3DMDDimensionValueGet(psValue, &sValueData); + if(iRet != A3D_SUCCESS) + { + markup_dimvalue->SetAttribute("error", iRet); + return; + } + if(sValueData.m_iType == 0) + markup_dimvalue->SetAttribute("m_iType", "true value"); + else if(sValueData.m_iType == 1) + markup_dimvalue->SetAttribute("m_iType", "fake num value"); + else if(sValueData.m_iType == 2) + markup_dimvalue->SetAttribute("m_iType", "fake alpha num value"); + else + markup_dimvalue->SetAttribute("m_iType", "unexpected"); + + markup_dimvalue->SetAttribute("m_bFormat", sValueData.m_bFormat ? "decimal format" : "fractional"); + markup_dimvalue->SetDoubleAttribute("m_dAccuracy", sValueData.m_dAccuracy); + markup_dimvalue->SetDoubleAttribute("m_dToleranceAccuracy", sValueData.m_dToleranceAccuracy); + markup_dimvalue->SetAttribute("m_pcFakeValue", sValueData.m_pcFakeValue ? sValueData.m_pcFakeValue : "null"); + markup_dimvalue->SetDoubleAttribute("m_dTolNumSup", sValueData.m_dTolNumSup); + markup_dimvalue->SetDoubleAttribute("m_dTolNumInf", sValueData.m_dTolNumInf); + markup_dimvalue->SetAttribute("m_pcTolTxtSup", sValueData.m_pcTolTxtSup ? sValueData.m_pcTolTxtSup : "null"); + markup_dimvalue->SetAttribute("m_pcTolTxtInf", sValueData.m_pcTolTxtInf ? sValueData.m_pcTolTxtInf : "null"); + markup_dimvalue->SetAttribute("m_pcBeforeText", sValueData.m_pcBeforeText ? sValueData.m_pcBeforeText : "null"); + markup_dimvalue->SetAttribute("m_pcAfterText", sValueData.m_pcAfterText ? sValueData.m_pcAfterText : "null"); + markup_dimvalue->SetAttribute("m_pcAboveText", sValueData.m_pcAboveText ? sValueData.m_pcAboveText : "null"); + markup_dimvalue->SetAttribute("m_pcBelowText", sValueData.m_pcBelowText ? sValueData.m_pcBelowText : "null"); + markup_dimvalue->SetAttribute("m_usLastSeparDefinedNum", sValueData.m_usLastSeparDefinedNum); + + markup_dimvalue->SetAttribute("m_iOption", sValueData.m_iOption); + markup_dimvalue->SetDoubleAttribute("m_dDeltaForMinMax", sValueData.m_dDeltaForMinMax); + + sttraverseDimensionValueFormat(sValueData.m_pDimValueFormat, markup_dimvalue); + sttraverseDimensionToleranceFormat(sValueData.m_pToleranceFormat, markup_dimvalue); + + if(sValueData.m_pChamferDimSecondValue) + sttraverseDimensionValue(sValueData.m_pChamferDimSecondValue, markup_dimvalue); + + A3DMDDimensionValueGet(NULL, &sValueData); +} + +//###################################################################################################################### +static void sttraverseDimensionExtentionLine(const A3DMDDimensionExtentionLine* psExtentionLine, _TiXmlElement* setting) +{ + A3DMDDimensionExtentionLineData sData; + A3D_INITIALIZE_DATA(A3DMDDimensionExtentionLineData, sData); + + _TiXmlElement* markup_extline = new _TiXmlElement("A3DMDDimensionExtentionLineData"); + setting->LinkEndChild(markup_extline); + + A3DStatus iRet = A3DMDDimensionExtentionLineGet(psExtentionLine, &sData); + if(iRet != A3D_SUCCESS) + { + markup_extline->SetAttribute("error", iRet); + return; + } + + if(sData.m_pFunnel) + { + A3DMDDimensionFunnelData sFunnelData; + A3D_INITIALIZE_DATA(A3DMDDimensionFunnelData, sFunnelData); + + _TiXmlElement* markup_funnel = new _TiXmlElement("A3DMDDimensionFunnelData"); + markup_extline->LinkEndChild(markup_funnel); + + iRet = A3DMDDimensionFunnelGet(sData.m_pFunnel, &sFunnelData); + if(iRet != A3D_SUCCESS) + { + markup_funnel->SetAttribute("error", iRet); + return; + } + + markup_funnel->SetAttribute("m_usIndex", sFunnelData.m_usIndex); + markup_funnel->SetAttribute("m_bMode", sFunnelData.m_bMode ? "true" : "false"); + markup_funnel->SetDoubleAttribute("m_dAngle", sFunnelData.m_dAngle); + markup_funnel->SetDoubleAttribute("m_dHeight", sFunnelData.m_dHeight); + markup_funnel->SetDoubleAttribute("m_dWidth", sFunnelData.m_dWidth); + A3DMDDimensionFunnelGet(NULL, &sFunnelData); + } + + _TiXmlElement* markup_ext1 = new _TiXmlElement("m_sExtremity1"); + markup_extline->LinkEndChild(markup_ext1); + markup_ext1->SetAttribute("m_bShow", sData.m_sExtremity1.m_bShow ? "true" : "false"); + markup_ext1->SetDoubleAttribute("m_dBlanking", sData.m_sExtremity1.m_dBlanking); + markup_ext1->SetDoubleAttribute("m_dOverrun", sData.m_sExtremity1.m_dOverrun); + + _TiXmlElement* markup_ext2 = new _TiXmlElement("m_sExtremity2"); + markup_extline->LinkEndChild(markup_ext2); + markup_ext2->SetAttribute("m_bShow", sData.m_sExtremity2.m_bShow ? "true" : "false"); + markup_ext2->SetDoubleAttribute("m_dBlanking", sData.m_sExtremity2.m_dBlanking); + markup_ext2->SetDoubleAttribute("m_dOverrun", sData.m_sExtremity2.m_dOverrun); + + markup_extline->SetDoubleAttribute("m_dLineSlant", sData.m_dLineSlant); + markup_extline->SetAttribute("m_usStyle", sData.m_usStyle); + markup_extline->SetDoubleAttribute("m_fThickness", sData.m_fThickness); + + A3DMDDimensionExtentionLineGet(NULL, &sData); +} + +//###################################################################################################################### +static void sttraverseDimensionLineSymbol(const A3DMDDimensionLineSymbol* psLineSymbol, _TiXmlElement* setting) +{ + if(psLineSymbol == NULL) + return; + + A3DMDDimensionLineSymbolData sData; + A3D_INITIALIZE_DATA(A3DMDDimensionLineSymbolData, sData); + + _TiXmlElement* markup_dimline = new _TiXmlElement("A3DMDDimensionLineSymbolData"); + setting->LinkEndChild(markup_dimline); + + A3DStatus iRet = A3DMDDimensionLineSymbolGet(psLineSymbol, &sData); + if(iRet != A3D_SUCCESS) + { + markup_dimline->SetAttribute("error", iRet); + return; + } + + markup_dimline->SetAttribute("m_eShape", sData.m_eShape); + markup_dimline->SetAttribute("m_iLineColor", sData.m_iLineColor); + markup_dimline->SetDoubleAttribute("m_fThickness", sData.m_fThickness); + markup_dimline->SetDoubleAttribute("m_fArrowLength", sData.m_fArrowLength); + markup_dimline->SetDoubleAttribute("m_fArrowAngle", sData.m_fArrowAngle); + A3DMDDimensionLineSymbolGet(NULL, &sData); +} + + +//###################################################################################################################### +static void sttraverseDimensionSecondPart(const A3DMDDimensionSecondPart* psSecondPart, _TiXmlElement* setting) +{ + if (psSecondPart == NULL) + return; + + A3DMDDimensionSecondPartData sData; + A3D_INITIALIZE_DATA(A3DMDDimensionSecondPartData, sData); + + _TiXmlElement* markup_secondpart = new _TiXmlElement("A3DMDDimensionSecondPartData"); + setting->LinkEndChild(markup_secondpart); + + A3DStatus iRet = A3DMDDimensionSecondPartGet(psSecondPart, &sData); + if (iRet != A3D_SUCCESS) + { + markup_secondpart->SetAttribute("error", iRet); + return; + } + + markup_secondpart->SetAttribute("m_eOrientation", sData.m_eOrientation); + markup_secondpart->SetDoubleAttribute("m_dAngle", sData.m_dAngle); + markup_secondpart->SetDoubleAttribute("m_dOffSet", sData.m_dOffSet); + + A3DMDDimensionSecondPartGet(NULL, &sData); +} + + +//###################################################################################################################### +static void sttraverseDimensionForeshortened(const A3DMDDimensionForeshortened* psForeshortened, _TiXmlElement* setting) +{ + if (psForeshortened == NULL) + return; + + A3DMDDimensionForeshortenedData sData; + A3D_INITIALIZE_DATA(A3DMDDimensionForeshortenedData, sData); + + _TiXmlElement* markup_Foreshortened = new _TiXmlElement("A3DMDDimensionForeshortenedData"); + setting->LinkEndChild(markup_Foreshortened); + + A3DStatus iRet = A3DMDDimensionForeshortenedGet(psForeshortened, &sData); + if (iRet != A3D_SUCCESS) + { + markup_Foreshortened->SetAttribute("error", iRet); + return; + } + + markup_Foreshortened->SetAttribute("m_bOrientation", sData.m_bOrientation); + markup_Foreshortened->SetAttribute("m_bTextPosition", sData.m_bTextPosition); + markup_Foreshortened->SetDoubleAttribute("m_dAngle", sData.m_dAngle); + markup_Foreshortened->SetDoubleAttribute("m_fRatio", sData.m_fRatio); + markup_Foreshortened->SetAttribute("m_usPointScale", sData.m_usPointScale); + + A3DMDDimensionForeshortenedGet(NULL, &sData); +} + +//###################################################################################################################### +static void sttraverseDimensionLine(const A3DMDDimensionLine* psLine, _TiXmlElement* setting) +{ + if (psLine == NULL) + return; + + A3DMDDimensionLineData sData; + A3D_INITIALIZE_DATA(A3DMDDimensionLineData, sData); + + _TiXmlElement* markup_dimline = new _TiXmlElement("A3DMDDimensionLineData"); + setting->LinkEndChild(markup_dimline); + + A3DStatus iRet = A3DMDDimensionLineGet(psLine, &sData); + if (iRet != A3D_SUCCESS) + { + markup_dimline->SetAttribute("error", iRet); + return; + } + if (sData.m_pSymbol1) + { + _TiXmlElement* Symbol1 = new _TiXmlElement("Symbol1"); + markup_dimline->LinkEndChild(Symbol1); + sttraverseDimensionLineSymbol(sData.m_pSymbol1, Symbol1); + } + if (sData.m_pSymbol2) + { + _TiXmlElement* Symbol2 = new _TiXmlElement("Symbol2"); + markup_dimline->LinkEndChild(Symbol2); + sttraverseDimensionLineSymbol(sData.m_pSymbol2, Symbol2); + } + if (sData.m_pLeaderSymbol) + { + _TiXmlElement* LeaderSymbol = new _TiXmlElement("LeaderSymbol"); + markup_dimline->LinkEndChild(LeaderSymbol); + sttraverseDimensionLineSymbol(sData.m_pLeaderSymbol, LeaderSymbol); + } + + markup_dimline->SetAttribute("m_eGraphRepresentation", sData.m_eGraphRepresentation); + if (sData.m_pSecondPart) + { + _TiXmlElement* SecondPart = new _TiXmlElement("SecondPart"); + markup_dimline->LinkEndChild(SecondPart); + sttraverseDimensionSecondPart(sData.m_pSecondPart, SecondPart); + } + + markup_dimline->SetAttribute("m_usStyle", sData.m_usStyle); + markup_dimline->SetDoubleAttribute("m_fThickness", sData.m_fThickness); + markup_dimline->SetAttribute("m_usReversal", sData.m_usReversal); + + if (sData.m_psForeshortened) + { + _TiXmlElement* Foreshortened = new _TiXmlElement("Foreshortened"); + markup_dimline->LinkEndChild(Foreshortened); + sttraverseDimensionForeshortened(sData.m_psForeshortened, Foreshortened); + } + markup_dimline->SetDoubleAttribute("m_dLeaderAngle", sData.m_dLeaderAngle); + markup_dimline->SetAttribute("m_eExtension", sData.m_eExtension); + + if (sData.m_pExplicitCurve) + { + _TiXmlElement* ExplicitCurve = new _TiXmlElement("ExplicitCurve"); + markup_dimline->LinkEndChild(ExplicitCurve); + traverseCurve(sData.m_pExplicitCurve, ExplicitCurve); + } + + A3DMDDimensionLineGet(NULL, &sData); +} + +//###################################################################################################################### +int traverseMarkupDimension(const A3DMarkupDimension* pMarkup, _TiXmlElement* setting) +{ + A3DMarkupDimensionData sMarkupData; + A3D_INITIALIZE_DATA(A3DMarkupDimensionData, sMarkupData); + + _TiXmlElement* markup_dim = new _TiXmlElement("A3DMarkupDimensionData"); + setting->LinkEndChild(markup_dim); + + A3DStatus iRet = A3DMarkupDimensionGet(pMarkup, &sMarkupData); + if(iRet != A3D_SUCCESS) + { + markup_dim->SetAttribute("error", iRet); + return iRet; + } + + sttraverseDimensionType(sMarkupData.m_eType, markup_dim); + sttraverseDimensionValue(sMarkupData.m_pMainValue, markup_dim); + + if(sMarkupData.m_pDualValue) + { + _TiXmlElement* markup_dualval = new _TiXmlElement("m_pDualValue"); + markup_dim->LinkEndChild(markup_dualval); + + if(sMarkupData.m_eDualDisplay == KEA3DMDDimensionDualDisplayNone) + markup_dualval->SetAttribute("m_eDualDisplay", "KEA3DMDDimensionDualDisplayNone"); + else if(sMarkupData.m_eDualDisplay == KEA3DMDDimensionDualDisplayBelow) + markup_dualval->SetAttribute("m_eDualDisplay", "KEA3DMDDimensionDualDisplayBelow"); + else if(sMarkupData.m_eDualDisplay == KEA3DMDDimensionDualDisplayFractional) + markup_dualval->SetAttribute("m_eDualDisplay", "KEA3DMDDimensionDualDisplayFractional"); + else if(sMarkupData.m_eDualDisplay == KEA3DMDDimensionDualDisplaySideBySide) + markup_dualval->SetAttribute("m_eDualDisplay", "KEA3DMDDimensionDualDisplaySideBySide"); + else + markup_dualval->SetAttribute("m_eDualDisplay", "unexpected"); + + sttraverseDimensionValue(sMarkupData.m_pDualValue, markup_dualval); + } + + markup_dim->SetDoubleAttribute("m_dValue", sMarkupData.m_dValue); + markup_dim->SetAttribute("m_eSymbol", sMarkupData.m_eSymbol); + markup_dim->SetAttribute("m_eAdditionnalSymbol", sMarkupData.m_eAdditionnalSymbol); + markup_dim->SetAttribute("m_pcSuffixe", sMarkupData.m_pcSuffixe?sMarkupData.m_pcSuffixe : "null"); + markup_dim->SetAttribute("m_pcPrefixe", sMarkupData.m_pcPrefixe?sMarkupData.m_pcPrefixe : "null"); + if(sMarkupData.m_eType == KEA3DMDDimensionTypeChamfer) + markup_dim->SetDoubleAttribute("m_dChamferDimSecondValue", sMarkupData.m_dChamferDimSecondValue); + + sttraverseDimensionExtentionLine(sMarkupData.m_pExtentionLine, markup_dim); + sttraverseDimensionLine(sMarkupData.m_pLine, markup_dim); + markup_dim->SetAttribute("m_eOrientation", sMarkupData.m_eOrientation); + markup_dim->SetAttribute("m_usPosition", sMarkupData.m_usPosition); + + _TiXmlElement* markup_frame = new _TiXmlElement("Frame"); + markup_dim->LinkEndChild(markup_frame); + markup_frame->SetAttribute("m_eFrame", sMarkupData.m_eFrame); + markup_frame->SetAttribute("m_usFrame", sMarkupData.m_usFrame); + markup_frame->SetAttribute("m_usFrameGroup", sMarkupData.m_usFrameGroup); + + _TiXmlElement* markup_score = new _TiXmlElement("Score"); + markup_dim->LinkEndChild(markup_score); + markup_score->SetAttribute("m_eScore", sMarkupData.m_eScore); + markup_score->SetAttribute("m_usScore", sMarkupData.m_usScore); + markup_score->SetAttribute("m_usScoreGroup", sMarkupData.m_usScoreGroup); + + traverseMarkupTextProperties(sMarkupData.m_pTextProperties, markup_dim); + + return A3DMarkupDimensionGet(NULL, &sMarkupData); +} + +//###################################################################################################################### +int traverseToleranceSizeValue(const A3DMDToleranceSizeValue* pToleranceSizeValue, _TiXmlElement* setting) +{ + A3DMDToleranceSizeValueData sToleranceSizeValueData; + A3D_INITIALIZE_DATA(A3DMDToleranceSizeValueData, sToleranceSizeValueData); + + _TiXmlElement* markup_ToleranceSizeValue = new _TiXmlElement("A3DMDToleranceSizeValueData"); + setting->LinkEndChild(markup_ToleranceSizeValue); + + A3DStatus iRet = A3DMDToleranceSizeValueGet(pToleranceSizeValue, &sToleranceSizeValueData); + if (iRet != A3D_SUCCESS) + { + markup_ToleranceSizeValue->SetAttribute("error", iRet); + return iRet; + } + sttraverseDimensionType(sToleranceSizeValueData.m_eType, markup_ToleranceSizeValue); + markup_ToleranceSizeValue->SetDoubleAttribute("m_dValue", sToleranceSizeValueData.m_dValue); + + markup_ToleranceSizeValue->SetAttribute("m_pcSeparator", sToleranceSizeValueData.m_pcSeparator ? sToleranceSizeValueData.m_pcSeparator : "null"); + + _TiXmlElement* MainValue = new _TiXmlElement("A3DMDDimensionValue"); + markup_ToleranceSizeValue->LinkEndChild(MainValue); + if (sToleranceSizeValueData.m_sMainValue.m_iType == 0) + MainValue->SetAttribute("m_iType", "true value"); + else if (sToleranceSizeValueData.m_sMainValue.m_iType == 1) + MainValue->SetAttribute("m_iType", "fake num value"); + else if (sToleranceSizeValueData.m_sMainValue.m_iType == 2) + MainValue->SetAttribute("m_iType", "fake alpha num value"); + else + MainValue->SetAttribute("m_iType", "unexpected"); + + MainValue->SetAttribute("m_bFormat", sToleranceSizeValueData.m_sMainValue.m_bFormat ? "decimal format" : "fractional"); + MainValue->SetDoubleAttribute("m_dAccuracy", sToleranceSizeValueData.m_sMainValue.m_dAccuracy); + MainValue->SetDoubleAttribute("m_dToleranceAccuracy", sToleranceSizeValueData.m_sMainValue.m_dToleranceAccuracy); + MainValue->SetAttribute("m_pcFakeValue", sToleranceSizeValueData.m_sMainValue.m_pcFakeValue ? sToleranceSizeValueData.m_sMainValue.m_pcFakeValue : "null"); + MainValue->SetDoubleAttribute("m_dTolNumSup", sToleranceSizeValueData.m_sMainValue.m_dTolNumSup); + MainValue->SetDoubleAttribute("m_dTolNumInf", sToleranceSizeValueData.m_sMainValue.m_dTolNumInf); + MainValue->SetAttribute("m_pcTolTxtSup", sToleranceSizeValueData.m_sMainValue.m_pcTolTxtSup ? sToleranceSizeValueData.m_sMainValue.m_pcTolTxtSup : "null"); + MainValue->SetAttribute("m_pcTolTxtInf", sToleranceSizeValueData.m_sMainValue.m_pcTolTxtInf ? sToleranceSizeValueData.m_sMainValue.m_pcTolTxtInf : "null"); + MainValue->SetAttribute("m_pcBeforeText", sToleranceSizeValueData.m_sMainValue.m_pcBeforeText ? sToleranceSizeValueData.m_sMainValue.m_pcBeforeText : "null"); + MainValue->SetAttribute("m_pcAfterText", sToleranceSizeValueData.m_sMainValue.m_pcAfterText ? sToleranceSizeValueData.m_sMainValue.m_pcAfterText : "null"); + MainValue->SetAttribute("m_pcAboveText", sToleranceSizeValueData.m_sMainValue.m_pcAboveText ? sToleranceSizeValueData.m_sMainValue.m_pcAboveText : "null"); + MainValue->SetAttribute("m_pcBelowText", sToleranceSizeValueData.m_sMainValue.m_pcBelowText ? sToleranceSizeValueData.m_sMainValue.m_pcBelowText : "null"); + MainValue->SetAttribute("m_usLastSeparDefinedNum", sToleranceSizeValueData.m_sMainValue.m_usLastSeparDefinedNum); + + MainValue->SetAttribute("m_iOption", sToleranceSizeValueData.m_sMainValue.m_iOption); + MainValue->SetDoubleAttribute("m_dDeltaForMinMax", sToleranceSizeValueData.m_sMainValue.m_dDeltaForMinMax); + + sttraverseDimensionValueFormat(sToleranceSizeValueData.m_sMainValue.m_pDimValueFormat, MainValue); + sttraverseDimensionToleranceFormat(sToleranceSizeValueData.m_sMainValue.m_pToleranceFormat, MainValue); + + if (sToleranceSizeValueData.m_sMainValue.m_pChamferDimSecondValue) + sttraverseDimensionValue(sToleranceSizeValueData.m_sMainValue.m_pChamferDimSecondValue, MainValue); + + sttraverseDimensionValue(sToleranceSizeValueData.m_pDualValue, MainValue); + + return A3DMDToleranceSizeValueGet(NULL, &sToleranceSizeValueData); +} \ No newline at end of file diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLMarkupGDT.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLMarkupGDT.cpp new file mode 100644 index 0000000..6816f4d --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLMarkupGDT.cpp @@ -0,0 +1,658 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "PRC2XML.h" + + + +//###################################################################################################################### +static void stvAddModifier(int iModifier, _TiXmlElement* setting) +{ + switch(iModifier) + { + case KEA3DGDTModifierNone: setting->SetAttribute("m_eModifier", "none"); break; + case KEA3DGDTModifierMax: setting->SetAttribute("m_eModifier", "maximum material condition"); break; + case KEA3DGDTModifierMin: setting->SetAttribute("m_eModifier", "least material condition"); break; + case KEA3DGDTModifierProj: setting->SetAttribute("m_eModifier", "projected tolerance zone"); break; + case KEA3DGDTModifierFree: setting->SetAttribute("m_eModifier", "free state"); break; + case KEA3DGDTModifierRfs: setting->SetAttribute("m_eModifier", "regardless of feature size"); break; + case KEA3DGDTModifierTangent: setting->SetAttribute("m_eModifier", "tangent plane"); break; + case KEA3DGDTModifierST: setting->SetAttribute("m_eModifier", "statical"); break; + default: setting->SetAttribute("m_eModifier", "unexpected"); break; + } +} + +//###################################################################################################################### +static void stvAddGDTType(int itype, _TiXmlElement* setting) +{ + switch(itype) + { + case KEA3DGDTTypeNone: setting->SetAttribute("m_eType", "none"); break; + case KEA3DGDTTypeStraightness: setting->SetAttribute("m_eType", "Straightness"); break; + case KEA3DGDTTypeFlatness: setting->SetAttribute("m_eType", "Flatness"); break; + case KEA3DGDTTypeCircularity: setting->SetAttribute("m_eType", "Circularity"); break; + case KEA3DGDTTypeCylindricity: setting->SetAttribute("m_eType", "Cylindricity"); break; + case KEA3DGDTTypeLineProfile: setting->SetAttribute("m_eType", "Profile of a line"); break; + case KEA3DGDTTypeSurfaceProfile: setting->SetAttribute("m_eType", "Profile of a surface"); break; + case KEA3DGDTTypeAngularity: setting->SetAttribute("m_eType", "Angularity"); break; + case KEA3DGDTTypePerpendicularity: setting->SetAttribute("m_eType", "Perpendicularity"); break; + case KEA3DGDTTypeParallelism: setting->SetAttribute("m_eType", "Parallel"); break; + case KEA3DGDTTypePosition: setting->SetAttribute("m_eType", "Positional"); break; + case KEA3DGDTTypeConcentricity: setting->SetAttribute("m_eType", "Concentricity"); break; + case KEA3DGDTTypeSymmetry: setting->SetAttribute("m_eType", "Symmetric"); break; + case KEA3DGDTTypeCircularRunout: setting->SetAttribute("m_eType", "Circular run out"); break; + case KEA3DGDTTypeTotalRunout: setting->SetAttribute("m_eType", "Total run out"); break; + default: setting->SetAttribute("m_eType", "unexpected"); break; + } +} + +static int sttraverseFCFDraftingIndicator(const A3DMDFCFDraftingIndicatorData& sData, _TiXmlElement* indicator); +//###################################################################################################################### +static int sttraverseDraftingRow(const A3DMDFCFDraftingRow *psRow, _TiXmlElement* setting) +{ + A3DMDFCFDraftingRowData sData; + A3D_INITIALIZE_DATA(A3DMDFCFDraftingRowData, sData); + + _TiXmlElement* drft_row = new _TiXmlElement("A3DMDFCFDraftingRowData"); + setting->LinkEndChild(drft_row); + + A3DStatus iRet = A3DMDFCFDraftingRowGet(psRow, &sData); + if(iRet != A3D_SUCCESS) + { + drft_row->SetAttribute("error", iRet); + return iRet; + } + + stvAddGDTType(sData.m_eType, drft_row); + + _TiXmlElement* row_boxes = new _TiXmlElement("A3DMDFCFDraftingRowData"); + drft_row->LinkEndChild(row_boxes); + if(sData.m_uiNumberOfTextsInBoxes == 0) + row_boxes->SetAttribute("error", "no box"); + + A3DUns32 i; + char sName[20]; + for(i = 0; i < sData.m_uiNumberOfTextsInBoxes; ++i) + { + sprintf_s(sName,sizeof(sName)-1, "box_%u", i); + if(sData.m_ppcTextsInBoxes[i] == NULL) + { + row_boxes->SetAttribute("error", "no text in box"); + continue; + } + row_boxes->SetAttribute(sName, sData.m_ppcTextsInBoxes[i]); + } + if (sData.m_uiNumberOfIndicators) + { + _TiXmlElement* indicators = new _TiXmlElement("m_ppIndicators"); + drft_row->LinkEndChild(indicators); + for (i = 0; i < sData.m_uiNumberOfIndicators; ++i) + { + A3DMDFCFDraftingIndicatorData sIndicatorData; + A3D_INITIALIZE_DATA(A3DMDFCFDraftingIndicatorData, sIndicatorData); + iRet = A3DMDFCFDraftingIndicatorGet(sData.m_ppIndicators[i], &sIndicatorData); + if (iRet == A3D_SUCCESS) + { + _TiXmlElement* indicator = new _TiXmlElement("A3DMDFCFIndicatorData"); + indicators->LinkEndChild(indicator); + sttraverseFCFDraftingIndicator(sIndicatorData, indicator); + A3DMDFCFDraftingIndicatorGet(nullptr, &sIndicatorData); + } + else + { + drft_row->SetAttribute("error", "A3DMDFCFIndicatorGet"); + } + } + } + return A3DMDFCFDraftingRowGet(NULL, &sData); +} + +//###################################################################################################################### +static int sttraverseDatumReference(const char* pcTitle, A3DMDFCFRowDatum* psDatum, _TiXmlElement* drw_row) +{ + _TiXmlElement* datum_ref = new _TiXmlElement(pcTitle); + drw_row->LinkEndChild(datum_ref); + + A3DMDFCFRowDatumData sDatumData; + A3D_INITIALIZE_DATA(A3DMDFCFRowDatumData, sDatumData); + + A3DStatus iRet = A3DMDFCFRowDatumGet(psDatum, &sDatumData); + if(iRet != A3D_SUCCESS) + { + drw_row->SetAttribute("error", iRet); + return A3D_SUCCESS; + } + + datum_ref->SetAttribute("m_pcDatum", sDatumData.m_pcDatum?sDatumData.m_pcDatum : "null"); + stvAddModifier(sDatumData.m_eModifier, datum_ref); + + if(sDatumData.m_pLinkedItem) + traverseLinkedItem(sDatumData.m_pLinkedItem, datum_ref); + A3DMDFCFRowDatum* pNext = nullptr; + if ((pNext = sDatumData.m_pNext)!= nullptr) + { + A3DMDFCFRowDatumGet(nullptr, &sDatumData); + return sttraverseDatumReference("next", pNext, datum_ref); + } + + return A3DMDFCFRowDatumGet(nullptr, &sDatumData); +} + +//###################################################################################################################### +static int sttraverseRowToleranceValue(const A3DMDFCFToleranceValueData& sToleranceData, _TiXmlElement* semantic_value) +{ + A3DStatus iRet = A3D_SUCCESS; + // value + if (sToleranceData.m_eValueType == KEA3DGDTValueNone) + semantic_value->SetAttribute("m_eValueType", "none"); + else if (sToleranceData.m_eValueType == KEA3DGDTValueDiameter) + semantic_value->SetAttribute("m_eValueType", "diameter"); + else if (sToleranceData.m_eValueType == KEA3DGDTValueRadius) + semantic_value->SetAttribute("m_eValueType", "radius"); + else if (sToleranceData.m_eValueType == KEA3DGDTValueSpherical) + semantic_value->SetAttribute("m_eValueType", "spherical"); + else + semantic_value->SetAttribute("m_eValueType", "unexpected"); + + + // modifier + stvAddModifier(sToleranceData.m_eModifier, semantic_value); + semantic_value->SetAttribute("m_bFreeState", sToleranceData.m_bFreeState ? "true" : "false"); + semantic_value->SetAttribute("m_bStatistical", sToleranceData.m_bStatistical ? "true" : "false"); + + + // main value + if (sToleranceData.m_sValue.m_bIsValue) + { + if (sToleranceData.m_sValue.m_pcValue == NULL) + semantic_value->SetAttribute("m_sValue.m_pcValue", "NULL"); + else + semantic_value->SetAttribute("m_sValue.m_pcValue", sToleranceData.m_sValue.m_pcValue); + } + else + semantic_value->SetDoubleAttribute("m_sValue.m_dValue", sToleranceData.m_sValue.m_dValue); + + // tolerance per unit + if (sToleranceData.m_psTolerancePerUnit) + { + _TiXmlElement* tol_per_unit = new _TiXmlElement("m_psTolerancePerUnit"); + semantic_value->LinkEndChild(tol_per_unit); + + A3DMDFCTolerancePerUnitData sTolerancePerUnitData; + A3D_INITIALIZE_DATA(A3DMDFCTolerancePerUnitData, sTolerancePerUnitData); + + iRet = A3DMDFCTolerancePerUnitGet(sToleranceData.m_psTolerancePerUnit, &sTolerancePerUnitData); + if (iRet != A3D_SUCCESS) + { + tol_per_unit->SetAttribute("error", iRet); + return iRet; + } + + tol_per_unit->SetDoubleAttribute("m_dUnitLengthOrAreaFirstValue", sTolerancePerUnitData.m_dUnitLengthOrAreaFirstValue); + if (sTolerancePerUnitData.m_pdUnitAreaSecondLength) + tol_per_unit->SetDoubleAttribute("m_pdUnitAreaSecondLength", *sTolerancePerUnitData.m_pdUnitAreaSecondLength); + + if (sTolerancePerUnitData.m_psRefinementZone) + { + _TiXmlElement* tol_per_unit_ref = new _TiXmlElement("m_psRefinementZone"); + tol_per_unit->LinkEndChild(tol_per_unit_ref); + + A3DMDFCValueData sValueData; + A3D_INITIALIZE_DATA(A3DMDFCValueData, sValueData); + + iRet = A3DMDFCValueGet(sTolerancePerUnitData.m_psRefinementZone, &sValueData); + if (iRet != A3D_SUCCESS) + { + tol_per_unit_ref->SetAttribute("refinement_zone_error", iRet); + return iRet; + } + + if (sValueData.m_bIsValue) + { + if (sValueData.m_pcValue == NULL) + tol_per_unit_ref->SetAttribute("m_sValue.m_pcValue", "NULL"); + else + tol_per_unit_ref->SetAttribute("m_sValue.m_pcValue", sValueData.m_pcValue); + } + else + tol_per_unit_ref->SetDoubleAttribute("m_sValue.m_dValue", sValueData.m_dValue); + + CHECK_RET(A3DMDFCValueGet(NULL, &sValueData)); + } + + CHECK_RET(A3DMDFCTolerancePerUnitGet(NULL, &sTolerancePerUnitData)); + } + + // projected zone + if (sToleranceData.m_psProjectedZone) + { + _TiXmlElement* proj_zone = new _TiXmlElement("m_psProjectedZone"); + semantic_value->LinkEndChild(proj_zone); + + A3DMDFCProjectedZoneData sProjectedZoneData; + A3D_INITIALIZE_DATA(A3DMDFCProjectedZoneData, sProjectedZoneData); + + iRet = A3DMDFCProjectedZoneGet(sToleranceData.m_psProjectedZone, &sProjectedZoneData); + if (iRet != A3D_SUCCESS) + { + proj_zone->SetAttribute("error", iRet); + return iRet; + } + + if (sProjectedZoneData.m_sLength.m_bIsValue) + { + if (sProjectedZoneData.m_sLength.m_pcValue == NULL) + proj_zone->SetAttribute("m_sLength.m_pcValue", "NULL"); + else + proj_zone->SetAttribute("m_sLength.m_pcValue", sProjectedZoneData.m_sLength.m_pcValue); + } + else + proj_zone->SetDoubleAttribute("m_sLength.m_dValue", sProjectedZoneData.m_sLength.m_dValue); + + if (sProjectedZoneData.m_pdPosition) + proj_zone->SetDoubleAttribute("m_pdPosition", *sProjectedZoneData.m_pdPosition); + CHECK_RET(A3DMDFCProjectedZoneGet(NULL, &sProjectedZoneData)); + } + + // profile tolerance offset + if (sToleranceData.m_psProfileTolerance) + { + _TiXmlElement* prof_tolerance = new _TiXmlElement("m_psProfileTolerance"); + semantic_value->LinkEndChild(prof_tolerance); + + A3DMDFCValueData sValueData; + A3D_INITIALIZE_DATA(A3DMDFCValueData, sValueData); + + iRet = A3DMDFCValueGet(sToleranceData.m_psProfileTolerance, &sValueData); + if (iRet != A3D_SUCCESS) + { + prof_tolerance->SetAttribute("profile_tolerance_error", iRet); + return iRet; + } + + if (sValueData.m_bIsValue) + { + if (sValueData.m_pcValue == NULL) + prof_tolerance->SetAttribute("m_sValue.m_pcValue", "NULL"); + else + prof_tolerance->SetAttribute("m_sValue.m_pcValue", sValueData.m_pcValue); + } + else + prof_tolerance->SetDoubleAttribute("m_dValue", sValueData.m_dValue); + + CHECK_RET(A3DMDFCValueGet(NULL, &sValueData)); + } + + // maximum bonus + if (sToleranceData.m_psMaximumBonus) + { + _TiXmlElement* max_bonus = new _TiXmlElement("m_psMaximumBonus"); + semantic_value->LinkEndChild(max_bonus); + A3DMDFCValueData sValueData; + A3D_INITIALIZE_DATA(A3DMDFCValueData, sValueData); + iRet = A3DMDFCValueGet(sToleranceData.m_psMaximumBonus, &sValueData); + if (iRet != A3D_SUCCESS) + { + max_bonus->SetAttribute("maximum_bonus_error", iRet); + return iRet; + } + if (sValueData.m_bIsValue) + { + if (sValueData.m_pcValue == NULL) + max_bonus->SetAttribute("m_sValue.m_pcValue", "NULL"); + else + max_bonus->SetAttribute("m_sValue.m_pcValue", sValueData.m_pcValue); + } + else + max_bonus->SetDoubleAttribute("m_dValue", sValueData.m_dValue); + + CHECK_RET(A3DMDFCValueGet(NULL, &sValueData)); + } + return iRet; +} + +//###################################################################################################################### +static int sttraverseDrawingRow(const A3DMDFCFDrawingRowData& sData, _TiXmlElement* drw_row) +{ + A3DStatus iRet; + + // row type + stvAddGDTType(sData.m_eType, drw_row); + + drw_row->SetAttribute("m_pcValue", sData.m_pcValue ? sData.m_pcValue : "null"); + + // references + if(sData.m_psPrimaryRef) + sttraverseDatumReference("m_psPrimaryRef", sData.m_psPrimaryRef, drw_row); + if(sData.m_psSecondaryRef) + sttraverseDatumReference("m_psSecondaryRef", sData.m_psSecondaryRef, drw_row); + if(sData.m_psTertiaryRef) + sttraverseDatumReference("m_psTertiaryRef", sData.m_psTertiaryRef, drw_row); + + if(sData.m_psSemanticValue == NULL) + { + return A3D_SUCCESS; + } + + // semantic tolerance value + _TiXmlElement* semantic_value = new _TiXmlElement("m_psSemanticValue"); + drw_row->LinkEndChild(semantic_value); + + A3DMDFCFToleranceValueData sSemanticData; + A3D_INITIALIZE_DATA(A3DMDFCFToleranceValueData, sSemanticData); + + iRet = A3DMDFCFToleranceValueGet(sData.m_psSemanticValue, &sSemanticData); + if(iRet != A3D_SUCCESS) + { + semantic_value->SetAttribute("error", iRet); + return iRet; + } + sttraverseRowToleranceValue(sSemanticData, semantic_value); + + _TiXmlElement* semantic_value2 = new _TiXmlElement("m_psNextSemanticValue"); + drw_row->LinkEndChild(semantic_value2); + + A3DMDFCFToleranceValueData sSemanticData2; + A3D_INITIALIZE_DATA(A3DMDFCFToleranceValueData, sSemanticData2); + + iRet = A3DMDFCFToleranceValueGet(sSemanticData.m_psNext, &sSemanticData2); + if (iRet != A3D_SUCCESS) + { + semantic_value2->SetAttribute("error", iRet); + CHECK_RET(A3DMDFCFToleranceValueGet(NULL, &sSemanticData)); + return iRet; + } + + drw_row->SetAttribute("m_pcNextValue", sSemanticData2.m_sValue.m_pcValue ? sSemanticData2.m_sValue.m_pcValue : "null"); + sttraverseRowToleranceValue(sSemanticData2, semantic_value2); + CHECK_RET(A3DMDFCFToleranceValueGet(NULL, &sSemanticData2)); + CHECK_RET(A3DMDFCFToleranceValueGet(NULL, &sSemanticData)); + + return iRet; +} + +//###################################################################################################################### +static int sttraverseFCFDraftingIndicator(const A3DMDFCFDraftingIndicatorData& sData, _TiXmlElement* indicator) +{ + // type + if (sData.m_eType == kA3DFCFIndicatorType_Undef) + indicator->SetAttribute("m_eType", "none"); + else if (sData.m_eType == kA3DFCFIndicatorType_DirectionFeature) + indicator->SetAttribute("m_eType", "direction_feature"); + else if (sData.m_eType == kA3DFCFIndicatorType_CollectionPlane) + indicator->SetAttribute("m_eType", "collection_plane"); + else if (sData.m_eType == kA3DFCFIndicatorType_IntersectionPlane) + indicator->SetAttribute("m_eType", "intersection_plane"); + else if (sData.m_eType == kA3DFCFIndicatorType_OrientationPlane) + indicator->SetAttribute("m_eType", "orientation_plane"); + else if (sData.m_eType == kA3DFCFIndicatorType_Text) + indicator->SetAttribute("m_eType", "text"); + else + indicator->SetAttribute("m_eType", "unexpected"); + + char sName[20]; + for (unsigned i = 0; i < sData.m_uiNumberOfTexts; ++i) + { + sprintf(sName, "m_pctext_%u", i); + if (sData.m_ppcTexts[i]) + indicator->SetAttribute(sName, sData.m_ppcTexts[i]); + } + return A3D_SUCCESS; +} + +//###################################################################################################################### +static int sttraverseFCFIndicator(const A3DMDFCFIndicatorData& sData, _TiXmlElement* indicator) +{ + // type + if (sData.m_eType == kA3DFCFIndicatorType_Undef) + indicator->SetAttribute("m_eType", "none"); + else if (sData.m_eType == kA3DFCFIndicatorType_DirectionFeature) + indicator->SetAttribute("m_eType", "direction_feature"); + else if (sData.m_eType == kA3DFCFIndicatorType_CollectionPlane) + indicator->SetAttribute("m_eType", "collection_plane"); + else if (sData.m_eType == kA3DFCFIndicatorType_IntersectionPlane) + indicator->SetAttribute("m_eType", "intersection_plane"); + else if (sData.m_eType == kA3DFCFIndicatorType_OrientationPlane) + indicator->SetAttribute("m_eType", "orientation_plane"); + else if (sData.m_eType == kA3DFCFIndicatorType_Text) + indicator->SetAttribute("m_eType", "text"); + else + indicator->SetAttribute("m_eType", "unexpected"); + + // symbol + if (sData.m_eSymbol == kA3DFCFIndicatorSymbol_Undef) + indicator->SetAttribute("m_eSymbol", "none"); + else if (sData.m_eSymbol == kA3DFCFIndicatorSymbol_Angularity) + indicator->SetAttribute("m_eSymbol", "angularity"); + else if (sData.m_eSymbol == kA3DFCFIndicatorSymbol_Perpendicularity) + indicator->SetAttribute("m_eSymbol", "perpendicularity"); + else if (sData.m_eSymbol == kA3DFCFIndicatorSymbol_Parallelism) + indicator->SetAttribute("m_eSymbol", "parallelism"); + else if (sData.m_eSymbol == kA3DFCFIndicatorSymbol_Symmetry) + indicator->SetAttribute("m_eSymbol", "symmetry"); + else if (sData.m_eSymbol == kA3DFCFIndicatorSymbol_Runout) + indicator->SetAttribute("m_eSymbol", "runout"); + else + indicator->SetAttribute("m_eSymbol", "unexpected"); + + // datum + if (sData.m_pDatum) + sttraverseDatumReference("m_pDatum", sData.m_pDatum, indicator); + + if (sData.m_pcText && sData.m_eType == kA3DFCFIndicatorType_Text) + indicator->SetAttribute("m_pcText", sData.m_pcText); + + for (unsigned i = 0; i < sData.m_uiNumberOfLinkedItems; ++i) + { + if (sData.m_ppLinkedItems[i]) + traverseLinkedItem(sData.m_ppLinkedItems[i], indicator); + } + return A3D_SUCCESS; +} +//###################################################################################################################### +static int sttraverseFeatureControlFrameData(const A3DMDFeatureControlFrameData& sFeatureControlFrameData, + _TiXmlElement* setting) +{ + A3DUns32 r; + A3DEEntityType eType = kA3DTypeUnknown; + A3DStatus iRet; + + _TiXmlElement* fcf = new _TiXmlElement("A3DMDFeatureControlFrameData"); + setting->LinkEndChild(fcf); + + _TiXmlElement* rows = new _TiXmlElement("m_ppRows"); + fcf->LinkEndChild(rows); + for(r = 0; r < sFeatureControlFrameData.m_uiNumberOfRows; ++r) + { + iRet = A3DEntityGetType(sFeatureControlFrameData.m_ppRows[r], &eType); + if(iRet != A3D_SUCCESS) + { + rows->SetAttribute("error_A3DEntityGetType", iRet); + continue; + } + + A3DMDFCFDrawingRowData sDrawingRowData; + A3D_INITIALIZE_DATA(A3DMDFCFDrawingRowData, sDrawingRowData); + + iRet = A3DMDFCFSemanticRowGet(sFeatureControlFrameData.m_ppRows[r], &sDrawingRowData); + if(iRet == A3D_SUCCESS) + { + _TiXmlElement* drw_row = new _TiXmlElement("A3DMDFCFDrawingRowData"); + rows->LinkEndChild(drw_row); + sttraverseDrawingRow(sDrawingRowData, drw_row); + A3DMDFCFDrawingRowGet(NULL, &sDrawingRowData); + } + else + { + if(eType != kA3DTypeMDFCFDraftingRow) + rows->SetAttribute("error", "FCFRow"); + else + sttraverseDraftingRow((const A3DMDFCFDraftingRow*) sFeatureControlFrameData.m_ppRows[r], rows); + } + + } + if (sFeatureControlFrameData.m_uiNumberOfIndicators) + { + _TiXmlElement* indicators = new _TiXmlElement("m_ppIndicators"); + fcf->LinkEndChild(indicators); + for (r = 0; r < sFeatureControlFrameData.m_uiNumberOfIndicators; ++r) + { + A3DMDFCFIndicatorData sIndicatorData; + A3D_INITIALIZE_DATA(A3DMDFCFIndicatorData, sIndicatorData); + iRet = A3DMDFCFIndicatorGet(sFeatureControlFrameData.m_ppIndicators[r], &sIndicatorData); + if (iRet == A3D_SUCCESS) + { + _TiXmlElement* indicator = new _TiXmlElement("A3DMDFCFIndicatorData"); + indicators->LinkEndChild(indicator); + sttraverseFCFIndicator(sIndicatorData, indicator); + A3DMDFCFIndicatorGet(nullptr, &sIndicatorData); + } + else + { + fcf->SetAttribute("error", "A3DMDFCFIndicatorGet"); + } + } + } + return A3D_SUCCESS; +} + +//###################################################################################################################### +static int sttraverseToleranceSize(const A3DMDToleranceSize* pToleranceSize, _TiXmlElement* setting) +{ + A3DMDToleranceSizeData sToleranceSizeData; + A3D_INITIALIZE_DATA(A3DMDToleranceSizeData, sToleranceSizeData); + + _TiXmlElement* toleranceSize = new _TiXmlElement("A3DMDToleranceSizeData"); + setting->LinkEndChild(toleranceSize); + + _TiXmlElement* values = new _TiXmlElement("m_ppTolSizeValue"); + toleranceSize->LinkEndChild(values); + + A3DStatus iRet = A3DMDToleranceSizeGet(pToleranceSize, &sToleranceSizeData); + if (iRet != A3D_SUCCESS) + { + toleranceSize->SetAttribute("error", iRet); + return iRet; + } + + for (A3DUns32 i = 0; i < sToleranceSizeData.m_uiNumberOfSizeValues; ++i) + { + traverseToleranceSizeValue(sToleranceSizeData.m_ppTolSizeValue[i], toleranceSize); + } + + return iRet; +} + +//###################################################################################################################### +int traverseMarkupGDT(const A3DMarkupGDT* psMarkup, _TiXmlElement* setting) +{ + A3DMarkupGDTData sData; + A3D_INITIALIZE_DATA(A3DMarkupGDTData, sData); + + _TiXmlElement* markup_gdt = new _TiXmlElement("A3DMarkupGDTData"); + setting->LinkEndChild(markup_gdt); + + A3DStatus iRet = A3DMarkupGDTGet(psMarkup, &sData); + if(iRet != A3D_SUCCESS) + { + markup_gdt->SetAttribute("error", iRet); + return iRet; + } + + markup_gdt->SetAttribute("m_pcAboveText", sData.m_pcAboveText ? sData.m_pcAboveText : "null"); + markup_gdt->SetAttribute("m_pcBelowText", sData.m_pcBelowText ? sData.m_pcBelowText : "null"); + markup_gdt->SetAttribute("m_pcBeforeText", sData.m_pcBeforeText ? sData.m_pcBeforeText : "null"); + markup_gdt->SetAttribute("m_pcAfterText", sData.m_pcAfterText ? sData.m_pcAfterText : "null"); + + A3DUns32 i; + char sName[20]; + A3DEEntityType eType = kA3DTypeUnknown; + _TiXmlElement* tolerance = NULL; + for (i = 0; i < sData.m_uiNumberOfMarkupTolerances; ++i) + { + sprintf_s(sName, sizeof(sName)-1,"A3DMDTolerance_%u", i); + tolerance = new _TiXmlElement(sName); + markup_gdt->LinkEndChild(tolerance); + iRet = A3DEntityGetType(sData.m_ppsMarkupTolerances[i], &eType); + if (iRet != A3D_SUCCESS) + { + tolerance->SetAttribute("error", iRet); + continue; + } + if (eType == kA3DTypeMDFeatureControlFrame) + { + // semantic data + A3DMDFeatureControlFrameData sFCFData; + A3D_INITIALIZE_DATA(A3DMDFeatureControlFrameData, sFCFData); + + iRet = A3DMDSemanticFeatureControlFrameGet(sData.m_ppsMarkupTolerances[i], &sFCFData); + if (iRet == A3D_SUCCESS) + { + _TiXmlElement* semantic_data = new _TiXmlElement("SEMANTIC_DATA"); + tolerance->LinkEndChild(semantic_data); + sttraverseFeatureControlFrameData(sFCFData, semantic_data); + A3DMDSemanticFeatureControlFrameGet(NULL, &sFCFData); + } + else if (A3DMDFeatureControlFrameGet(sData.m_ppsMarkupTolerances[i], &sFCFData) == A3D_SUCCESS) + { + sttraverseFeatureControlFrameData(sFCFData, tolerance); + A3DMDFeatureControlFrameGet(NULL, &sFCFData); + } + else + tolerance->SetAttribute("error", iRet); + } + else if (eType == kA3DTypeMDToleranceSize) + { + sttraverseToleranceSize(sData.m_ppsMarkupTolerances[i], tolerance); + } + else + { + tolerance->SetAttribute("eType", "unexpected"); + continue; + } + } + + // text properties + traverseMarkupTextProperties(sData.m_pTextProperties, setting); + + return A3DMarkupGDTGet(NULL, &sData); +} + +//###################################################################################################################### +int traverseMarkupDatum(const A3DMarkupDatum* psMarkup, _TiXmlElement* setting) +{ + A3DMarkupDatumData sMarkupData; + A3D_INITIALIZE_DATA(A3DMarkupDatumData, sMarkupData); + _TiXmlElement* markup_datum = new _TiXmlElement("A3DMarkupDatumData"); + setting->LinkEndChild(markup_datum); + A3DStatus iRet = A3DMarkupDatumGet(psMarkup, &sMarkupData); + if(iRet != A3D_SUCCESS) + { + markup_datum->SetAttribute("error", iRet); + return iRet; + } + markup_datum->SetAttribute("m_pcUpText", sMarkupData.m_pcUpText?sMarkupData.m_pcUpText:"NULL"); + markup_datum->SetAttribute("m_pcDownText", sMarkupData.m_pcDownText?sMarkupData.m_pcDownText:"NULL"); + + markup_datum->SetAttribute("m_bTarget", sMarkupData.m_bTarget ? "true" : "false"); + markup_datum->SetAttribute("m_bDiameter", sMarkupData.m_bDiameter ? "true" : "false"); + markup_datum->SetAttribute("m_bIndividual", sMarkupData.m_bIndividual ? "true" : "false"); + + + markup_datum->SetAttribute("m_pcAboveText", sMarkupData.m_pcAboveText ? sMarkupData.m_pcAboveText : "null"); + markup_datum->SetAttribute("m_pcBelowText", sMarkupData.m_pcBelowText ? sMarkupData.m_pcBelowText : "null"); + markup_datum->SetAttribute("m_pcBeforeText", sMarkupData.m_pcBeforeText ? sMarkupData.m_pcBeforeText : "null"); + markup_datum->SetAttribute("m_pcAfterText", sMarkupData.m_pcAfterText ? sMarkupData.m_pcAfterText : "null"); + + traverseMarkupTextProperties(sMarkupData.m_pTextProperties, markup_datum); + return A3DMarkupDatumGet(NULL, &sMarkupData); +} diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLMarkupText.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLMarkupText.cpp new file mode 100644 index 0000000..2c2a23f --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLMarkupText.cpp @@ -0,0 +1,262 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "PRC2XML.h" + + + +//###################################################################################################################### +static void sttraverseFrameType(int iFrameType, _TiXmlElement* setting) +{ + switch(iFrameType) + { + case KA3DMarkupFrameNone: setting->SetAttribute("m_eFrameType", "No Frame"); break; + case KA3DMarkupFrameRectangle: setting->SetAttribute("m_eFrameType", "Rectangle"); break; + case KA3DMarkupFrameSquare: setting->SetAttribute("m_eFrameType", "Square"); break; + case KA3DMarkupFrameCircle: setting->SetAttribute("m_eFrameType", "Circle"); break; + case KA3DMarkupFrameScoredCircle: setting->SetAttribute("m_eFrameType", "Scored Circle"); break; + case KA3DMarkupFrameDiamond: setting->SetAttribute("m_eFrameType", "Diamond"); break; + case KA3DMarkupFrameTriangle: setting->SetAttribute("m_eFrameType", "Triangle"); break; + case KA3DMarkupFrameRightFlag: setting->SetAttribute("m_eFrameType", "Right Flag"); break; + case KA3DMarkupFrameLeftFlag: setting->SetAttribute("m_eFrameType", "Left Flag"); break; + case KA3DMarkupFrameBothFlag: setting->SetAttribute("m_eFrameType", "Both Flag"); break; + case KA3DMarkupFrameOblong: setting->SetAttribute("m_eFrameType", "Oblong"); break; + case KA3DMarkupFrameEllipse: setting->SetAttribute("m_eFrameType", "Ellipse"); break; + case KA3DMarkupFrameFixRectangle: setting->SetAttribute("m_eFrameType", "Fixed Rectangle"); break; + case KA3DMarkupFrameFixSquare: setting->SetAttribute("m_eFrameType", "Fixed Square"); break; + case KA3DMarkupFrameFixCircle: setting->SetAttribute("m_eFrameType", "Fixed Circle"); break; + case KA3DMarkupFrameFixScoredCircle: setting->SetAttribute("m_eFrameType", "Fixed Scored Circle"); break; + case KA3DMarkupFrameFixDiamond: setting->SetAttribute("m_eFrameType", "Fixed Diamond"); break; + case KA3DMarkupFrameFixTriangle: setting->SetAttribute("m_eFrameType", "Fixed Triangle"); break; + case KA3DMarkupFrameFixRightFlag: setting->SetAttribute("m_eFrameType", "Fixed Right Flag"); break; + case KA3DMarkupFrameFixLeftFlag: setting->SetAttribute("m_eFrameType", "Fixed Left Flag"); break; + case KA3DMarkupFrameFixBothFlag: setting->SetAttribute("m_eFrameType", "Fixed Both Flag"); break; + case KA3DMarkupFrameFixOblong: setting->SetAttribute("m_eFrameType", "Fixed Oblong"); break; + case KA3DMarkupFrameFixEllipse: setting->SetAttribute("m_eFrameType", "Fixed Ellipse"); break; + case KA3DMarkupFrameCustom: setting->SetAttribute("m_eFrameType", "Custom"); break; + default: setting->SetAttribute("m_eFrameType", "unexpected"); break; + } +} + +//###################################################################################################################### +static void sttraverseAlignmentType(int iAlignmentType, _TiXmlElement* setting) +{ + switch(iAlignmentType) + { + case KA3DLeaderAlignment_Simple: setting->SetAttribute("m_eLeaderAlignmentType", "Simple"); break; + case KA3DLeaderAlignment_Below: setting->SetAttribute("m_eLeaderAlignmentType", "Below"); break; + case KA3DLeaderAlignment_Underline: setting->SetAttribute("m_eLeaderAlignmentType", "Underline"); break; + case KA3DLeaderAlignment_ExtToMax: setting->SetAttribute("m_eLeaderAlignmentType", "Extend to line maximum"); break; + case KA3DLeaderAlignment_OnBoxPoint: setting->SetAttribute("m_eLeaderAlignmentType", "On box point"); break; + case KA3DLeaderAlignment_SimpleOnBoxPoint: setting->SetAttribute("m_eLeaderAlignmentType", "Simple on box point"); break; + case KA3DLeaderAlignment_Maximal_Underline: setting->SetAttribute("m_eLeaderAlignmentType", "Underline maximum"); break; + case KA3DLeaderAlignment_Simple_OppositeAnchor: setting->SetAttribute("m_eLeaderAlignmentType", "Simple, opposite anchor point"); break; + default: setting->SetAttribute("m_eLeaderAlignmentType", "unexpected"); break; + } +} + +//###################################################################################################################### +static void sttraverseTextPosition(const A3DMDTextPosition* pTextPosition, _TiXmlElement* setting) +{ + if(pTextPosition == NULL) + { + setting->SetAttribute("text_position", "not defined"); + return; + } + + A3DMDTextPositionData sTextPositionData; + A3D_INITIALIZE_DATA(A3DMDTextPositionData, sTextPositionData); + if(A3DMDTextPositionGet(pTextPosition, &sTextPositionData) != A3D_SUCCESS) + { + setting->SetAttribute("error", "text_properties"); + return; + } + + _TiXmlElement* markup_textposition = new _TiXmlElement("A3DMDTextPositionData"); + setting->LinkEndChild(markup_textposition); + traversePoint("m_sPosition" , sTextPositionData.m_sPosition , markup_textposition); + traversePoint("m_sBaseVector", sTextPositionData.m_sBaseVector, markup_textposition); + traversePoint("m_sUpVector" , sTextPositionData.m_sUpVector , markup_textposition); + A3DMDTextPositionGet(NULL, &sTextPositionData); +} + +//###################################################################################################################### + +int traverseMarkupTextProperties(const A3DMDTextProperties* pTextProperties, _TiXmlElement* setting) +{ + if(pTextProperties == NULL) + { + setting->SetAttribute("text_properties", "not defined"); + return A3D_SUCCESS; + } + + A3DStatus iRet = A3D_SUCCESS; + A3DMDTextPropertiesData sTextPropertiesData; + A3D_INITIALIZE_DATA(A3DMDTextPropertiesData, sTextPropertiesData); + iRet = A3DMDTextPropertiesGet(pTextProperties, &sTextPropertiesData); + if(iRet != A3D_SUCCESS) + { + setting->SetAttribute("error", "text_properties"); + return A3D_SUCCESS; + } + + _TiXmlElement* markup_textprops = new _TiXmlElement("A3DMDTextPropertiesData"); + setting->LinkEndChild(markup_textprops); + markup_textprops->SetAttribute("m_pcFont", sTextPropertiesData.m_pcFont ? sTextPropertiesData.m_pcFont : "null"); + markup_textprops->SetDoubleAttribute("m_dAngle", sTextPropertiesData.m_dAngle); + markup_textprops->SetAttribute("m_bSlant", sTextPropertiesData.m_bSlant ? "true" : "false"); + markup_textprops->SetAttribute("m_ucThickness", sTextPropertiesData.m_ucThickness); + markup_textprops->SetAttribute("m_ucSize", sTextPropertiesData.m_ucSize); + markup_textprops->SetAttribute("m_usLineStyle", sTextPropertiesData.m_usLineStyle); + markup_textprops->SetDoubleAttribute("m_dCharHeight", sTextPropertiesData.m_dCharHeight); + markup_textprops->SetDoubleAttribute("m_dCharSpacing", sTextPropertiesData.m_dCharSpacing); + markup_textprops->SetDoubleAttribute("m_dCharWidth", sTextPropertiesData.m_dCharWidth); + markup_textprops->SetAttribute("m_iCharFixedRatioMode", sTextPropertiesData.m_iCharFixedRatioMode); + + switch(sTextPropertiesData.m_eGlobalTextScoring) + { + case KEA3DMDTextPropertiesScoreNone: + markup_textprops->SetAttribute("m_eGlobalTextScoring", "KEA3DMDTextPropertiesScoreNone"); + break; + case KEA3DMDTextPropertiesUnderScored: + markup_textprops->SetAttribute("m_eGlobalTextScoring", "KEA3DMDTextPropertiesUnderScored"); + break; + case KEA3DMDTextPropertiesScored: + markup_textprops->SetAttribute("m_eGlobalTextScoring", "KEA3DMDTextPropertiesScored"); + break; + case KEA3DMDTextPropertiesOverScored: + markup_textprops->SetAttribute("m_eGlobalTextScoring", "KEA3DMDTextPropertiesOverScored"); + break; + default: + markup_textprops->SetAttribute("m_eGlobalTextScoring", "unexpected"); + } + + switch(sTextPropertiesData.m_eFormat) + { + case KEA3DMDTextPropertiesFormatNormal: + markup_textprops->SetAttribute("m_eFormat", "KEA3DMDTextPropertiesFormatNormal"); + break; + case KEA3DMDTextPropertiesFormatUnderLine: + markup_textprops->SetAttribute("m_eFormat", "KEA3DMDTextPropertiesFormatUnderLine"); + break; + case KEA3DMDTextPropertiesFormatOverLine: + markup_textprops->SetAttribute("m_eFormat", "KEA3DMDTextPropertiesFormatOverLine"); + break; + case KEA3DMDTextPropertiesFormatExposant: + markup_textprops->SetAttribute("m_eFormat", "KEA3DMDTextPropertiesFormatExposant"); + break; + case KEA3DMDTextPropertiesFormatindice: + markup_textprops->SetAttribute("m_eFormat", "KEA3DMDTextPropertiesFormatindice"); + break; + default: + markup_textprops->SetAttribute("m_eFormat", "unexpected"); + } + + switch(sTextPropertiesData.m_eJustification) + { + case KEA3DMDTextPropertiesJustificationLeft: + markup_textprops->SetAttribute("m_eJustification", "KEA3DMDTextPropertiesJustificationLeft"); + break; + case KEA3DMDTextPropertiesJustificationCenter: + markup_textprops->SetAttribute("m_eJustification", "KEA3DMDTextPropertiesJustificationCenter"); + break; + case KEA3DMDTextPropertiesJustificationRight: + markup_textprops->SetAttribute("m_eJustification", "KEA3DMDTextPropertiesJustificationRight"); + break; + default: + markup_textprops->SetAttribute("m_eJustification", "unexpected"); + } + + return A3DMDTextPropertiesGet(NULL, &sTextPropertiesData); +} + +//###################################################################################################################### + +int traverseMarkupText(const A3DMarkupText* pMarkup, _TiXmlElement* setting) +{ + A3DMarkupTextData sMarkupData; + A3D_INITIALIZE_DATA(A3DMarkupTextData, sMarkupData); + _TiXmlElement* markup_text = new _TiXmlElement("A3DMarkupTextData"); + setting->LinkEndChild(markup_text); + A3DStatus iRet = A3DMarkupTextGet(pMarkup, &sMarkupData); + if(iRet != A3D_SUCCESS) + { + markup_text->SetAttribute("error", iRet); + return iRet; + } + + char acName[20]; + for(A3DUns32 i = 0; i < sMarkupData.m_uiLinesSize; i++) + { + sprintf(acName, "line_%u", i); + markup_text->SetAttribute(acName, sMarkupData.m_ppLines[i]); + } + for(A3DUns32 i = 0; i < sMarkupData.m_uiFileLinksSize; i++) + { + sprintf(acName, "file_link_%u", i); + markup_text->SetAttribute(acName, sMarkupData.m_ppFileLinks[i]); + } + sttraverseFrameType(sMarkupData.m_eFrameType, markup_text); + sttraverseAlignmentType(sMarkupData.m_eLeaderAlignmentType, markup_text); + sttraverseTextPosition(sMarkupData.m_psTextPosition, markup_text); + markup_text->SetDoubleAttribute("Wrapping_width", sMarkupData.m_dWrappingWidth); + traverseMarkupTextProperties(sMarkupData.m_psTextPosition, markup_text); + + return A3DMarkupTextGet(NULL, &sMarkupData); +} + +//###################################################################################################################### +int traverseMarkupRichText(const A3DMarkupRichText* pMarkup, _TiXmlElement* setting) +{ + A3DMarkupRichTextData sMarkupData; + A3D_INITIALIZE_DATA(A3DMarkupRichTextData, sMarkupData); + _TiXmlElement* markup_text = new _TiXmlElement("A3DMarkupRichTextData"); + setting->LinkEndChild(markup_text); + A3DStatus iRet = A3DMarkupRichTextGet(pMarkup, &sMarkupData); + if(iRet != A3D_SUCCESS) + { + markup_text->SetAttribute("error", iRet); + return iRet; + } + + markup_text->SetAttribute("m_pcRichText", sMarkupData.m_pcRichText?sMarkupData.m_pcRichText:"NULL"); + // Let's try to parse the string + char acAttributValue[1024]; + A3DMkpRTFField* pRTF = NULL; + if (A3DMkpRTFFieldCreate(sMarkupData.m_pcRichText, &pRTF) == A3D_SUCCESS) + { + A3DMkpRTFFieldData sRTFFieldData; + A3D_INITIALIZE_DATA(A3DRTFFieldData, sRTFFieldData); + + while (A3DMkpRTFFieldGet(pRTF, &sRTFFieldData) == A3D_SUCCESS) + { + if (sRTFFieldData.m_pcFamilyName) + snprintf(acAttributValue,sizeof(acAttributValue), "font-family:%s;", sRTFFieldData.m_pcFamilyName); + + A3DMkpRTFFieldGet(NULL, &sRTFFieldData); + } + A3DMkpRTFFieldDelete(pRTF); + } + + char acName[20]; + for(A3DUns32 i = 0; i < sMarkupData.m_uiFileLinksSize; i++) + { + sprintf(acName, "file_link_%u", i); + markup_text->SetAttribute(acName, sMarkupData.m_ppFileLinks[i]); + } + sttraverseFrameType(sMarkupData.m_eFrameType, markup_text); + sttraverseAlignmentType(sMarkupData.m_eLeaderAlignmentType, markup_text); + sttraverseTextPosition(sMarkupData.m_psTextPosition, markup_text); + markup_text->SetDoubleAttribute("Wrapping_width", sMarkupData.m_dWrappingWidth); + + return A3DMarkupRichTextGet(NULL, &sMarkupData); +} diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLRepItems.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLRepItems.cpp new file mode 100644 index 0000000..e30bf42 --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLRepItems.cpp @@ -0,0 +1,478 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "PRC2XML.h" + +#include + +//###################################################################################################################### +int traverseCSys(const A3DRiCoordinateSystem* pCSys, _TiXmlElement* setting) +{ + A3DRiCoordinateSystemData sData; + A3D_INITIALIZE_DATA(A3DRiCoordinateSystemData, sData); + + _TiXmlElement* csys = new _TiXmlElement("A3DRiCoordinateSystemData"); + traverseSource(pCSys, csys); + + A3DInt32 iRet = A3DRiCoordinateSystemGet(pCSys, &sData); + if(iRet == A3D_SUCCESS) + { + iRet = traverseTransformation(sData.m_pTransformation, csys); + A3DRiCoordinateSystemGet(NULL, &sData); + } + else + { + csys->SetAttribute("error", iRet); + } + + setting->LinkEndChild(csys); + return iRet; +} + +//###################################################################################################################### +int traverseRepItemContent(const A3DRiRepresentationItem* pRi, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + A3DRiRepresentationItemData sData; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, sData); + + iRet = A3DRiRepresentationItemGet(pRi, &sData); + if(iRet == A3D_SUCCESS) + { + std::unique_ptr<_TiXmlElement> repitemdata(new _TiXmlElement("A3DRiRepresentationItemData")); + + if(sData.m_pCoordinateSystem) + traverseCSys(sData.m_pCoordinateSystem, repitemdata.get()); + + if(sData.m_pTessBase) + traverseTessBase(sData.m_pTessBase, repitemdata.get()); + + if(sData.m_pCoordinateSystem || sData.m_pTessBase) + setting->LinkEndChild(repitemdata.release()); + + A3DRiRepresentationItemGet(NULL, &sData); + } + + return A3D_SUCCESS; +} + +//###################################################################################################################### +static int traverseBrepModel(const A3DRiBrepModel* pBrepModel, _TiXmlElement* setting) +{ + A3DRiBrepModelData sData; + A3D_INITIALIZE_DATA(A3DRiBrepModelData, sData); + + _TiXmlElement* brep = new _TiXmlElement("A3DRiBrepModelData"); + traverseSource(pBrepModel, brep); + traverseRepItemContent(pBrepModel, brep); + traverseMaterialProperties(pBrepModel, brep); + + _TiXmlElement* physicalprops = new _TiXmlElement("A3DPhysicalPropertiesData"); + + A3DVector3dData psScale; + A3D_INITIALIZE_DATA(A3DVector3dData, psScale); + psScale.m_dX = 1; + psScale.m_dY = 1; + psScale.m_dZ = 1; + A3DPhysicalPropertiesData physicalPropertiesData; + A3D_INITIALIZE_A3DPhysicalPropertiesData(physicalPropertiesData); + A3DInt32 iRet = A3DComputePhysicalProperties(pBrepModel, &psScale, &physicalPropertiesData); + + if (iRet == A3D_SUCCESS) + { + physicalprops->SetAttribute("m_bVolumecomputed", physicalPropertiesData.m_bVolumeComputed); + physicalprops->SetDoubleAttribute("m_dSurface", (double)physicalPropertiesData.m_dSurface); + physicalprops->SetDoubleAttribute("m_dVolume", (double)physicalPropertiesData.m_dVolume); + + physicalprops->SetDoubleAttribute("m_sGravityCenter.m_dX", (double)physicalPropertiesData.m_sGravityCenter.m_dX); + physicalprops->SetDoubleAttribute("m_sGravityCenter.m_dY", (double)physicalPropertiesData.m_sGravityCenter.m_dY); + physicalprops->SetDoubleAttribute("m_sGravityCenter.m_dZ", (double)physicalPropertiesData.m_sGravityCenter.m_dZ); + } + else + { + physicalprops->SetAttribute("error", iRet); + } + + setting->LinkEndChild(physicalprops); + iRet = A3DRiBrepModelGet(pBrepModel, &sData); + if(iRet == A3D_SUCCESS) + { + traverseBrepData(sData.m_pBrepData, brep); + A3DRiBrepModelGet(NULL, &sData); + } + + setting->LinkEndChild(brep); + return iRet; +} + +//###################################################################################################################### +static int traversePolyBrepModel(const A3DRiPolyBrepModel* pPolyBrepModel, _TiXmlElement* setting) +{ + A3DRiPolyBrepModelData sData; + A3D_INITIALIZE_DATA(A3DRiPolyBrepModelData, sData); + + _TiXmlElement* polybrep = new _TiXmlElement("A3DRiPolyBrepModelData"); + traverseSource(pPolyBrepModel, polybrep); + traverseRepItemContent(pPolyBrepModel, polybrep); + traverseMaterialProperties(pPolyBrepModel, polybrep); + + A3DPhysicalPropertiesData physicalPropertiesData; + A3D_INITIALIZE_DATA(A3DPhysicalPropertiesData, physicalPropertiesData); + A3DVector3dData psScale; + A3D_INITIALIZE_DATA(A3DVector3dData, psScale); + psScale.m_dX = 1; + psScale.m_dY = 1; + psScale.m_dZ = 1; + A3DInt32 iRet = A3DComputePolyBrepPhysicalProperties(pPolyBrepModel, &psScale, &physicalPropertiesData); + + _TiXmlElement* physicalprops = new _TiXmlElement("A3DPhysicalPropertiesData"); + physicalprops->SetAttribute("m_bVolumecomputed", physicalPropertiesData.m_bVolumeComputed); + physicalprops->SetDoubleAttribute("m_dSurface", (double)physicalPropertiesData.m_dSurface); + physicalprops->SetDoubleAttribute("m_dVolume", (double)physicalPropertiesData.m_dVolume); + + physicalprops->SetDoubleAttribute("m_sGravityCenter.m_dX",(double) physicalPropertiesData.m_sGravityCenter.m_dX); + physicalprops->SetDoubleAttribute("m_sGravityCenter.m_dY", (double)physicalPropertiesData.m_sGravityCenter.m_dY); + physicalprops->SetDoubleAttribute("m_sGravityCenter.m_dZ",(double) physicalPropertiesData.m_sGravityCenter.m_dZ); + + setting->LinkEndChild(physicalprops); + + iRet = A3DRiPolyBrepModelGet(pPolyBrepModel, &sData); + if(iRet == A3D_SUCCESS) + { + polybrep->SetAttribute("m_bIsClosed", (int) sData.m_bIsClosed); + A3DRiPolyBrepModelGet(NULL, &sData); + } + + setting->LinkEndChild(polybrep); + return iRet; +} + +//###################################################################################################################### +static int traverseRICurve(const A3DRiCurve* pRICrv, _TiXmlElement* setting) +{ + A3DRiCurveData sData; + A3D_INITIALIZE_DATA(A3DRiCurveData, sData); + + _TiXmlElement* ricrv = new _TiXmlElement("A3DRiCurveData"); + traverseSource(pRICrv, ricrv); + traverseRepItemContent(pRICrv, ricrv); + traverseMaterialProperties(pRICrv, ricrv); + + A3DInt32 iRet = A3DRiCurveGet(pRICrv, &sData); + if(iRet == A3D_SUCCESS) + { + traverseSingleWireBody(sData.m_pBody, ricrv); + A3DRiCurveGet(NULL, &sData); + } + + setting->LinkEndChild(ricrv); + return iRet; +} + +//###################################################################################################################### +static int traverseRIPlane(const A3DRiPlane* pRIPlane, _TiXmlElement* setting) +{ + A3DRiPlaneData sData; + A3D_INITIALIZE_DATA(A3DRiPlaneData, sData); + + _TiXmlElement* riplane = new _TiXmlElement("A3DRiPlaneData"); + traverseSource(pRIPlane, riplane); + traverseRepItemContent(pRIPlane, riplane); + traverseMaterialProperties(pRIPlane, riplane); + + A3DInt32 iRet = A3DRiPlaneGet(pRIPlane, &sData); + if(iRet == A3D_SUCCESS) + { + traverseBrepData(sData.m_pBrepData, riplane); + A3DRiPlaneGet(NULL, &sData); + } + + setting->LinkEndChild(riplane); + return iRet; +} + +//###################################################################################################################### +static int traverseDirection(const A3DRiDirection* pDirection, _TiXmlElement* setting) +{ + A3DRiDirectionData sData; + A3D_INITIALIZE_DATA(A3DRiDirectionData, sData); + + _TiXmlElement* dir = new _TiXmlElement("A3DRiDirectionData"); + traverseSource(pDirection, dir); + traverseRepItemContent(pDirection, dir); + + A3DInt32 iRet = A3DRiDirectionGet(pDirection, &sData); + if(iRet == A3D_SUCCESS) + { + traversePoint("m_sOrigin" , sData.m_sOrigin , dir); + traversePoint("m_sDirection", sData.m_sDirection, dir); + A3DRiDirectionGet(NULL, &sData); + } + else + { + dir->SetAttribute("error", iRet); + } + + setting->LinkEndChild(dir); + return iRet; +} + +//###################################################################################################################### +static int traversePointSet(const A3DRiPointSet* pPointSet, _TiXmlElement* setting) +{ + A3DRiPointSetData sData; + A3D_INITIALIZE_DATA(A3DRiPointSetData, sData); + + _TiXmlElement* pointset = new _TiXmlElement("A3DRiPointSetData"); + traverseSource(pPointSet, pointset); + traverseRepItemContent(pPointSet, pointset); + traverseMaterialProperties(pPointSet, pointset); + + A3DInt32 iRet = A3DRiPointSetGet(pPointSet, &sData); + if(iRet == A3D_SUCCESS) + { + for(A3DUns32 ui = 0; ui < sData.m_uiSize; ++ui) + traversePoint("m_pPts", sData.m_pPts[ui], pointset); + A3DRiPointSetGet(NULL, &sData); + } + else + { + pointset->SetAttribute("error", iRet); + } + + setting->LinkEndChild(pointset); + return iRet; +} + +//###################################################################################################################### +static int traverseSet(const A3DRiSet* pSet, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + A3DRiSetData sData; + A3D_INITIALIZE_DATA(A3DRiSetData, sData); + + _TiXmlElement* set = new _TiXmlElement("A3DRiSetData"); + traverseSource(pSet, set); + traverseRepItemContent(pSet, set); + traverseMaterialProperties(pSet, set); + + iRet = A3DRiSetGet(pSet, &sData); + if(iRet == A3D_SUCCESS) + { + for(A3DUns32 ui = 0; ui < sData.m_uiRepItemsSize; ++ui) + iRet = traverseRepItem(sData.m_ppRepItems[ui], set); + + A3DRiSetGet(NULL, &sData); + } + else + { + set->SetAttribute("error", iRet); + } + + setting->LinkEndChild(set); + return iRet; +} + +//###################################################################################################################### +int traverseDrawingBlock(const A3DDrawingBlock *pDrwBlock, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + + A3DDrawingBlockBasicData sDrwBlockData; + A3D_INITIALIZE_DATA(A3DDrawingBlockBasicData, sDrwBlockData); + + CHECK_RET( A3DDrawingBlockBasicGet( (A3DDrawingBlockBasic const*) pDrwBlock, &sDrwBlockData)); + + _TiXmlElement* drwBlock = new _TiXmlElement("A3DDrawingBlockData"); + traverseSource(pDrwBlock, drwBlock); + + drwBlock->SetAttribute("Nb_Entities", sDrwBlockData.m_uiDrwEntitiesSize); + drwBlock->SetAttribute("Nb_Markups", sDrwBlockData.m_uiMarkupsSize); + drwBlock->SetAttribute("Nb_SubBlocks", sDrwBlockData.m_uiDrwBlocksSize); + + for (A3DUns32 ui = 0; ui < sDrwBlockData.m_uiMarkupsSize; ++ui) + { + traverseMarkup(sDrwBlockData.m_ppMarkups[ui], drwBlock); + } + + setting->LinkEndChild(drwBlock); + + return iRet; +} + +//###################################################################################################################### +int traverseDrawingView(const A3DDrawingView *pDrwView, _TiXmlElement* setting) +{ + + A3DDrawingViewData sDrwViewData; + A3D_INITIALIZE_DATA(A3DDrawingViewData, sDrwViewData); + + + _TiXmlElement* drwView = new _TiXmlElement("A3DDrawingViewData"); + + // Get the type of the drawing view + A3DInt32 iRet = A3D_SUCCESS; + + iRet = A3DDrawingViewGet(pDrwView, &sDrwViewData); + + A3DEDrawingViewType eDrwType = sDrwViewData.m_eType; + + switch(eDrwType) + { + case kA3DDrawingViewTypeIso: + drwView->SetAttribute("ISO_view",1); + case kA3DDrawingViewTypeTop: + drwView->SetAttribute("Top_view",1); + case kA3DDrawingViewTypeBottom: + drwView->SetAttribute("Bottom_view",1); + case kA3DDrawingViewTypeLeft: + drwView->SetAttribute("Left_view",1); + case kA3DDrawingViewTypeRight: + drwView->SetAttribute("Right_view",1); + case kA3DDrawingViewTypeFront: + drwView->SetAttribute("Front_view",1); + case kA3DDrawingViewTypeBack: + drwView->SetAttribute("Back_view",1); + case kA3DDrawingViewTypeBackground: + drwView->SetAttribute("Background_view",1); + case kA3DDrawingViewTypeWorking: + drwView->SetAttribute("Working_view",1); + case kA3DDrawingViewTypeProjected: + drwView->SetAttribute("Projected_view",1); + case kA3DDrawingViewTypeAuxiliary: + drwView->SetAttribute("Auxiliary_view",1); + case kA3DDrawingViewTypeSection: + drwView->SetAttribute("Section_view",1); + case kA3DDrawingViewTypeDetail : + drwView->SetAttribute("Detail_view",1); + default: + drwView->SetAttribute("Unknown",1); + break; + } + + // get the name of the drawing view + A3DRootBaseData sData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sData); + CHECK_RET(A3DRootBaseGet(pDrwView, &sData)); + + if(sData.m_pcName && sData.m_pcName[0] != '\0') + drwView->SetAttribute("name", sData.m_pcName); + A3DRootBaseGet(NULL,&sData); + + if (sDrwViewData.m_pLocalBlocks) + { + traverseDrawingBlock(sDrwViewData.m_pLocalBlocks, drwView); + } + + for (A3DUns32 ui = 0; ui < sDrwViewData.m_uiDrwBlocksSize; ++ui) + { + traverseDrawingBlock(sDrwViewData.m_ppDrwBlocks[ui], drwView); + } + + setting->LinkEndChild(drwView); + + return iRet; +} + +//###################################################################################################################### +int traverseDrawingSheet(const A3DDrawingSheet * pDrwSheet, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + + A3DDrawingSheetData sDrwSheetData; + A3D_INITIALIZE_DATA(A3DDrawingSheetData, sDrwSheetData); + + iRet = A3DDrawingSheetGet(pDrwSheet, &sDrwSheetData); + + + _TiXmlElement* pSheet = new _TiXmlElement("A3DDrawingSheetdata"); + + for (A3DUns32 ui = 0; ui < sDrwSheetData.m_uiDrwViewsSize; ++ui) + { + traverseDrawingView(sDrwSheetData.m_ppDrwViews[ui], pSheet); + } + + setting->LinkEndChild(pSheet); + + return iRet; + +} + +//###################################################################################################################### +int traverseDrawing(const A3DDrawingModel * pDrawing, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + + A3DDrawingModelData sDrwModelData; + A3D_INITIALIZE_DATA(A3DDrawingModelData, sDrwModelData); + + A3DRootBaseData sBaseData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sBaseData); + + A3DRootBaseGet(pDrawing, &sBaseData); + + iRet = A3DDrawingModelGet(pDrawing, &sDrwModelData); + + _TiXmlElement* drawing = new _TiXmlElement("A3DDrawingModeldata"); + + // traverse the drawing sheet + for (A3DUns32 ui = 0; ui < sDrwModelData.m_uiDrwSheetsSize; ++ui) + { + traverseDrawingSheet(sDrwModelData.m_ppDrwSheets[ui], drawing); + } + + setting->LinkEndChild(drawing); + + return iRet; +} + + +//###################################################################################################################### +int traverseRepItem(const A3DRiRepresentationItem* pRepItem, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + A3DEEntityType eType; + + CHECK_RET(A3DEntityGetType(pRepItem, &eType)); + + switch(eType) + { + case kA3DTypeRiSet: + iRet = traverseSet(pRepItem, setting); + break; + case kA3DTypeRiPointSet: + iRet = traversePointSet(pRepItem, setting); + break; + case kA3DTypeRiDirection: + iRet = traverseDirection(pRepItem, setting); + break; + case kA3DTypeRiCurve: + iRet = traverseRICurve(pRepItem, setting); + break; + case kA3DTypeRiCoordinateSystem: + iRet = traverseCSys(pRepItem, setting); + break; + case kA3DTypeRiPlane: + iRet = traverseRIPlane(pRepItem, setting); + break; + case kA3DTypeRiBrepModel: + iRet = traverseBrepModel(pRepItem, setting); + break; + case kA3DTypeRiPolyBrepModel: + iRet = traversePolyBrepModel(pRepItem, setting); + break; + default: + iRet = A3D_NOT_IMPLEMENTED; + break; + } + return iRet; +} diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLRootEntities.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLRootEntities.cpp new file mode 100644 index 0000000..c886b8e --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLRootEntities.cpp @@ -0,0 +1,197 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "PRC2XML.h" + + + +//###################################################################################################################### +int traverseAttribute(const A3DMiscAttribute* pAttribute, _TiXmlElement* setting) +{ + A3DMiscAttributeData sData; + A3D_INITIALIZE_DATA(A3DMiscAttributeData, sData); + + A3DInt32 iRet = A3DMiscAttributeGet(pAttribute, &sData); + if(iRet == A3D_SUCCESS) + { + _TiXmlElement* attribute = new _TiXmlElement("A3DMiscAttributeData"); + attribute->SetAttribute("m_bTitleIsInt", (int) sData.m_bTitleIsInt); + if(sData.m_bTitleIsInt) + { + A3DUns32 uiVal; + memcpy(&uiVal,sData.m_pcTitle, sizeof(A3DUns32)); + attribute->SetAttribute("m_pcTitle", (int)uiVal); + } + else + { + if(sData.m_pcTitle && sData.m_pcTitle[0] != '\0') + attribute->SetAttribute("m_pcTitle", sData.m_pcTitle); + } + + for(A3DUns32 ui = 0; ui < sData.m_uiSize; ++ui) + { + _TiXmlElement* single = new _TiXmlElement("m_asSingleAttributesData"); + + single->SetAttribute("m_bTitleIsInt", (int) sData.m_asSingleAttributesData[ui].m_bTitleIsInt); + if(sData.m_asSingleAttributesData[ui].m_pcTitle == NULL) + single->SetAttribute("m_pcTitle", "NULL"); + else if(sData.m_asSingleAttributesData[ui].m_bTitleIsInt) + { + A3DUns32 uiVal; + memcpy(&uiVal,sData.m_asSingleAttributesData[ui].m_pcTitle, sizeof(A3DUns32)); + single->SetAttribute("m_pcTitle", (int)uiVal); + } + else + { + if(sData.m_asSingleAttributesData[ui].m_pcTitle && sData.m_asSingleAttributesData[ui].m_pcTitle[0] != '\0') + single->SetAttribute("m_pcTitle", sData.m_asSingleAttributesData[ui].m_pcTitle); + } + + A3DInt32 iVal; + + switch(sData.m_asSingleAttributesData[ui].m_eType) + { + case kA3DModellerAttributeTypeInt: + memcpy(&iVal, sData.m_asSingleAttributesData[ui].m_pcData, sizeof(A3DInt32)); + single->SetAttribute("m_eType", "kA3DModellerAttributeTypeInt"); + single->SetAttribute("m_pcData", iVal); + break; + + case kA3DModellerAttributeTypeReal: + A3DDouble dVal; + memcpy(&dVal, sData.m_asSingleAttributesData[ui].m_pcData, sizeof(A3DDouble)); + single->SetAttribute("m_eType", "kA3DModellerAttributeTypeReal"); + _SetDoubleAttribute(single, "m_pcData", dVal); + if (sData.m_asSingleAttributesData[ui].m_usUnit!= A3D_DEFAULT_NO_UNIT) + single->SetAttribute("m_usUnit", sData.m_asSingleAttributesData[ui].m_usUnit); + break; + + case kA3DModellerAttributeTypeTime: + memcpy(&iVal, sData.m_asSingleAttributesData[ui].m_pcData, sizeof(A3DInt32)); + single->SetAttribute("m_eType", "kA3DModellerAttributeTypeTime"); + single->SetAttribute("m_pcData", iVal); + break; + + case kA3DModellerAttributeTypeString: + single->SetAttribute("m_eType", "kA3DModellerAttributeTypeString"); + if(sData.m_asSingleAttributesData[ui].m_pcData && sData.m_asSingleAttributesData[ui].m_pcData[0] != '\0') + single->SetAttribute("m_pcData", sData.m_asSingleAttributesData[ui].m_pcData); + break; + + default: + break; + } + attribute->LinkEndChild(single); + } + setting->LinkEndChild(attribute); + A3DMiscAttributeGet(NULL, &sData); + } + + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traverseGraphics(const A3DGraphics* pGraphics, _TiXmlElement* setting) +{ + A3DGraphicsData sData; + A3D_INITIALIZE_DATA(A3DGraphicsData, sData); + + A3DInt32 iRet = A3DGraphicsGet(pGraphics, &sData); + if(iRet == A3D_SUCCESS) + { + _TiXmlElement* graphics = new _TiXmlElement("A3DGraphicsData"); + + if(sData.m_uiLayerIndex != A3D_DEFAULT_LAYER) + graphics->SetAttribute("m_uiLayerIndex", (int) sData.m_uiLayerIndex); + if(sData.m_uiStyleIndex != A3D_DEFAULT_STYLE_INDEX) + graphics->SetAttribute("m_uiStyleIndex", (int) sData.m_uiStyleIndex); + + graphics->SetAttribute("m_usBehaviour", (int) sData.m_usBehaviour); + + CHECK_RET(A3DGraphicsGet(NULL, &sData)); + setting->LinkEndChild(graphics); + } + + return iRet; +} + +//###################################################################################################################### +int traverseBase(const A3DEntity* pEntity, _TiXmlElement* setting) +{ + A3DRootBaseData sData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sData); + A3DInt32 iRet = A3DRootBaseGet(pEntity, &sData); + if(iRet == A3D_SUCCESS) + { + _TiXmlElement* base = new _TiXmlElement("A3DRootBaseData"); + if(sData.m_pcName && sData.m_pcName[0] != '\0') + base->SetAttribute("m_pcName", sData.m_pcName); + + base->SetAttribute("m_uiPersistentId", sData.m_uiPersistentId); + base->SetAttribute("m_uiNonPersistentId", sData.m_uiNonPersistentId); + if (sData.m_pcPersistentId) + base->SetAttribute("m_pcPersistentId", sData.m_pcPersistentId); + + for(A3DUns32 ui = 0; ui < sData.m_uiSize; ++ui) + traverseAttribute(sData.m_ppAttributes[ui], base); + + A3DBoundingBoxData sBoundingBox; + A3D_INITIALIZE_DATA(A3DBoundingBoxData, sBoundingBox); + iRet = A3DMiscGetBoundingBox(pEntity, &sBoundingBox); + if(iRet == A3D_SUCCESS) + { + if((sBoundingBox.m_sMin.m_dX + sBoundingBox.m_sMin.m_dY + sBoundingBox.m_sMin.m_dZ + sBoundingBox.m_sMax.m_dX + sBoundingBox.m_sMax.m_dY + sBoundingBox.m_sMax.m_dZ) != 0.0) + { + char acBBox[256]; + sprintf(acBBox, "Min(%f,%f,%f) Max(%f,%f,%f)", sBoundingBox.m_sMin.m_dX, sBoundingBox.m_sMin.m_dY, sBoundingBox.m_sMin.m_dZ, sBoundingBox.m_sMax.m_dX, sBoundingBox.m_sMax.m_dY, sBoundingBox.m_sMax.m_dZ); + base->SetAttribute("BoundingBox", acBBox); + A3DMiscGetBoundingBox(NULL, &sBoundingBox); + } + } + + setting->LinkEndChild(base); + A3DRootBaseGet(NULL, &sData); + } + + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traverseBaseWithGraphics(const A3DEntity* pEntity, _TiXmlElement* setting) +{ + A3DRootBaseWithGraphicsData sData; + A3D_INITIALIZE_DATA(A3DRootBaseWithGraphicsData, sData); + + A3DInt32 iRet = A3DRootBaseWithGraphicsGet(pEntity, &sData); + if(iRet == A3D_SUCCESS) + { + _TiXmlElement* basewithgraphics = new _TiXmlElement("A3DRootBaseWithGraphicsData"); + traverseBase(pEntity,basewithgraphics); + if(sData.m_pGraphics != NULL) + traverseGraphics(sData.m_pGraphics,basewithgraphics); + setting->LinkEndChild(basewithgraphics); + A3DRootBaseWithGraphicsGet(NULL, &sData); + } + + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traverseSource(const A3DEntity* pEntity, _TiXmlElement* setting) +{ + if(A3DEntityIsBaseWithGraphicsType(pEntity)) + return traverseBaseWithGraphics(pEntity, setting); + else if(A3DEntityIsBaseType(pEntity)) + return traverseBase(pEntity, setting); + + return A3D_SUCCESS; +} diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLStructure.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLStructure.cpp new file mode 100644 index 0000000..5a6fc58 --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLStructure.cpp @@ -0,0 +1,614 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "PRC2XML.h" + +int traverseDisplayFilters(A3DUns32 uiSize, A3DAsmFilter** ppFilters, _TiXmlElement* setting); +int traverseGraphScene(const A3DGraphSceneDisplayParametersData& sData, _TiXmlElement* setting); +//###################################################################################################################### +int traverseMaterialProperties(const A3DEntity* pEntity, _TiXmlElement* xmlfather) +{ + _TiXmlElement* xml = new _TiXmlElement("A3DMiscMaterialPropertiesData"); + A3DMiscMaterialPropertiesData sMaterialPropertiesData; + A3D_INITIALIZE_DATA(A3DMiscMaterialPropertiesData, sMaterialPropertiesData); + + A3DStatus iRet = A3DMiscGetMaterialProperties(pEntity, &sMaterialPropertiesData); + if(iRet == A3D_SUCCESS) + { + xml->SetDoubleAttribute("m_dDensity", sMaterialPropertiesData.m_dDensity); + xml->SetAttribute("m_pcMaterialName", sMaterialPropertiesData.m_pcMaterialName ? sMaterialPropertiesData.m_pcMaterialName:"NULL"); + xml->SetAttribute("m_ePhysicType", sMaterialPropertiesData.m_ePhysicType); + switch (sMaterialPropertiesData.m_ePhysicType) + { + case A3DPhysicType_None: + case A3DPhysicType_Fiber: + case A3DPhysicType_HoneyComb: + case A3DPhysicType_Isotropic: + case A3DPhysicType_Orthotropic2D: + case A3DPhysicType_Orthotropic3D: + case A3DPhysicType_Anisotropic: + + default: + break; + } + A3DMiscGetMaterialProperties(NULL, &sMaterialPropertiesData); + } + + xmlfather->LinkEndChild(xml); + return A3D_SUCCESS; +} + +//###################################################################################################################### +static int stTraversePartDef(const A3DAsmPartDefinition* pPart, _TiXmlElement* xmlfather) +{ + A3DInt32 iRet = A3D_SUCCESS; + A3DAsmPartDefinitionData sData; + A3D_INITIALIZE_DATA(A3DAsmPartDefinitionData, sData); + + _TiXmlElement* part = new _TiXmlElement("A3DAsmPartDefinitionData"); + traverseSource(pPart, part); + + iRet = A3DAsmPartDefinitionGet(pPart, &sData); + if(iRet == A3D_SUCCESS) + { + A3DUns32 ui; + part->SetAttribute("m_bInactivateAnnotations", sData.m_bInactivateAnnotations ? "true" : "false"); + + iRet = traverseBoundingBox(&sData.m_sBoundingBox, part); + + for(ui = 0; ui < sData.m_uiAnnotationsSize; ++ui) + traverseAnnotation(sData.m_ppAnnotations[ui], part); + + for(ui = 0; ui < sData.m_uiViewsSize; ++ui) + traverseView(sData.m_ppViews[ui], part); + + for(ui = 0; ui < sData.m_uiRepItemsSize; ++ui) + traverseRepItem(sData.m_ppRepItems[ui], part); + + // traverse the drawing !!!!!!! + for (ui = 0; ui < sData.m_uiDrawingModelsSize; ++ui) + traverseDrawing(sData.m_ppDrawingModels[ui], part); + + A3DAsmPartDefinitionGet(NULL, &sData); + } + else + { + part->SetAttribute("error", iRet); + } + + traverseMaterialProperties(pPart, part); + xmlfather->LinkEndChild(part); + return A3D_SUCCESS; +} + +//###################################################################################################################### +static int stTraverseFilter(const A3DAsmFilter* pFilter, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + A3DAsmFilterData sData; + A3D_INITIALIZE_DATA(A3DAsmFilterData, sData); + + _TiXmlElement* filter = new _TiXmlElement("A3DAsmFilterData"); + traverseSource(pFilter, filter); + + iRet = A3DAsmFilterGet(pFilter, &sData); + if(iRet == A3D_SUCCESS) + { + filter->SetAttribute("active", (int) sData.m_bIsActive); + A3DAsmFilterGet(NULL, &sData); + } + else + { + filter->SetAttribute("error", iRet); + } + + setting->LinkEndChild(filter); + return iRet; +} + +//###################################################################################################################### +int traverseEntityReference(const A3DMiscEntityReference* pEntityReference, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + A3DMiscEntityReferenceData sData; + A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sData); + + _TiXmlElement* entityreference = new _TiXmlElement("A3DMiscEntityReferenceData"); + traverseSource(pEntityReference, entityreference); + + iRet = A3DMiscEntityReferenceGet(pEntityReference, &sData); + if (iRet != A3D_SUCCESS || sData.m_pEntity == NULL) + { + entityreference->SetAttribute("error", iRet); + setting->LinkEndChild(entityreference); + return iRet; + } + _TiXmlElement* entity = new _TiXmlElement("m_pEntity"); + _SetAttributePtr(entity, "Address", (void*)sData.m_pEntity); + entityreference->LinkEndChild(entity); + + if (sData.m_pCoordinateSystem != NULL) + iRet = traverseCSys(sData.m_pCoordinateSystem, entityreference); + + A3DEEntityType eType = kA3DTypeUnknown; + iRet = A3DEntityGetType(sData.m_pEntity, &eType); + if (iRet != A3D_SUCCESS) + { + entityreference->SetAttribute("error_A3DEntityGetType", iRet); + setting->LinkEndChild(entityreference); + return iRet; + } + + if (eType == kA3DTypeMiscReferenceOnTopology) + { + A3DMiscReferenceOnTopologyData sReferenceOnTopologyData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnTopologyData, sReferenceOnTopologyData); + if(A3DMiscReferenceOnTopologyGet((A3DMiscReferenceOnTopology*) sData.m_pEntity, &sReferenceOnTopologyData) != A3D_SUCCESS) + { + entityreference->SetAttribute("error_A3DMiscReferenceOnTopologyGet", iRet); + setting->LinkEndChild(entityreference); + return iRet; + } + + switch(sReferenceOnTopologyData.m_eTopoItemType) + { + case kA3DTypeTopoEdge: + entityreference->SetAttribute("topotype", "Edge"); + if(sReferenceOnTopologyData.m_uiSize != 3) + { + entityreference->SetAttribute("ref_count", "error"); + break; + } + entityreference->SetAttribute("face_indice", sReferenceOnTopologyData.m_puiAdditionalIndexes[0]); + entityreference->SetAttribute("loop_indice", sReferenceOnTopologyData.m_puiAdditionalIndexes[1]); + entityreference->SetAttribute("edge_indice", sReferenceOnTopologyData.m_puiAdditionalIndexes[2]); + break; + case kA3DTypeTopoCoEdge: + entityreference->SetAttribute("topotype", "CoEdge"); + if(sReferenceOnTopologyData.m_uiSize != 3) + { + entityreference->SetAttribute("ref_count", "error"); + break; + } + entityreference->SetAttribute("face_indice", sReferenceOnTopologyData.m_puiAdditionalIndexes[0]); + entityreference->SetAttribute("loop_indice", sReferenceOnTopologyData.m_puiAdditionalIndexes[1]); + entityreference->SetAttribute("coedge_indice", sReferenceOnTopologyData.m_puiAdditionalIndexes[2]); + break; + case kA3DTypeTopoFace: + entityreference->SetAttribute("topotype", "Face"); + if(sReferenceOnTopologyData.m_uiSize != 1) + { + entityreference->SetAttribute("ref_count", "error"); + break; + } + entityreference->SetAttribute("face_indice", sReferenceOnTopologyData.m_puiAdditionalIndexes[0]); + break; + case kA3DTypeTopoUniqueVertex: + entityreference->SetAttribute("topotype", "Unique Vertex"); + if(sReferenceOnTopologyData.m_uiSize != 4) + { + entityreference->SetAttribute("ref_count", "error"); + break; + } + entityreference->SetAttribute("face_indice", sReferenceOnTopologyData.m_puiAdditionalIndexes[0]); + entityreference->SetAttribute("loop_indice", sReferenceOnTopologyData.m_puiAdditionalIndexes[1]); + entityreference->SetAttribute("edge_indice", sReferenceOnTopologyData.m_puiAdditionalIndexes[2]); + entityreference->SetAttribute("vertex_indice", sReferenceOnTopologyData.m_puiAdditionalIndexes[3]); + break; + case kA3DTypeTopoMultipleVertex: + entityreference->SetAttribute("topotype", "Multiple Vertex"); + if(sReferenceOnTopologyData.m_uiSize%3 != 0) + { + entityreference->SetAttribute("ref_count", "error"); + break; + } + entityreference->SetAttribute("ref_count", "todo"); + entityreference->SetAttribute("face_indice", sReferenceOnTopologyData.m_puiAdditionalIndexes[0]); + entityreference->SetAttribute("loop_indice", sReferenceOnTopologyData.m_puiAdditionalIndexes[1]); + entityreference->SetAttribute("edge_indice", sReferenceOnTopologyData.m_puiAdditionalIndexes[2]); + entityreference->SetAttribute("vertex_indice", sReferenceOnTopologyData.m_puiAdditionalIndexes[3]); + break; + default: + entityreference->SetAttribute("linked_item_topo_reference", "unexpected"); + break; + } + A3DMiscReferenceOnTopologyGet(nullptr, &sReferenceOnTopologyData); + } + else if(eType == kA3DTypeMiscReferenceOnCsysItem) + { + A3DMiscReferenceOnCsysItemData sA3DMiscReferenceOnCSYSITemData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnCsysItemData, sA3DMiscReferenceOnCSYSITemData); + iRet = A3DMiscReferenceOnCsysItemGet(sData.m_pEntity, &sA3DMiscReferenceOnCSYSITemData); + if(iRet!=A3D_SUCCESS || !sA3DMiscReferenceOnCSYSITemData.m_pCoordinateSystem) + { + entityreference->SetAttribute("error_A3DMiscReferenceOnCsysItemGet", iRet); + setting->LinkEndChild(entityreference); + A3DMiscReferenceOnCsysItemGet(nullptr, &sA3DMiscReferenceOnCSYSITemData); + return iRet; + } + A3DRootBaseData sCSYSRootData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sCSYSRootData); + if( A3DRootBaseGet(sA3DMiscReferenceOnCSYSITemData.m_pCoordinateSystem, &sCSYSRootData)== A3D_SUCCESS) + { + entityreference->SetAttribute("cys_name", (sCSYSRootData.m_pcName && sCSYSRootData.m_pcName[0] != '\0')?sCSYSRootData.m_pcName:"NULL"); + entityreference->SetAttribute("index", sA3DMiscReferenceOnCSYSITemData.m_uiIndex); + } + A3DMiscReferenceOnCsysItemGet(nullptr, &sA3DMiscReferenceOnCSYSITemData); + } + else + { + A3DRootBaseData sBaseData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sBaseData); + iRet = A3DRootBaseGet(sData.m_pEntity,&sBaseData); + if(iRet == A3D_SUCCESS) + { + if(sBaseData.m_pcName && sBaseData.m_pcName[0] != '\0') + entityreference->SetAttribute("name", sBaseData.m_pcName); + A3DRootBaseGet(NULL,&sBaseData); + } + + if (eType == kA3DTypeRiPolyBrepModel) + { + A3DMiscReferenceOnTessData sReferenceOnTessData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnTessData, sReferenceOnTessData); + if (A3DMiscReferenceOnTessGet(pEntityReference, &sReferenceOnTessData) == A3D_SUCCESS) + { + switch(sReferenceOnTessData.m_eTopoItemType) + { + case kA3DTypeTessFace: + entityreference->SetAttribute("topotype", "Face"); + if (sReferenceOnTessData.m_uiSize == 0) + entityreference->SetAttribute("ref_count", "error"); + + for (A3DUns32 iFace=0;iFaceSetAttribute("face_indice", sReferenceOnTessData.m_puiAdditionalIndexes[iFace]); + break; + case kA3DTypeTessEdge: + entityreference->SetAttribute("topotype", "Edge"); + if (sReferenceOnTessData.m_uiSize != 3) + entityreference->SetAttribute("ref_count", "error"); + else + { + entityreference->SetAttribute("face_indice", sReferenceOnTessData.m_puiAdditionalIndexes[0]); + entityreference->SetAttribute("loop_indice", sReferenceOnTessData.m_puiAdditionalIndexes[1]); + entityreference->SetAttribute("edge_indice", sReferenceOnTessData.m_puiAdditionalIndexes[2]); + } + break; + case kA3DTypeTessVertex: + entityreference->SetAttribute("topotype", "Vertex"); + if (sReferenceOnTessData.m_uiSize != 4) + entityreference->SetAttribute("ref_count", "error"); + else + { + entityreference->SetAttribute("face_indice" , sReferenceOnTessData.m_puiAdditionalIndexes[0]); + entityreference->SetAttribute("loop_indice" , sReferenceOnTessData.m_puiAdditionalIndexes[1]); + entityreference->SetAttribute("edge_indice" , sReferenceOnTessData.m_puiAdditionalIndexes[2]); + entityreference->SetAttribute("vertex_indice", sReferenceOnTessData.m_puiAdditionalIndexes[3]); + } + break; + default: break; + } + + A3DMiscReferenceOnTessGet(NULL, &sReferenceOnTessData); + } + } + else if(eType == kA3DTypeRiPlane) + { + A3DMiscMarkupLinkedItem* pLinkedItem = NULL; + A3DRiPlaneSupportGet((const A3DRiPlane*) sData.m_pEntity, &pLinkedItem); + if( pLinkedItem) + { + _TiXmlElement* entityreferencesupport = new _TiXmlElement("SUPPORT"); + entityreference->LinkEndChild(entityreferencesupport); + traverseEntityReference(pLinkedItem, entityreferencesupport); + } + } + else if(eType == kA3DTypeRiCurve) + { + A3DMiscMarkupLinkedItem* pLinkedItem = NULL; + A3DRiCurveSupportGet((const A3DRiCurve*) sData.m_pEntity, &pLinkedItem); + if( pLinkedItem) + { + _TiXmlElement* entityreferencesupport = new _TiXmlElement("SUPPORT"); + entityreference->LinkEndChild(entityreferencesupport); + traverseEntityReference(pLinkedItem, entityreferencesupport); + } + } + } + A3DMiscEntityReferenceGet(NULL, &sData); + + setting->LinkEndChild(entityreference); + return iRet; +} + +//###################################################################################################################### +static int traverseMaterialAndVis(const A3DMaterialAndVisualisationInfos& oMatVis, _TiXmlElement* setting) +{ + setting->SetAttribute("m_bIsSuppressed", oMatVis.m_bIsSuppressed); + setting->SetAttribute("m_usLayer", oMatVis.m_usLayer); + setting->SetAttribute("m_usBehaviour", oMatVis.m_usBehaviour); + setting->SetAttribute("m_ucType", oMatVis.m_ucType); + + for (A3DUns32 i = 0; i < oMatVis.m_uiPathInAssemblyTreeSize; i++) + { + A3DUTF8Char* acValue = oMatVis.m_ppPathInAssemblyTree[i]; + char acBuffer[32]; + sprintf(acBuffer, "m_ppPathInAssemblyTree_%d", i); + + setting->SetAttribute(acBuffer, acValue ? acValue : ""); + } + + if (oMatVis.m_pMaterial) + traverseMaterial(*oMatVis.m_pMaterial, setting); + + if (oMatVis.m_pTransform) + traverseCartesianTransformationData(*oMatVis.m_pTransform, setting); + return 0; +} + +//###################################################################################################################### +static int stTraversePOccurrence(const A3DAsmProductOccurrence* pOccurrence, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + A3DAsmProductOccurrenceData sData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sData); + + _TiXmlElement* occurrence = new _TiXmlElement("A3DAsmProductOccurrenceData"); + traverseSource(pOccurrence, occurrence); + + A3DRootBaseData sRootBaseData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sRootBaseData); + iRet = A3DRootBaseGet(pOccurrence, &sRootBaseData); + + if (iRet == A3D_SUCCESS) + { + if (sRootBaseData.m_pcName && sRootBaseData.m_pcName[0] != '\0') + occurrence->SetAttribute("m_pcName", sRootBaseData.m_pcName); + + A3DRootBaseGet(NULL, &sRootBaseData); + } + + iRet = A3DAsmProductOccurrenceGet(pOccurrence, &sData); + if (iRet == A3D_SUCCESS) + { + A3DUns32 ui; + + occurrence->SetAttribute("m_ucBehaviour", (int)(sData.m_ucBehaviour)); + occurrence->SetAttribute("m_eProductLoadStatus", (int)(sData.m_eProductLoadStatus)); + + occurrence->SetAttribute("m_uiProductFlags", (int)(sData.m_uiProductFlags)); + occurrence->SetAttribute("m_bUnitFromCAD", (int)(sData.m_bUnitFromCAD)); + occurrence->SetDoubleAttribute("m_dUnit", (double)(sData.m_dUnit)); + occurrence->SetDoubleAttribute("m_dDensityVolumeUnit", sData.m_dDensityVolumeUnit); + occurrence->SetDoubleAttribute("m_dDensityMassUnit", sData.m_dDensityMassUnit); + occurrence->SetAttribute("m_eModellerType", sData.m_eModellerType); + occurrence->SetAttribute("m_bInactivateAnnotations", sData.m_bInactivateAnnotations ? "true" : "false"); + + traverseTransformation(sData.m_pLocation, occurrence); + + if (sData.m_uiDisplayFilterSize && sData.m_ppDisplayFilters) + { + _TiXmlElement* displayfilters = new _TiXmlElement("DisplayFilters"); + traverseDisplayFilters(sData.m_uiDisplayFilterSize, sData.m_ppDisplayFilters, displayfilters); + occurrence->LinkEndChild(displayfilters); + } + + A3DUns32 uiLayers=0; + A3DAsmLayer* asLayers = 0; + if (A3DAsmProductOccurrenceGetLayerList(pOccurrence,&uiLayers,&asLayers) == A3D_SUCCESS) + { + if (uiLayers) + { + _TiXmlElement * pLayers = new _TiXmlElement("Layers"); + for (A3DUns32 i = 0; i < uiLayers; ++i) + { + _TiXmlElement * Layer = new _TiXmlElement("Layer"); + Layer->SetAttribute("Name", asLayers[i].m_pcLayerName ? asLayers[i].m_pcLayerName : "null"); + Layer->SetAttribute("Layer", asLayers[i].m_usLayer); + pLayers->LinkEndChild(Layer); + } + occurrence->LinkEndChild(pLayers); + } + A3DAsmProductOccurrenceGetLayerList(0, &uiLayers, &asLayers); + } + + if (sData.m_pPrototype) + { + _TiXmlElement* occurrenceproto = new _TiXmlElement("m_pPrototype"); + stTraversePOccurrence(sData.m_pPrototype, occurrenceproto); + occurrence->LinkEndChild(occurrenceproto); + } + //else // this is commented but beware http://docs.techsoft3d.com/exchange/latest/build/group__a3d__productoccurrence.html#ga497615eb89393c2aba37cce2e2323f4d + { + A3DUTF8Char* mPOPath = NULL; + + iRet = A3DAsmProductOccurrenceGetFilePathName(pOccurrence, &mPOPath); + if (iRet == A3D_SUCCESS) + occurrence->SetAttribute("A3DAsmProductOccurrenceGetFilePathName", mPOPath != NULL ? mPOPath : ""); + else + occurrence->SetAttribute("A3DAsmProductOccurrenceGetFilePathName", iRet); + A3DAsmProductOccurrenceGetFilePathName(NULL, &mPOPath); + + mPOPath = NULL; + iRet = A3DAsmProductOccurrenceGetOriginalFilePathName(pOccurrence, &mPOPath); + if (iRet == A3D_SUCCESS) + occurrence->SetAttribute("A3DAsmProductOccurrenceGetOriginalFilePathName", mPOPath != NULL ? mPOPath : ""); + else + occurrence->SetAttribute("A3DAsmProductOccurrenceGetOriginalFilePathName", iRet); + A3DAsmProductOccurrenceGetOriginalFilePathName(NULL, &mPOPath); + } + + if (sData.m_pExternalData) + { + _TiXmlElement* occurrenceexternaldata = new _TiXmlElement("m_pExternalData"); + stTraversePOccurrence(sData.m_pExternalData, occurrenceexternaldata); + occurrence->LinkEndChild(occurrenceexternaldata); + } + + for (ui = 0; ui < sData.m_uiPOccurrencesSize; ++ui) + stTraversePOccurrence(sData.m_ppPOccurrences[ui], occurrence); + + for (ui = 0; ui < sData.m_uiEntityReferenceSize; ++ui) + traverseEntityReference(sData.m_ppEntityReferences[ui], occurrence); + + for (ui = 0; ui < sData.m_uiAnnotationsSize; ++ui) + traverseAnnotation(sData.m_ppAnnotations[ui], occurrence); + + for (ui = 0; ui < sData.m_uiSceneDisplayParameterSize; ++ui) + traverseGraphScene(sData.m_psSceneDisplayParameters[ui], occurrence); + + for (ui = 0; ui < sData.m_uiViewsSize; ++ui) + traverseView(sData.m_ppViews[ui], occurrence); + + if (sData.m_pPart) + stTraversePartDef(sData.m_pPart, occurrence); + + if (sData.m_pEntityFilter) + stTraverseFilter(sData.m_pEntityFilter, occurrence); + + for (ui = 0; ui < sData.m_uiFeatureBasedEntitiesSize; ++ui) + traverseFeatureTree(sData.m_ppFeatureBasedEntities[ui], occurrence); + + for (ui = 0; ui < sData.m_uiContraintsSize; ++ui) + traverseConstraint(sData.m_ppConstraints[ui], occurrence); + + for (ui = 0; ui < sData.m_uiMaterialAndVisualisationSetupSize; ++ui) + { + _TiXmlElement* materialandvis = new _TiXmlElement("m_psMaterialAndVisualisationSetup"); + traverseMaterialAndVis(sData.m_psMaterialAndVisualisationSetup[ui], materialandvis); + occurrence->LinkEndChild(materialandvis); + } + + //----------- Export Specific information per CAD format ----------- + switch (sData.m_eModellerType) + { + case kA3DModellerUnigraphics: + { + A3DAsmProductOccurrenceDataUg sDataUg; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceDataUg, sDataUg); + iRet = A3DAsmProductOccurrenceGetUg(pOccurrence, &sDataUg); + if (iRet == A3D_SUCCESS) + { + _TiXmlElement* occurrencedataug = new _TiXmlElement("A3DAsmProductOccurrenceDataUg"); + + occurrencedataug->SetAttribute("RootFilePath", sDataUg.m_psRootFilePath ? sDataUg.m_psRootFilePath : "NULL"); + occurrencedataug->SetAttribute("FileName", sDataUg.m_psFileName ? sDataUg.m_psFileName : "NULL"); + occurrencedataug->SetAttribute("PartUID", sDataUg.m_psPartUID ? sDataUg.m_psPartUID : "NULL"); + occurrencedataug->SetAttribute("InstanceFileName", sDataUg.m_psInstanceFileName ? sDataUg.m_psInstanceFileName : "NULL"); + occurrencedataug->SetAttribute("InstanceTag", sDataUg.m_uiInstanceTag); + + // Treat RefSets + if (sDataUg.m_uiChildrenByRefsetsSize || sDataUg.m_uiSolidsByRefsetsSize) + { + _TiXmlElement* refsetList = new _TiXmlElement("RefSets"); + + // Children by RefSet + for (A3DUns32 iRefSet = 0; iRefSet < sDataUg.m_uiChildrenByRefsetsSize; ++iRefSet) + { + const A3DElementsByRefsetUg &pRefsetData = sDataUg.m_asChildrenByRefsets[iRefSet]; + + // Init Xml Element if first occurrence + _TiXmlElement* refset = new _TiXmlElement("RefSet"); + refset->SetAttribute("Name", pRefsetData.m_psRefset); + + // Add children + for (A3DUns32 i = 0; i < pRefsetData.m_uiElementsSize; ++i) + { + _TiXmlElement * refsetChild = new _TiXmlElement("Child"); + refsetChild->SetAttribute("id", pRefsetData.m_auiElements[i]); + refset->LinkEndChild(refsetChild); + } + + refsetList->LinkEndChild(refset); + } + + // Solid by RefSet + for (A3DUns32 iRefSet = 0; iRefSet < sDataUg.m_uiSolidsByRefsetsSize; ++iRefSet) + { + const A3DElementsByRefsetUg &pRefsetData = sDataUg.m_asSolidsByRefsets[iRefSet]; + + // Init Xml Element if first occurrence + _TiXmlElement* refset = new _TiXmlElement("RefSet"); + refset->SetAttribute("Name", pRefsetData.m_psRefset); + + // Add Solid + for (A3DUns32 i = 0; i < pRefsetData.m_uiElementsSize; ++i) + { + _TiXmlElement * refsetChild = new _TiXmlElement("Solid"); + refsetChild->SetAttribute("id", pRefsetData.m_auiElements[i]); + refset->LinkEndChild(refsetChild); + } + + refsetList->LinkEndChild(refset); + } + + occurrencedataug->LinkEndChild(refsetList); + } + + occurrence->LinkEndChild(occurrencedataug); + + CHECK_RET(A3DAsmProductOccurrenceGetUg(NULL, &sDataUg)); + } + break; + } + default: + break; + } + + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sData)); + } + else + { + occurrence->SetAttribute("error", iRet); + } + + traverseMaterialProperties(pOccurrence, occurrence); + + setting->LinkEndChild(occurrence); + + return iRet; +} + +//###################################################################################################################### +int traverseModel(const A3DAsmModelFile* pModelFile, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + A3DAsmModelFileData sData; + A3D_INITIALIZE_DATA(A3DAsmModelFileData, sData); + + _TiXmlElement* model = new _TiXmlElement("A3DAsmModelFileData"); + traverseSource(pModelFile, model); + + iRet = A3DAsmModelFileGet(pModelFile , &sData); + if(iRet == A3D_SUCCESS) + { + A3DUns32 ui; + + model->SetAttribute("m_bUnitFromCAD", sData.m_bUnitFromCAD); + model->SetDoubleAttribute("m_dUnit", sData.m_dUnit); + model->SetAttribute("m_eModellerType", sData.m_eModellerType); + + dumpRelationships(sData.m_pBIMData, model); + + for(ui = 0; ui < sData.m_uiPOccurrencesSize; ++ui) + stTraversePOccurrence(sData.m_ppPOccurrences[ui], model); + + CHECK_RET(A3DAsmModelFileGet(NULL, &sData)); + } + else + { + model->SetAttribute("error", iRet); + } + + setting->LinkEndChild(model); + return iRet; +} diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLTessellation.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLTessellation.cpp new file mode 100644 index 0000000..a329f1f --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLTessellation.cpp @@ -0,0 +1,316 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "PRC2XML.h" + + + +//###################################################################################################################### +static _TiXmlElement* stfonts = NULL; + +//###################################################################################################################### +A3DVoid _InitializeFontsArray() +{ + if(stfonts == NULL) + stfonts = new _TiXmlElement("Fonts"); +} + +//###################################################################################################################### +A3DVoid _TerminateFontsArray() +{ + delete stfonts; + stfonts = NULL; +} + +//###################################################################################################################### +static A3DBool stCompareFontData(const _TiXmlElement* node, const A3DFontData* psFontData) +{ + if(node->Attribute("m_pcFamilyName") && strcmp(node->Attribute("m_pcFamilyName"), psFontData->m_pcFamilyName) != 0) + return false; + + int iSize; + if(node->Attribute("m_uiSize", &iSize) && iSize != (int) psFontData->m_uiSize) + return false; + if(node->Attribute("m_eCharset", &iSize) && iSize != psFontData->m_eCharset) + return false; + if(node->Attribute("m_cAttributes", &iSize) && iSize != psFontData->m_cAttributes) + return false; + + return true; +} + +//###################################################################################################################### +static A3DVoid stAddFont(const A3DFontData* psFontData) +{ + if(stfonts == NULL || psFontData == NULL) + return; + + _TiXmlElement* node = stfonts->FirstChildElement(); + while(node) + { + if(stCompareFontData(node, psFontData)) + return; + node = node->NextSiblingElement(); + } + + _TiXmlElement* font = new _TiXmlElement("A3DFontData"); + font->SetAttribute("m_pcFamilyName", psFontData->m_pcFamilyName); + font->SetAttribute("m_eCharset", psFontData->m_eCharset); + font->SetAttribute("m_uiSize", (int)psFontData->m_uiSize); + font->SetAttribute("m_cAttributes", psFontData->m_cAttributes); + stfonts->LinkEndChild(font); +} + +//###################################################################################################################### +static A3DInt32 stExportFontsFromMarkupTessellation(const A3DTessMarkupData* psTess) +{ + if(psTess->m_uiCodesSize == 0) + return A3D_SUCCESS; + + A3DFontKeyData sFontKeyData; + A3DFontData sFontData; + unsigned int uiCount, uiExtraDataType; + const A3DUns32* puiStart = &psTess->m_puiCodes[0]; + const A3DUns32* puiEnd = &psTess->m_puiCodes[psTess->m_uiCodesSize-1]; + + for(; puiStart < puiEnd; puiStart++) + { + uiCount = *puiStart & kA3DMarkupIntegerMask; + if((*puiStart & kA3DMarkupIsExtraData) != 0) + { + uiExtraDataType = (*puiStart & kA3DMarkupExtraDataType); + switch(uiExtraDataType) // forced to decode these modes to traverse the inside + { + case kA3DMarkupFaceViewMask: + case kA3DMarkupFrameDrawMask: + case kA3DMarkupFixedSizeMask: + puiStart += 1; + break; + case kA3DMarkupFontMask: + A3D_INITIALIZE_DATA(A3DFontKeyData, sFontKeyData); + sFontKeyData.m_iFontFamilyIndex = *(puiStart+2); + sFontKeyData.m_iFontStyleIndex = (*(puiStart+3) & kA3DFontKeyStyle) >> 24; + sFontKeyData.m_iFontSizeIndex = (*(puiStart+3) & kA3DFontKeySize) >> 12; + sFontKeyData.m_cAttributes = (A3DInt8) (*(puiStart+3) & kA3DFontKeyAttrib); + A3D_INITIALIZE_DATA(A3DFontData, sFontData); + CHECK_RET(A3DGlobalFontKeyGet(&sFontKeyData, &sFontData)); + stAddFont(&sFontData); + puiStart += size_t(uiCount + 1); + CHECK_RET(A3DGlobalFontKeyGet(nullptr, &sFontData)); + break; + default: + puiStart += size_t(uiCount + 1); + break; + } + } + // forced to decode that mode to traverse the inside + else if((*puiStart & kA3DMarkupIsMatrix) != 0) + puiStart += 1; + else + puiStart += size_t(uiCount + 1); + } + + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traverseFonts(_TiXmlElement* setting) +{ + if(stfonts == NULL) + return A3D_ERROR; + + _TiXmlElement* node = setting->FirstChildElement("A3DGlobalData"); + if(node == NULL) + return A3D_ERROR; + + _TiXmlElement* font = stfonts->FirstChildElement(); + while(font) + { + _TiXmlElement* newfont = new _TiXmlElement(*font); + node->LinkEndChild(newfont); + font = font->NextSiblingElement(); + } + + return A3D_SUCCESS; +} + +//###################################################################################################################### +static A3DInt32 stTraverseTessBase(const A3DTessBase* pTess, _TiXmlElement* setting) +{ + A3DTessBaseData sData; + A3D_INITIALIZE_DATA(A3DTessBaseData, sData); + + _TiXmlElement* tessbase = new _TiXmlElement("A3DTessBaseData"); + + A3DInt32 iRet = A3DTessBaseGet(pTess, &sData); + if(iRet == A3D_SUCCESS) + { + tessbase->SetAttribute("m_bIsCalculated", sData.m_bIsCalculated ? 1 : 0); + traverseDoubles("m_pdCoords", sData.m_uiCoordSize, sData.m_pdCoords, tessbase); + + A3DTessBaseGet(NULL, &sData); + } + setting->LinkEndChild(tessbase); + + return iRet; +} + +//###################################################################################################################### +int traverseMarkupTess(const A3DTessMarkup* pMarkupTess, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + A3DTessMarkupData sData; + A3D_INITIALIZE_DATA(A3DTessMarkupData, sData); + + _TiXmlElement* markuptess = new _TiXmlElement("A3DTessMarkupData"); + + stTraverseTessBase(pMarkupTess, markuptess); + + iRet = A3DTessMarkupGet(pMarkupTess, &sData); + if(iRet == A3D_SUCCESS) + { + traverseUInts("m_puiCodes",sData.m_uiCodesSize, sData.m_puiCodes, markuptess); + + for(A3DUns32 i = 0; i < sData.m_uiTextsSize; ++i) + { + _TiXmlElement* text = new _TiXmlElement("pcText"); + text->SetAttribute("data", sData.m_ppcTexts[i]); + markuptess->LinkEndChild(text); + } + + if(sData.m_pcLabel) + markuptess->SetAttribute("m_pcLabel", sData.m_pcLabel); + markuptess->SetAttribute("m_cBehaviour", (int) sData.m_cBehaviour); + + stExportFontsFromMarkupTessellation(&sData); + A3DTessMarkupGet(NULL, &sData); + } + else + { + markuptess->SetAttribute("error", iRet); + } + + setting->LinkEndChild(markuptess); + return iRet; +} + +//###################################################################################################################### +static int traverse3DWireTess(const A3DTess3DWire* pWireTess, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + A3DTess3DWireData sData; + A3D_INITIALIZE_DATA(A3DTess3DWireData, sData); + + _TiXmlElement* wiretess = new _TiXmlElement("A3DTess3DWireData"); + + stTraverseTessBase(pWireTess, wiretess); + + iRet = A3DTess3DWireGet(pWireTess, &sData); + if(iRet == A3D_SUCCESS) + { + traverseUInts("m_puiSizesWires", sData.m_uiSizesWiresSize, sData.m_puiSizesWires, wiretess); + traverseUChars("m_pucRGBAVertices", sData.m_uiRGBAVerticesSize, sData.m_pucRGBAVertices, wiretess); + + A3DTess3DWireGet(NULL, &sData); + } + else + { + wiretess->SetAttribute("error", iRet); + } + setting->LinkEndChild(wiretess); + + return iRet; +} + +//###################################################################################################################### +static int traverseFaceTessData(const A3DTessFaceData& sFaceTessData, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + + _TiXmlElement* facetess = new _TiXmlElement("A3DTessFaceData"); + + facetess->SetAttribute("m_usUsedEntitiesFlags", (int) sFaceTessData.m_usUsedEntitiesFlags); + facetess->SetAttribute("m_uiStartTriangulated", (int) sFaceTessData.m_uiStartTriangulated); + facetess->SetAttribute("m_uiStartWire", (int) sFaceTessData.m_uiStartWire); + facetess->SetAttribute("m_uiTextureCoordIndexesSize", (int) sFaceTessData.m_uiTextureCoordIndexesSize); + + traverseUInts("m_puiStyleIndexes", sFaceTessData.m_uiStyleIndexesSize, sFaceTessData.m_puiStyleIndexes, facetess); + traverseUInts("m_puiSizesTriangulated", sFaceTessData.m_uiSizesTriangulatedSize, + sFaceTessData.m_puiSizesTriangulated, facetess); + traverseUInts("m_puiSizesWires", sFaceTessData.m_uiSizesWiresSize, sFaceTessData.m_puiSizesWires, facetess); + traverseUChars("m_pucRGBAVertices", sFaceTessData.m_uiRGBAVerticesSize, sFaceTessData.m_pucRGBAVertices, facetess); + + setting->LinkEndChild(facetess); + return iRet; +} + +//###################################################################################################################### +static int sttraverse3DTess(const A3DTess3D* pTess, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + A3DTess3DData sData; + A3D_INITIALIZE_DATA(A3DTess3DData, sData); + + _TiXmlElement* tess = new _TiXmlElement("A3DTess3DData"); + + stTraverseTessBase(pTess, tess); + + iRet = A3DTess3DGet(pTess, &sData); + if(iRet == A3D_SUCCESS) + { + tess->SetAttribute("m_bHasFaces", (int)(sData.m_bHasFaces)); + traverseDoubles("m_pdNormals", sData.m_uiNormalSize, sData.m_pdNormals, tess); + traverseUInts("m_puiWireIndexes", sData.m_uiWireIndexSize, sData.m_puiWireIndexes, tess); + traverseUInts("m_puiTriangulatedIndexes", sData.m_uiTriangulatedIndexSize, sData.m_puiTriangulatedIndexes, + tess); + traverseDoubles("m_pdTextureCoords", sData.m_uiTextureCoordSize, sData.m_pdTextureCoords, tess); + tess->SetDoubleAttribute("m_dCreaseAngle", sData.m_dCreaseAngle); + + for(A3DUns32 ui = 0; ui < sData.m_uiFaceTessSize; ++ui) + traverseFaceTessData(sData.m_psFaceTessData[ui], tess); + + A3DTess3DGet(NULL, &sData); + } + else + { + tess->SetAttribute("error", iRet); + } + setting->LinkEndChild(tess); + + return iRet; +} + +//###################################################################################################################### +int traverseTessBase(const A3DTessBase* pTess, _TiXmlElement* setting) +{ + A3DEEntityType eType; + A3DInt32 iRet = A3DEntityGetType(pTess, &eType); + if(iRet == A3D_SUCCESS) + { + switch(eType) + { + case kA3DTypeTess3D: + sttraverse3DTess(pTess,setting); + break; + case kA3DTypeTess3DWire: + traverse3DWireTess(pTess,setting); + break; + case kA3DTypeTessMarkup: + traverseMarkupTess(pTess,setting); + break; + default: + break; + } + } + + return iRet; +} diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLTexture.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLTexture.cpp new file mode 100644 index 0000000..5d9f62d --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLTexture.cpp @@ -0,0 +1,94 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "PRC2XML.h" + + + +//###################################################################################################################### +int traverseTextureApplication(const A3DGraphTextureApplicationData& sData, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + _TiXmlElement *textureapplication = new _TiXmlElement("A3DGraphTextureApplicationData"); + + textureapplication->SetAttribute("m_uiMaterialIndex", (int) sData.m_uiMaterialIndex); + textureapplication->SetAttribute("m_uiTextureDefinitionIndex", (int) sData.m_uiTextureDefinitionIndex); + textureapplication->SetAttribute("m_iUVCoordinatesIndex", (int) sData.m_iUVCoordinatesIndex); + textureapplication->SetAttribute("m_uiNextTextureApplicationIndex", (int) sData.m_uiNextTextureApplicationIndex); + setting->LinkEndChild(textureapplication); + + return iRet; +} + +//###################################################################################################################### +static int sttraverseTextureTransformation(const A3DGraphTextureTransformationData& sData, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + _TiXmlElement *texturetransformation = new _TiXmlElement("A3DGraphTextureTransformationData"); + + texturetransformation->SetAttribute("m_bTextureFlipS", (int) sData.m_bTextureFlipS); + texturetransformation->SetAttribute("m_bTextureFlipT", (int) sData.m_bTextureFlipT); + traverseDoubles("m_dMatrix",16,(A3DDouble*)(&(sData.m_dMatrix)),texturetransformation); + texturetransformation->SetAttribute("m_bIs2D", (int) sData.m_bIs2D); + setting->LinkEndChild(texturetransformation); + + return iRet; +} + +//###################################################################################################################### +int traverseTextureDefinition(const A3DGraphTextureDefinitionData& sData, _TiXmlElement* setting) +{ + A3DInt32 iRet = A3D_SUCCESS; + _TiXmlElement *texturedefinition = new _TiXmlElement("A3DGraphTextureDefinitionData"); + + texturedefinition->SetAttribute("m_uiPictureIndex", (int) sData.m_uiPictureIndex); + texturedefinition->SetAttribute("m_ucTextureDimension", (int) sData.m_ucTextureDimension); + texturedefinition->SetAttribute("m_eMappingType", (int) sData.m_eMappingType); + texturedefinition->SetAttribute("m_eMappingOperator", (int) sData.m_eMappingOperator); + + traverseCartesianTransformation(sData.m_pOperatorTransfo, texturedefinition); + + texturedefinition->SetAttribute("m_uiMappingAttributes", (int) sData.m_uiMappingAttributes); + traverseDoubles("m_pdMappingAttributesIntensity", sData.m_uiMappingAttributesIntensitySize, + sData.m_pdMappingAttributesIntensity, texturedefinition); + traverseUChars("m_pucMappingAttributesComponents", sData.m_uiMappingAttributesComponentsSize, + sData.m_pucMappingAttributesComponents, texturedefinition); + texturedefinition->SetAttribute("m_eTextureFunction", (int) sData.m_eTextureFunction); + texturedefinition->SetAttribute("m_dRed", (int) sData.m_dRed); + texturedefinition->SetAttribute("m_dGreen", (int) sData.m_dGreen); + texturedefinition->SetAttribute("m_dBlue", (int) sData.m_dBlue); + texturedefinition->SetAttribute("m_dAlpha", (int) sData.m_dAlpha); + texturedefinition->SetAttribute("m_eBlend_src_RGB", (int) sData.m_eBlend_src_RGB); + texturedefinition->SetAttribute("m_eBlend_dst_RGB", (int) sData.m_eBlend_dst_RGB); + texturedefinition->SetAttribute("m_eBlend_src_Alpha", (int) sData.m_eBlend_src_Alpha); + texturedefinition->SetAttribute("m_eBlend_dst_Alpha", (int) sData.m_eBlend_dst_Alpha); + texturedefinition->SetAttribute("m_ucTextureApplyingMode", (int) sData.m_ucTextureApplyingMode); + texturedefinition->SetAttribute("m_eTextureAlphaTest", (int) sData.m_eTextureAlphaTest); + texturedefinition->SetAttribute("m_dAlphaTestReference", (int) sData.m_dAlphaTestReference); + texturedefinition->SetAttribute("m_eTextureWrappingModeS", (int) sData.m_eTextureWrappingModeS); + texturedefinition->SetAttribute("m_eTextureWrappingModeT", (int) sData.m_eTextureWrappingModeT); + + if(sData.m_pTextureTransfo != NULL) + { + A3DGraphTextureTransformationData sTransfoData; + A3D_INITIALIZE_DATA(A3DGraphTextureTransformationData, sTransfoData); + iRet = A3DGraphTextureTransformationGet(sData.m_pTextureTransfo,&sTransfoData); + if(iRet == A3D_SUCCESS) + { + sttraverseTextureTransformation(sTransfoData,texturedefinition); + A3DGraphTextureTransformationGet(NULL,&sTransfoData); + } + } + setting->LinkEndChild(texturedefinition); + + return iRet; +} diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLTools.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLTools.cpp new file mode 100644 index 0000000..8c6a8e0 --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLTools.cpp @@ -0,0 +1,450 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "PRC2XML.h" + + + +//###################################################################################################################### +#define READMAXBIGSTRING 65536 +A3DUTF8Char gbigstring[READMAXBIGSTRING]; // 64 kB buffer is OK to store big strings like array of doubles +A3DUns32 gnAllocatedStrings = 0; + +//###################################################################################################################### +void _SetDoubleAttribute(_TiXmlElement* psElement, const char* name, double val) +{ + // max size of one double: "%.15 " 13+1+15+1=30 + A3DUTF8Char* pc = gbigstring; + size_t iwritten = sprintf_s(pc,sizeof(gbigstring)-1, "%.15f", val); + for(size_t i = iwritten - 1; i > 0; i--) + { + if((pc)[i] == '0') + (pc)[i] = 0; + else + break; + } + + psElement->SetAttribute(name, pc); +} + +//###################################################################################################################### +const _TiXmlElement* _FirstChildByAttribute(_TiXmlElement* psElement, const A3DUTF8Char* pcAttribName, void* pValue) +{ + A3DUTF8Char buffer[64]; + sprintf_s(buffer,sizeof(buffer)-1, "%p", pValue); + + const _TiXmlElement* child = psElement->FirstChildElement(); + for(; child; child = child->NextSiblingElement()) + { + const A3DUTF8Char* pcValue = child->Attribute(pcAttribName); + if(pcValue != NULL && strcmp(pcValue, buffer) == 0) + return child; + } + return NULL; +} + +//###################################################################################################################### +void _SetAttributePtr(_TiXmlElement* psElement, const A3DUTF8Char* pcAttribName, void* pValue) +{ + A3DUTF8Char buffer[64]; + sprintf_s(buffer,sizeof(buffer)-1, "%p", pValue); + psElement->SetAttribute(pcAttribName, buffer); +} + +//###################################################################################################################### +int traverseDoubles(const A3DUTF8Char* name, const A3DUns32 uiSize, const A3DDouble* pd, _TiXmlElement* setting) +{ + if(uiSize > 0) + { + A3DUns32 ui = 0; + _TiXmlElement* doubles = new _TiXmlElement(name); + + doubles->SetAttribute("size", (int)uiSize); + + // max size of one double: "%.15 " 13+1+15+1=30 + A3DUns32 uiFormat = 30; + A3DUTF8Char* pc = NULL; + if(uiFormat*uiSize > READMAXBIGSTRING) + { + pc = (A3DUTF8Char*) malloc(size_t(uiSize * uiFormat) * sizeof(A3DUTF8Char)); + pc[0] = 0; + gnAllocatedStrings++; + } + else + pc = gbigstring; + + size_t uiNext = 0; + for(ui = 0; ui < uiSize; ++ui) + { + int iwritten = sprintf(pc+uiNext, "%.15f", pd[ui]); + size_t i = size_t(iwritten - 1); + for(; i > 0; i--) + { + if((pc+uiNext)[i] == '0') + (pc+uiNext)[i] = 0; + else + break; + } + (pc+uiNext)[i+1] = L' '; + uiNext += i+2; + } + pc[uiNext-1] = 0; + + doubles->SetAttribute("data", pc); + setting->LinkEndChild(doubles); + + if(uiFormat*uiSize > READMAXBIGSTRING) + free(pc); + } + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traverseUInts(const A3DUTF8Char* name, const A3DUns32 uiSize, const A3DUns32* pui, _TiXmlElement* setting) +{ + if(uiSize > 0) + { + A3DUns32 ui = 0; + _TiXmlElement* uints = new _TiXmlElement(name); + uints->SetAttribute("size", (int)uiSize); + + // max size of one uint: "%d " 14+1=15 + A3DUns32 uiFormat = 15; + A3DUTF8Char* pc = NULL; + if(uiFormat*uiSize > READMAXBIGSTRING) + { + pc = (A3DUTF8Char*) malloc(size_t(uiSize * uiFormat) * sizeof(A3DUTF8Char)); + pc[0] = 0; + gnAllocatedStrings++; + } + else + pc = gbigstring; + + size_t uiNext = 0; + for(ui = 0; ui < uiSize; ++ui) + { + int iwritten = sprintf(pc+uiNext, "%u ", pui[ui]); + uiNext += size_t(iwritten); + } + pc[uiNext] = 0; + + uints->SetAttribute("data", pc); + setting->LinkEndChild(uints); + + if(uiFormat*uiSize > READMAXBIGSTRING) + free(pc); + } + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traverseUChars(const A3DUTF8Char* name, const A3DUns32 uiSize, const A3DUns8* pui, _TiXmlElement* setting) +{ + if(uiSize > 0) + { + A3DUns32 ui = 0; + _TiXmlElement* uints = new _TiXmlElement(name); + uints->SetAttribute("size", (int)uiSize); + + // max size of one uchar: "%d ": 6 + A3DUns32 uiFormat = 6; + A3DUTF8Char* pc = NULL; + if(uiFormat*uiSize > READMAXBIGSTRING) + { + pc = (A3DUTF8Char*) malloc(size_t(uiSize * uiFormat) * sizeof(A3DUTF8Char)); + pc[0] = 0; + gnAllocatedStrings++; + } + else + pc = gbigstring; + + size_t uiNext = 0; + for(ui = 0; ui < uiSize; ++ui) + { + int iwritten = sprintf(pc+uiNext, "%u ", pui[ui]); + uiNext += size_t(iwritten); + } + pc[uiNext] = 0; + + uints->SetAttribute("data", pc); + setting->LinkEndChild(uints); + + if(uiFormat*uiSize > READMAXBIGSTRING) + free(pc); + } + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traverseBools(const A3DUTF8Char* name, const A3DUns32 uiSize, const A3DBool* pb, _TiXmlElement* setting) +{ + if(uiSize > 0) + { + A3DUns32 ui = 0; + _TiXmlElement* bools = new _TiXmlElement(name); + bools->SetAttribute("size", (int) uiSize); + + // max size of one bool: 2 + A3DUns32 uiFormat = 2; + A3DUTF8Char* pc = NULL; + if(uiFormat*uiSize > READMAXBIGSTRING) + { + pc = (A3DUTF8Char*) malloc(size_t(uiSize * uiFormat) * sizeof(A3DUTF8Char)); + pc[0] = 0; + gnAllocatedStrings++; + } + else + pc = gbigstring; + + size_t uiNext = 0; + for(ui = 0; ui < uiSize; ++ui) + { + int iwritten = sprintf(pc+uiNext, "%u ", pb[ui] ? 1 : 0); + uiNext += size_t(iwritten); + } + pc[uiNext] = 0; + + bools->SetAttribute("data", pc); + setting->LinkEndChild(bools); + + if(uiFormat*uiSize > READMAXBIGSTRING) + free(pc); + } + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traverseVoids(const A3DUTF8Char* name, const A3DUns32 uiSize, const A3DVoid** pp, _TiXmlElement* setting) +{ + if(uiSize > 0) + { + A3DUns32 ui = 0; + _TiXmlElement* uints = new _TiXmlElement(name); + uints->SetAttribute("size", (int)uiSize); + + // max size of one void: "%p ":8 + A3DUns32 uiFormat = 8; + A3DUTF8Char* pc = NULL; + if(uiFormat*uiSize > READMAXBIGSTRING) + { + pc = (A3DUTF8Char*) malloc(size_t(uiSize * uiFormat) * sizeof(A3DUTF8Char)); + pc[0] = 0; + gnAllocatedStrings++; + } + else + pc = gbigstring; + + size_t uiNext = 0; + for(ui = 0; ui < uiSize; ++ui) + { + const A3DVoid* p = pp[ui]; + int iwritten = sprintf(pc+uiNext, "%p ", (void*) p); + uiNext += size_t(iwritten); + } + pc[uiNext]=0; + + uints->SetAttribute("data", pc); + setting->LinkEndChild(uints); + + if(uiFormat*uiSize > READMAXBIGSTRING) + free(pc); + } + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traversePoint(const A3DUTF8Char* name, const A3DVector3dData& sData, _TiXmlElement* setting) +{ + _TiXmlElement* pt = new _TiXmlElement(name); + _SetDoubleAttribute(pt, "m_dX", sData.m_dX); + _SetDoubleAttribute(pt, "m_dY", sData.m_dY); + _SetDoubleAttribute(pt, "m_dZ", sData.m_dZ); + setting->LinkEndChild(pt); + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traversePoint2d(const A3DUTF8Char* name, const A3DVector2dData& sData, _TiXmlElement* setting) +{ + _TiXmlElement* pt = new _TiXmlElement(name); + _SetDoubleAttribute(pt, "m_dX", sData.m_dX); + _SetDoubleAttribute(pt, "m_dY", sData.m_dY); + setting->LinkEndChild(pt); + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traversePoints(const A3DUTF8Char* name, const A3DUns32 uiSize, const A3DVector3dData* pv, _TiXmlElement* setting) +{ + if(uiSize > 0) + { + A3DDouble* pd = (A3DDouble*) malloc(size_t(uiSize) * 3 * sizeof(A3DDouble)); + if(pd == NULL) + return A3D_ALLOC_FATAL_ERROR; + + for(A3DUns32 ui = 0; ui < uiSize; ++ui) + { + pd[3*ui] = pv[ui].m_dX; + pd[3*ui+1] = pv[ui].m_dY; + pd[3*ui+2] = pv[ui].m_dZ; + } + traverseDoubles(name, 3*uiSize, pd, setting); + free(pd); + } + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traverseInterval(const A3DIntervalData* pData, _TiXmlElement* setting) +{ + _TiXmlElement* extent1d = new _TiXmlElement("A3DIntervalData"); + _SetDoubleAttribute(extent1d, "m_dMin", pData->m_dMin); + _SetDoubleAttribute(extent1d, "m_dMax", pData->m_dMax); + setting->LinkEndChild(extent1d); + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traverseDomain(const A3DDomainData* pData, _TiXmlElement* setting) +{ + _TiXmlElement* extent2d = new _TiXmlElement("A3DDomainData"); + _SetDoubleAttribute(extent2d, "m_sMin.m_dX", pData->m_sMin.m_dX); + _SetDoubleAttribute(extent2d, "m_sMin.m_dY", pData->m_sMin.m_dY); + _SetDoubleAttribute(extent2d, "m_sMax.m_dX", pData->m_sMax.m_dX); + _SetDoubleAttribute(extent2d, "m_sMax.m_dY", pData->m_sMax.m_dY); + setting->LinkEndChild(extent2d); + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traverseBoundingBox(const A3DBoundingBoxData* pData, _TiXmlElement* setting) +{ + _TiXmlElement* extent3d = new _TiXmlElement("A3DBoundingBoxData"); + _SetDoubleAttribute(extent3d, "m_sMin.m_dX", pData->m_sMin.m_dX); + _SetDoubleAttribute(extent3d, "m_sMin.m_dY", pData->m_sMin.m_dY); + _SetDoubleAttribute(extent3d, "m_sMin.m_dZ", pData->m_sMin.m_dZ); + _SetDoubleAttribute(extent3d, "m_sMax.m_dX", pData->m_sMax.m_dX); + _SetDoubleAttribute(extent3d, "m_sMax.m_dY", pData->m_sMax.m_dY); + _SetDoubleAttribute(extent3d, "m_sMax.m_dZ", pData->m_sMax.m_dZ); + setting->LinkEndChild(extent3d); + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traverseParam(const A3DParameterizationData* pData, _TiXmlElement* setting) +{ + _TiXmlElement* param = new _TiXmlElement("A3DParameterizationData"); + _SetDoubleAttribute(param, "m_sInterval.m_dMin", pData->m_sInterval.m_dMin); + _SetDoubleAttribute(param, "m_sInterval.m_dMax", pData->m_sInterval.m_dMax); + _SetDoubleAttribute(param, "m_dCoeffA", pData->m_dCoeffA); + _SetDoubleAttribute(param, "m_dCoeffB", pData->m_dCoeffB); + setting->LinkEndChild(param); + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traverseUVParam(const A3DUVParameterizationData* pData, _TiXmlElement* setting) +{ + _TiXmlElement* param = new _TiXmlElement("A3DUVParameterizationData"); + traverseDomain(&pData->m_sUVDomain, param); + _SetDoubleAttribute(param, "m_dUCoeffA", pData->m_dUCoeffA); + _SetDoubleAttribute(param, "m_dUCoeffB", pData->m_dUCoeffB); + _SetDoubleAttribute(param, "m_dVCoeffA", pData->m_dVCoeffA); + _SetDoubleAttribute(param, "m_dVCoeffB", pData->m_dVCoeffB); + _SetDoubleAttribute(param, "m_bSwapUV", (int)pData->m_bSwapUV); + setting->LinkEndChild(param); + return A3D_SUCCESS; +} + +//###################################################################################################################### +A3DStatus traverseCartesianTransformationData(const A3DMiscCartesianTransformationData& oTrsf, _TiXmlElement* setting) +{ + _TiXmlElement* trsf = new _TiXmlElement("A3DMiscCartesianTransformationData"); + trsf->SetAttribute("m_ucBehaviour", (int)(oTrsf.m_ucBehaviour)); + traversePoint("m_sOrigin" , oTrsf.m_sOrigin , trsf); + traversePoint("m_sXVector", oTrsf.m_sXVector, trsf); + traversePoint("m_sYVector", oTrsf.m_sYVector, trsf); + traversePoint("m_sScale" , oTrsf.m_sScale , trsf); + setting->LinkEndChild(trsf); + return A3D_SUCCESS; +} + + +//###################################################################################################################### +A3DStatus traverseCartesianTransformation(const A3DMiscCartesianTransformation* pTrsf, _TiXmlElement* setting) +{ + if (pTrsf) + { + A3DMiscCartesianTransformationData sData; + A3D_INITIALIZE_DATA(A3DMiscCartesianTransformationData, sData); + A3DStatus iRet = A3DMiscCartesianTransformationGet(pTrsf, &sData); + if (iRet == A3D_SUCCESS) + { + traverseCartesianTransformationData(sData, setting); + A3DMiscCartesianTransformationGet(NULL, &sData); + } + else + { + setting->SetAttribute("error", iRet); + } + } + return A3D_SUCCESS; +} + +//###################################################################################################################### +A3DStatus traverseGeneralTransformation(const A3DMiscGeneralTransformation* pTrsf, _TiXmlElement* setting) +{ + _TiXmlElement* trsf = new _TiXmlElement("A3DMiscGeneralTransformationData"); + A3DMiscGeneralTransformationData sData; + A3D_INITIALIZE_DATA(A3DMiscGeneralTransformationData, sData); + A3DStatus iRet = A3DMiscGeneralTransformationGet(pTrsf, &sData); + if (iRet == A3D_SUCCESS) + { + traverseDoubles("m_adCoeff", 16, sData.m_adCoeff, trsf); + A3DMiscGeneralTransformationGet(NULL, &sData); + } + else + { + trsf->SetAttribute("error", iRet); + } + setting->LinkEndChild(trsf); + return A3D_SUCCESS; +} + +//###################################################################################################################### +A3DStatus traverseTransformation(const A3DMiscTransformation* pTransfo3d, _TiXmlElement* setting) +{ + if(pTransfo3d == NULL) + return A3D_SUCCESS; + + A3DStatus iRet; + _TiXmlElement* trsf = new _TiXmlElement("A3DMiscTransformation"); + traverseSource(pTransfo3d, trsf); + A3DEEntityType eType = kA3DTypeUnknown; + iRet = A3DEntityGetType(pTransfo3d, &eType); + if (eType == kA3DTypeMiscCartesianTransformation) + { + iRet = traverseCartesianTransformation(pTransfo3d, trsf); + } + else if (eType == kA3DTypeMiscGeneralTransformation) + { + iRet = traverseGeneralTransformation(pTransfo3d, trsf); + } + else + { + trsf->SetAttribute("error", iRet); + } + + setting->LinkEndChild(trsf); + return iRet; +} + diff --git a/exchange/exchangesource/PRC2XML/PRC2XMLTopology.cpp b/exchange/exchangesource/PRC2XML/PRC2XMLTopology.cpp new file mode 100644 index 0000000..7761e60 --- /dev/null +++ b/exchange/exchangesource/PRC2XML/PRC2XMLTopology.cpp @@ -0,0 +1,417 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "PRC2XML.h" + + + +//###################################################################################################################### +static int sttraverseMultipleVertex(const A3DTopoMultipleVertex* pVertex, _TiXmlElement* setting) +{ + A3DTopoMultipleVertexData sData; + A3D_INITIALIZE_DATA(A3DTopoMultipleVertexData, sData); + + _TiXmlElement* vertex = new _TiXmlElement("A3DTopoMultipleVertexData"); + traverseSource(pVertex, vertex); + + A3DInt32 iRet = A3DTopoMultipleVertexGet(pVertex, &sData); + if(iRet == A3D_SUCCESS) + { + traversePoints("m_pPts",sData.m_uiSize, sData.m_pPts, vertex); + A3DTopoMultipleVertexGet(NULL, &sData); + } + else + { + vertex->SetAttribute("error", iRet); + } + + setting->LinkEndChild(vertex); + return iRet; +} + +//###################################################################################################################### +static int sttraverseUniqueVertex(const A3DTopoUniqueVertex* pVertex, _TiXmlElement* setting) +{ + A3DTopoUniqueVertexData sData; + A3D_INITIALIZE_DATA(A3DTopoUniqueVertexData, sData); + + _TiXmlElement* vertex = new _TiXmlElement("A3DTopoUniqueVertexData"); + traverseSource(pVertex, vertex); + + A3DInt32 iRet = A3DTopoUniqueVertexGet(pVertex, &sData); + if(iRet == A3D_SUCCESS) + { + traversePoint("m_sPoint", sData.m_sPoint, vertex); + _SetDoubleAttribute(vertex, "m_dTolerance", sData.m_dTolerance); + A3DTopoUniqueVertexGet(NULL, &sData); + } + else + { + vertex->SetAttribute("error", iRet); + } + + setting->LinkEndChild(vertex); + return iRet; +} + +//###################################################################################################################### +static int sttraverseVertex(const A3DTopoVertex* pVertex, _TiXmlElement* setting) +{ + A3DEEntityType eType; + A3DInt32 iRet = A3DEntityGetType(pVertex, &eType); + if(iRet == A3D_SUCCESS) + { + switch(eType) + { + case kA3DTypeTopoMultipleVertex: + iRet = sttraverseMultipleVertex(pVertex, setting); + break; + case kA3DTypeTopoUniqueVertex: + iRet = sttraverseUniqueVertex(pVertex, setting); + break; + default: + break; + } + } + return iRet; +} + +//###################################################################################################################### +static int sttraverseEdge(const A3DTopoEdge* pEdge, _TiXmlElement* setting) +{ + A3DTopoEdgeData sData; + A3D_INITIALIZE_DATA(A3DTopoEdgeData, sData); + + _TiXmlElement* edge = new _TiXmlElement("A3DTopoEdgeData"); + traverseSource(pEdge, edge); + + A3DInt32 iRet = A3DTopoEdgeGet(pEdge, &sData); + if(iRet == A3D_SUCCESS) + { + _SetDoubleAttribute(edge, "m_dTolerance", sData.m_dTolerance); + edge->SetAttribute("m_bHasTrimDomain", (int) sData.m_bHasTrimDomain); + + if(sData.m_p3dCurve) + traverseCurve(sData.m_p3dCurve, edge); + if(sData.m_bHasTrimDomain) + traverseInterval(&sData.m_sInterval, edge); + + if(sData.m_pStartVertex) + sttraverseVertex(sData.m_pStartVertex, edge); + if(sData.m_pEndVertex) + sttraverseVertex(sData.m_pEndVertex, edge); + + A3DTopoEdgeGet(NULL, &sData); + } + else + { + edge->SetAttribute("error", iRet); + } + + setting->LinkEndChild(edge); + return iRet; +} + +//###################################################################################################################### +static int sttraverseCoEdge(const A3DTopoCoEdge* pCoEdge, _TiXmlElement* setting) +{ + A3DTopoCoEdgeData sData; + A3D_INITIALIZE_DATA(A3DTopoCoEdgeData, sData); + + _TiXmlElement* coedge = new _TiXmlElement("A3DTopoCoEdgeData"); + traverseSource(pCoEdge, coedge); + + A3DInt32 iRet = A3DTopoCoEdgeGet(pCoEdge, &sData); + if(iRet == A3D_SUCCESS) + { + if(sData.m_pEdge) + sttraverseEdge(sData.m_pEdge, coedge); + if(sData.m_pUVCurve) + traverseCurve(sData.m_pUVCurve, coedge); + + //_SetAttributePtr(coedge, "m_pNeighbor", sData.m_pNeighbor); + coedge->SetAttribute("m_pNeighbor", sData.m_pNeighbor ? "true" : "false"); + coedge->SetAttribute("m_ucOrientationUVWithLoop", (int) sData.m_ucOrientationUVWithLoop); + coedge->SetAttribute("m_ucOrientationWithLoop", (int) sData.m_ucOrientationWithLoop); + A3DTopoCoEdgeGet(NULL, &sData); + } + else + { + coedge->SetAttribute("error", iRet); + } + + setting->LinkEndChild(coedge); + return iRet; +} + +//###################################################################################################################### +static int sttraverseLoop(const A3DTopoLoop* pLoop, _TiXmlElement* setting) +{ + A3DTopoLoopData sData; + A3D_INITIALIZE_DATA(A3DTopoLoopData, sData); + + _TiXmlElement* loop = new _TiXmlElement("A3DTopoLoopData"); + traverseSource(pLoop, loop); + + A3DInt32 iRet = A3DTopoLoopGet(pLoop, &sData); + if(iRet == A3D_SUCCESS) + { + loop->SetAttribute("m_ucOrientationWithSurface", (int)(sData.m_ucOrientationWithSurface)); + for(A3DUns32 ui = 0; ui < sData.m_uiCoEdgeSize; ++ui) + iRet = sttraverseCoEdge(sData.m_ppCoEdges[ui], loop); + A3DTopoLoopGet(NULL, &sData); + } + else + { + loop->SetAttribute("error", iRet); + } + + setting->LinkEndChild(loop); + return iRet; +} + +//###################################################################################################################### +static int sttraverseFace(const A3DTopoFace* pFace, _TiXmlElement* setting) +{ + A3DTopoFaceData sData; + A3D_INITIALIZE_DATA(A3DTopoFaceData, sData); + + _TiXmlElement* face = new _TiXmlElement("A3DTopoFaceData"); + traverseSource(pFace, face); + + A3DInt32 iRet = A3DTopoFaceGet(pFace, &sData); + if(iRet == A3D_SUCCESS) + { + face->SetAttribute("m_bHasTrimDomain", (int)(sData.m_bHasTrimDomain)); + face->SetAttribute("m_uiOuterLoopIndex", (int)(sData.m_uiOuterLoopIndex)); + _SetDoubleAttribute(face, "m_dTolerance", sData.m_dTolerance); + + traverseSurface(sData.m_pSurface, face); + + if(sData.m_bHasTrimDomain) + traverseDomain(&sData.m_sSurfaceDomain, face); + + for(A3DUns32 ui = 0; ui < sData.m_uiLoopSize; ++ui) + iRet = sttraverseLoop(sData.m_ppLoops[ui], face); + + A3DTopoFaceGet(NULL, &sData); + } + else + { + face->SetAttribute("error", iRet); + } + + setting->LinkEndChild(face); + return iRet; +} + +//###################################################################################################################### +static int sttraverseShell(const A3DTopoShell* pShell, _TiXmlElement* setting) +{ + A3DTopoShellData sData; + A3D_INITIALIZE_DATA(A3DTopoShellData, sData); + + _TiXmlElement* shell = new _TiXmlElement("A3DTopoShellData"); + traverseSource(pShell, shell); + + A3DInt32 iRet = A3DTopoShellGet(pShell, &sData); + if(iRet == A3D_SUCCESS) + { + shell->SetAttribute("closed", (int)(sData.m_bClosed)); + + for(A3DUns32 ui = 0; ui < sData.m_uiFaceSize; ++ui) + iRet = sttraverseFace(sData.m_ppFaces[ui], shell); + + traverseUChars("m_pucOrientationWithShell",sData.m_uiFaceSize,sData.m_pucOrientationWithShell,shell); + + A3DTopoShellGet(NULL, &sData); + } + else + { + shell->SetAttribute("error", iRet); + } + + setting->LinkEndChild(shell); + return iRet; +} + +//###################################################################################################################### +static int sttraverseConnex(const A3DTopoConnex* pConnex, _TiXmlElement* setting) +{ + A3DTopoConnexData sData; + A3D_INITIALIZE_DATA(A3DTopoConnexData, sData); + + _TiXmlElement* connex = new _TiXmlElement("A3DTopoConnexData"); + traverseSource(pConnex, connex); + + A3DInt32 iRet = A3DTopoConnexGet(pConnex, &sData); + if(iRet == A3D_SUCCESS) + { + for(A3DUns32 ui = 0; ui < sData.m_uiShellSize; ++ui) + iRet = sttraverseShell(sData.m_ppShells[ui], connex); + A3DTopoConnexGet(NULL, &sData); + } + else + { + connex->SetAttribute("error", iRet); + } + + setting->LinkEndChild(connex); + return iRet; +} + +//###################################################################################################################### +int traverseBrepData(const A3DTopoBrepData* pBrepData, _TiXmlElement* setting) +{ + A3DTopoBrepDataData sData; + A3D_INITIALIZE_DATA(A3DTopoBrepDataData, sData); + + _TiXmlElement* brepdata = new _TiXmlElement("A3DTopoBrepDataData"); + traverseSource(pBrepData, brepdata); + unsigned char ucBehavior; + traverseBodyContent(pBrepData, brepdata,ucBehavior); + + A3DInt32 iRet = A3DTopoBrepDataGet(pBrepData, &sData); + if(iRet == A3D_SUCCESS) + { + for(A3DUns32 ui = 0; ui < sData.m_uiConnexSize; ++ui) + iRet = sttraverseConnex(sData.m_ppConnexes[ui], brepdata); + + if(ucBehavior !=0) + iRet = traverseBoundingBox(&sData.m_sBoundingBox, brepdata); + + A3DTopoBrepDataGet(NULL, &sData); + } + else + { + brepdata->SetAttribute("error", iRet); + } + + setting->LinkEndChild(brepdata); + return iRet; +} + +//###################################################################################################################### +static int sttraverseWireEdge(const A3DTopoWireEdge* pWireEdge, _TiXmlElement* setting) +{ + A3DTopoWireEdgeData sData; + A3D_INITIALIZE_DATA(A3DTopoWireEdgeData, sData); + + _TiXmlElement* wireedge = new _TiXmlElement("A3DTopoWireEdgeData"); + traverseSource(pWireEdge, wireedge); + + A3DInt32 iRet = A3DTopoWireEdgeGet(pWireEdge, &sData); + if(iRet == A3D_SUCCESS) + { + wireedge->SetAttribute("m_bHasTrimDomain", (int) sData.m_bHasTrimDomain); + + if(sData.m_p3dCurve) + traverseCurve(sData.m_p3dCurve, wireedge); + + if(sData.m_bHasTrimDomain) + traverseInterval(&sData.m_sInterval, wireedge); + + A3DTopoWireEdgeGet(NULL, &sData); + } + else + { + wireedge->SetAttribute("error", iRet); + } + + setting->LinkEndChild(wireedge); + return iRet; +} + +//###################################################################################################################### +int traverseSingleWireBody(const A3DTopoSingleWireBody* pSingleWireBody, _TiXmlElement* setting) +{ + A3DTopoSingleWireBodyData sData; + A3D_INITIALIZE_DATA(A3DTopoSingleWireBodyData, sData); + + _TiXmlElement* singlewirebody = new _TiXmlElement("A3DTopoSingleWireBodyData"); + traverseSource(pSingleWireBody, singlewirebody); + unsigned char ucBehavior; + traverseBodyContent(pSingleWireBody, singlewirebody, ucBehavior); + + A3DInt32 iRet = A3DTopoSingleWireBodyGet(pSingleWireBody, &sData); + if(iRet == A3D_SUCCESS) + { + iRet = sttraverseWireEdge(sData.m_pWireEdge, singlewirebody); + A3DTopoSingleWireBodyGet(NULL, &sData); + } + else + { + singlewirebody->SetAttribute("error", iRet); + } + + setting->LinkEndChild(singlewirebody); + return iRet; +} + +//###################################################################################################################### +int traverseBodyContent(const A3DTopoBody* pBody, _TiXmlElement* setting, unsigned char &ucBehavior) +{ + A3DInt32 iErr = A3D_SUCCESS; + A3DTopoBodyData sData; + A3D_INITIALIZE_DATA(A3DTopoBodyData, sData); + + iErr = A3DTopoBodyGet(pBody, &sData); + if(iErr == A3D_SUCCESS) + { + _TiXmlElement* bodydata = new _TiXmlElement("A3DTopoBodyData"); + + ucBehavior = (unsigned char) sData.m_ucBehaviour; + bodydata->SetAttribute("m_ucBehaviour", (int) sData.m_ucBehaviour); + + if(sData.m_pContext) + { + traverseTopoContext(sData.m_pContext, bodydata); + setting->LinkEndChild(bodydata); + } + + A3DTopoBodyGet(NULL, &sData); + } + + return A3D_SUCCESS; +} + +//###################################################################################################################### +int traverseTopoContext(const A3DTopoContext* pContext, _TiXmlElement* setting) +{ + A3DInt32 iErr = A3D_SUCCESS; + A3DTopoContextData sData; + A3D_INITIALIZE_DATA(A3DTopoContextData, sData); + + _TiXmlElement* topocontext = new _TiXmlElement("A3DTopoContextData"); + traverseSource(pContext, topocontext); + + iErr = A3DTopoContextGet(pContext, &sData); + if(iErr == A3D_SUCCESS) + { + topocontext->SetAttribute("m_ucBehaviour", sData.m_ucBehaviour); + topocontext->SetDoubleAttribute("m_dGranularity", sData.m_dGranularity); + topocontext->SetDoubleAttribute("m_dTolerance", sData.m_dTolerance); + topocontext->SetAttribute("m_bHaveSmallestFaceThickness", sData.m_bHaveSmallestFaceThickness ? "true" : "false"); + topocontext->SetDoubleAttribute("m_dSmallestThickness", sData.m_dSmallestThickness); + topocontext->SetAttribute("m_bHaveScale", sData.m_bHaveScale ? "true" : "false"); + topocontext->SetDoubleAttribute("m_dScale", sData.m_dScale); + + A3DTopoContextGet(NULL, &sData); + } + else + { + topocontext->SetAttribute("error", iErr); + } + + setting->LinkEndChild(topocontext); + return iErr; +} diff --git a/exchange/exchangesource/PRC2XML/TinyXML/tinystr.cpp b/exchange/exchangesource/PRC2XML/TinyXML/tinystr.cpp new file mode 100644 index 0000000..840bb31 --- /dev/null +++ b/exchange/exchangesource/PRC2XML/TinyXML/tinystr.cpp @@ -0,0 +1,111 @@ +/* +www.sourceforge.net/projects/tinyxml + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + + +#ifndef TIXML_USE_STL + +#include "tinystr.h" + +// Error value for find primitive +const _TiXmlString::size_type _TiXmlString::npos = static_cast< _TiXmlString::size_type >(-1); + + +// Null rep. +_TiXmlString::Rep _TiXmlString::nullrep_ = { 0, 0, { '\0' } }; + + +void _TiXmlString::reserve (size_type cap) +{ + if (cap > capacity()) + { + _TiXmlString tmp; + tmp.init(length(), cap); + memcpy(tmp.start(), data(), length()); + swap(tmp); + } +} + + +_TiXmlString& _TiXmlString::assign(const char* str, size_type len) +{ + size_type cap = capacity(); + if (len > cap || cap > 3*(len + 8)) + { + _TiXmlString tmp; + tmp.init(len); + memcpy(tmp.start(), str, len); + swap(tmp); + } + else + { + memmove(start(), str, len); + set_size(len); + } + return *this; +} + + +_TiXmlString& _TiXmlString::append(const char* str, size_type len) +{ + size_type newsize = length() + len; + if (newsize > capacity()) + { + reserve (newsize + capacity()); + } + memmove(finish(), str, len); + set_size(newsize); + return *this; +} + + +_TiXmlString operator + (const _TiXmlString & a, const _TiXmlString & b) +{ + _TiXmlString tmp; + tmp.reserve(a.length() + b.length()); + tmp += a; + tmp += b; + return tmp; +} + +_TiXmlString operator + (const _TiXmlString & a, const char* b) +{ + _TiXmlString tmp; + _TiXmlString::size_type b_len = static_cast<_TiXmlString::size_type>( strlen(b) ); + tmp.reserve(a.length() + b_len); + tmp += a; + tmp.append(b, b_len); + return tmp; +} + +_TiXmlString operator + (const char* a, const _TiXmlString & b) +{ + _TiXmlString tmp; + _TiXmlString::size_type a_len = static_cast<_TiXmlString::size_type>( strlen(a) ); + tmp.reserve(a_len + b.length()); + tmp.append(a, a_len); + tmp += b; + return tmp; +} + + +#endif // TIXML_USE_STL diff --git a/exchange/exchangesource/PRC2XML/TinyXML/tinystr.h b/exchange/exchangesource/PRC2XML/TinyXML/tinystr.h new file mode 100644 index 0000000..ed5b54d --- /dev/null +++ b/exchange/exchangesource/PRC2XML/TinyXML/tinystr.h @@ -0,0 +1,305 @@ +/* +www.sourceforge.net/projects/tinyxml + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + + +#ifndef TIXML_USE_STL + +#ifndef TIXML_STRING_INCLUDED +#define TIXML_STRING_INCLUDED + +#include +#include + +/* The support for explicit isn't that universal, and it isn't really + required - it is used to check that the TiXmlString class isn't incorrectly + used. Be nice to old compilers and macro it here: +*/ +#if defined(_MSC_VER) && (_MSC_VER >= 1200 ) + // Microsoft visual studio, version 6 and higher. + #define TIXML_EXPLICIT explicit +#elif defined(__GNUC__) && (__GNUC__ >= 3 ) + // GCC version 3 and higher.s + #define TIXML_EXPLICIT explicit +#else + #define TIXML_EXPLICIT +#endif + + +/* + TiXmlString is an emulation of a subset of the std::string template. + Its purpose is to allow compiling TinyXML on compilers with no or poor STL support. + Only the member functions relevant to the TinyXML project have been implemented. + The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase + a string and there's no more room, we allocate a buffer twice as big as we need. +*/ +class _TiXmlString +{ + public : + // The size type used + typedef size_t size_type; + + // Error value for find primitive + static const size_type npos; // = -1; + + + // TiXmlString empty constructor + _TiXmlString () : rep_(&nullrep_) + { + } + + // TiXmlString copy constructor + _TiXmlString ( const _TiXmlString & copy) : rep_(0) + { + init(copy.length()); + memcpy(start(), copy.data(), length()); + } + + // TiXmlString constructor, based on a string + TIXML_EXPLICIT _TiXmlString ( const char * copy) : rep_(0) + { + init( static_cast( strlen(copy) )); + memcpy(start(), copy, length()); + } + + // TiXmlString constructor, based on a string + TIXML_EXPLICIT _TiXmlString ( const char * str, size_type len) : rep_(0) + { + init(len); + memcpy(start(), str, len); + } + + // TiXmlString destructor + ~_TiXmlString () + { + quit(); + } + + _TiXmlString& operator = (const char * copy) + { + return assign( copy, (size_type)strlen(copy)); + } + + _TiXmlString& operator = (const _TiXmlString & copy) + { + return assign(copy.start(), copy.length()); + } + + + // += operator. Maps to append + _TiXmlString& operator += (const char * suffix) + { + return append(suffix, static_cast( strlen(suffix) )); + } + + // += operator. Maps to append + _TiXmlString& operator += (char single) + { + return append(&single, 1); + } + + // += operator. Maps to append + _TiXmlString& operator += (const _TiXmlString & suffix) + { + return append(suffix.data(), suffix.length()); + } + + + // Convert a TiXmlString into a null-terminated char * + const char * c_str () const { return rep_->str; } + + // Convert a TiXmlString into a char * (need not be null terminated). + const char * data () const { return rep_->str; } + + // Return the length of a TiXmlString + size_type length () const { return rep_->size; } + + // Alias for length() + size_type size () const { return rep_->size; } + + // Checks if a TiXmlString is empty + bool empty () const { return rep_->size == 0; } + + // Return capacity of string + size_type capacity () const { return rep_->capacity; } + + + // single char extraction + const char& at (size_type index) const + { + assert( index < length() ); + return rep_->str[ index ]; + } + + // [] operator + char& operator [] (size_type index) const + { + assert( index < length() ); + return rep_->str[ index ]; + } + + // find a char in a string. Return TiXmlString::npos if not found + size_type find (char lookup) const + { + return find(lookup, 0); + } + + // find a char in a string from an offset. Return TiXmlString::npos if not found + size_type find (char tofind, size_type offset) const + { + if (offset >= length()) return npos; + + for (const char* p = c_str() + offset; *p != '\0'; ++p) + { + if (*p == tofind) return static_cast< size_type >( p - c_str() ); + } + return npos; + } + + void clear () + { + //Lee: + //The original was just too strange, though correct: + // TiXmlString().swap(*this); + //Instead use the quit & re-init: + quit(); + init(0,0); + } + + /* Function to reserve a big amount of data when we know we'll need it. Be aware that this + function DOES NOT clear the content of the TiXmlString if any exists. + */ + void reserve (size_type cap); + + _TiXmlString& assign (const char* str, size_type len); + + _TiXmlString& append (const char* str, size_type len); + + void swap (_TiXmlString& other) + { + Rep* r = rep_; + rep_ = other.rep_; + other.rep_ = r; + } + + private: + + void init(size_type sz) { init(sz, sz); } + void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; } + char* start() const { return rep_->str; } + char* finish() const { return rep_->str + rep_->size; } + + struct Rep + { + size_type size, capacity; + char str[1]; + }; + + void init(size_type sz, size_type cap) + { + if (cap) + { + // Lee: the original form: + // rep_ = static_cast(operator new(sizeof(Rep) + cap)); + // doesn't work in some cases of new being overloaded. Switching + // to the normal allocation, although use an 'int' for systems + // that are overly picky about structure alignment. + const size_type bytesNeeded = sizeof(Rep) + cap; + const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int ); + rep_ = reinterpret_cast( new int[ intsNeeded ] ); + + rep_->str[ rep_->size = sz ] = '\0'; + rep_->capacity = cap; + } + else + { + rep_ = &nullrep_; + } + } + + void quit() + { + if (rep_ != &nullrep_) + { + // The rep_ is really an array of ints. (see the allocator, above). + // Cast it back before delete, so the compiler won't incorrectly call destructors. + delete [] ( reinterpret_cast( rep_ ) ); + } + } + + Rep * rep_; + static Rep nullrep_; + +} ; + + +inline bool operator == (const _TiXmlString & a, const _TiXmlString & b) +{ + return ( a.length() == b.length() ) // optimization on some platforms + && ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare +} +inline bool operator < (const _TiXmlString & a, const _TiXmlString & b) +{ + return strcmp(a.c_str(), b.c_str()) < 0; +} + +inline bool operator != (const _TiXmlString & a, const _TiXmlString & b) { return !(a == b); } +inline bool operator > (const _TiXmlString & a, const _TiXmlString & b) { return b < a; } +inline bool operator <= (const _TiXmlString & a, const _TiXmlString & b) { return !(b < a); } +inline bool operator >= (const _TiXmlString & a, const _TiXmlString & b) { return !(a < b); } + +inline bool operator == (const _TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; } +inline bool operator == (const char* a, const _TiXmlString & b) { return b == a; } +inline bool operator != (const _TiXmlString & a, const char* b) { return !(a == b); } +inline bool operator != (const char* a, const _TiXmlString & b) { return !(b == a); } + +_TiXmlString operator + (const _TiXmlString & a, const _TiXmlString & b); +_TiXmlString operator + (const _TiXmlString & a, const char* b); +_TiXmlString operator + (const char* a, const _TiXmlString & b); + + +/* + TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString. + Only the operators that we need for TinyXML have been developped. +*/ +class TiXmlOutStream : public _TiXmlString +{ +public : + + // TiXmlOutStream << operator. + TiXmlOutStream & operator << (const _TiXmlString & in) + { + *this += in; + return *this; + } + + // TiXmlOutStream << operator. + TiXmlOutStream & operator << (const char * in) + { + *this += in; + return *this; + } + +} ; + +#endif // TIXML_STRING_INCLUDED +#endif // TIXML_USE_STL diff --git a/exchange/exchangesource/PRC2XML/TinyXML/tinyxml.cpp b/exchange/exchangesource/PRC2XML/TinyXML/tinyxml.cpp new file mode 100644 index 0000000..68ef65d --- /dev/null +++ b/exchange/exchangesource/PRC2XML/TinyXML/tinyxml.cpp @@ -0,0 +1,1886 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code by Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include + +#ifdef TIXML_USE_STL +#include +#include +#endif + +#include "tinyxml.h" + +FILE* TiXmlFOpen( const char* filename, const char* mode ); + +bool _TiXmlBase::condenseWhiteSpace = true; + +// Microsoft compiler security +FILE* TiXmlFOpen( const char* filename, const char* mode ) +{ + #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) + FILE* fp = 0; + errno_t err = fopen_s( &fp, filename, mode ); + if ( !err && fp ) + return fp; + return 0; + #else + return fopen( filename, mode ); + #endif +} + +void _TiXmlBase::EncodeString( const TIXML_STRING& str, TIXML_STRING* outString ) +{ + int i=0; + + while( i<(int)str.length() ) + { + unsigned char c = (unsigned char) str[i]; + + if ( c == '&' + && i < ( (int)str.length() - 2 ) + && str[i+1] == '#' + && str[i+2] == 'x' ) + { + // Hexadecimal character reference. + // Pass through unchanged. + // © -- copyright symbol, for example. + // + // The -1 is a bug fix from Rob Laveaux. It keeps + // an overflow from happening if there is no ';'. + // There are actually 2 ways to exit this loop - + // while fails (error case) and break (semicolon found). + // However, there is no mechanism (currently) for + // this function to return an error. + while ( i<(int)str.length()-1 ) + { + outString->append( str.c_str() + i, 1 ); + ++i; + if ( str[i] == ';' ) + break; + } + } + else if ( c == '&' ) + { + outString->append( entity[0].str, entity[0].strLength ); + ++i; + } + else if ( c == '<' ) + { + outString->append( entity[1].str, entity[1].strLength ); + ++i; + } + else if ( c == '>' ) + { + outString->append( entity[2].str, entity[2].strLength ); + ++i; + } + else if ( c == '\"' ) + { + outString->append( entity[3].str, entity[3].strLength ); + ++i; + } + else if ( c == '\'' ) + { + outString->append( entity[4].str, entity[4].strLength ); + ++i; + } + else if ( c < 32 ) + { + // Easy pass at non-alpha/numeric/symbol + // Below 32 is symbolic. + char buf[ 32 ]; + + #if defined(TIXML_SNPRINTF) + TIXML_SNPRINTF( buf, sizeof(buf), "&#x%02X;", (unsigned) ( c & 0xff ) ); + #else + sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) ); + #endif + + //*ME: warning C4267: convert 'size_t' to 'int' + //*ME: Int-Cast to make compiler happy ... + outString->append( buf, (int)strlen( buf ) ); + ++i; + } + else + { + //char realc = (char) c; + //outString->append( &realc, 1 ); + *outString += (char) c; // somewhat more efficient function call. + ++i; + } + } +} + + +_TiXmlNode::_TiXmlNode( NodeType _type ) : _TiXmlBase() +{ + parent = 0; + type = _type; + firstChild = 0; + lastChild = 0; + prev = 0; + next = 0; +} + + +_TiXmlNode::~_TiXmlNode() +{ + _TiXmlNode* node = firstChild; + _TiXmlNode* temp = 0; + + while ( node ) + { + temp = node; + node = node->next; + delete temp; + } +} + + +void _TiXmlNode::CopyTo( _TiXmlNode* target ) const +{ + target->SetValue (value.c_str() ); + target->userData = userData; + target->location = location; +} + + +void _TiXmlNode::Clear() +{ + _TiXmlNode* node = firstChild; + _TiXmlNode* temp = 0; + + while ( node ) + { + temp = node; + node = node->next; + delete temp; + } + + firstChild = 0; + lastChild = 0; +} + + +_TiXmlNode* _TiXmlNode::LinkEndChild( _TiXmlNode* node ) +{ + assert( node->parent == 0 || node->parent == this ); + assert( node->GetDocument() == 0 || node->GetDocument() == this->GetDocument() ); + + if ( node->Type() == _TiXmlNode::TINYXML_DOCUMENT ) + { + delete node; + if ( GetDocument() ) + GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + node->parent = this; + + node->prev = lastChild; + node->next = 0; + + if ( lastChild ) + lastChild->next = node; + else + firstChild = node; // it was an empty list. + + lastChild = node; + return node; +} + + +_TiXmlNode* _TiXmlNode::InsertEndChild( const _TiXmlNode& addThis ) +{ + if ( addThis.Type() == _TiXmlNode::TINYXML_DOCUMENT ) + { + if ( GetDocument() ) + GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + _TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + + return LinkEndChild( node ); +} + + +_TiXmlNode* _TiXmlNode::InsertBeforeChild( _TiXmlNode* beforeThis, const _TiXmlNode& addThis ) +{ + if ( !beforeThis || beforeThis->parent != this ) { + return 0; + } + if ( addThis.Type() == _TiXmlNode::TINYXML_DOCUMENT ) + { + if ( GetDocument() ) + GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + _TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + node->parent = this; + + node->next = beforeThis; + node->prev = beforeThis->prev; + if ( beforeThis->prev ) + { + beforeThis->prev->next = node; + } + else + { + assert( firstChild == beforeThis ); + firstChild = node; + } + beforeThis->prev = node; + return node; +} + + +_TiXmlNode* _TiXmlNode::InsertAfterChild( _TiXmlNode* afterThis, const _TiXmlNode& addThis ) +{ + if ( !afterThis || afterThis->parent != this ) { + return 0; + } + if ( addThis.Type() == _TiXmlNode::TINYXML_DOCUMENT ) + { + if ( GetDocument() ) + GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + _TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + node->parent = this; + + node->prev = afterThis; + node->next = afterThis->next; + if ( afterThis->next ) + { + afterThis->next->prev = node; + } + else + { + assert( lastChild == afterThis ); + lastChild = node; + } + afterThis->next = node; + return node; +} + + +_TiXmlNode* _TiXmlNode::ReplaceChild( _TiXmlNode* replaceThis, const _TiXmlNode& withThis ) +{ + if ( !replaceThis ) + return 0; + + if ( replaceThis->parent != this ) + return 0; + + if ( withThis.ToDocument() ) { + // A document can never be a child. Thanks to Noam. + _TiXmlDocument* document = GetDocument(); + if ( document ) + document->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + _TiXmlNode* node = withThis.Clone(); + if ( !node ) + return 0; + + node->next = replaceThis->next; + node->prev = replaceThis->prev; + + if ( replaceThis->next ) + replaceThis->next->prev = node; + else + lastChild = node; + + if ( replaceThis->prev ) + replaceThis->prev->next = node; + else + firstChild = node; + + delete replaceThis; + node->parent = this; + return node; +} + + +bool _TiXmlNode::RemoveChild( _TiXmlNode* removeThis ) +{ + if ( !removeThis ) { + return false; + } + + if ( removeThis->parent != this ) + { + assert( 0 ); + return false; + } + + if ( removeThis->next ) + removeThis->next->prev = removeThis->prev; + else + lastChild = removeThis->prev; + + if ( removeThis->prev ) + removeThis->prev->next = removeThis->next; + else + firstChild = removeThis->next; + + delete removeThis; + return true; +} + +const _TiXmlNode* _TiXmlNode::FirstChild( const char * _value ) const +{ + const _TiXmlNode* node; + for ( node = firstChild; node; node = node->next ) + { + if ( strcmp( node->Value(), _value ) == 0 ) + return node; + } + return 0; +} + + +const _TiXmlNode* _TiXmlNode::LastChild( const char * _value ) const +{ + const _TiXmlNode* node; + for ( node = lastChild; node; node = node->prev ) + { + if ( strcmp( node->Value(), _value ) == 0 ) + return node; + } + return 0; +} + + +const _TiXmlNode* _TiXmlNode::IterateChildren( const _TiXmlNode* previous ) const +{ + if ( !previous ) + { + return FirstChild(); + } + else + { + assert( previous->parent == this ); + return previous->NextSibling(); + } +} + + +const _TiXmlNode* _TiXmlNode::IterateChildren( const char * val, const _TiXmlNode* previous ) const +{ + if ( !previous ) + { + return FirstChild( val ); + } + else + { + assert( previous->parent == this ); + return previous->NextSibling( val ); + } +} + + +const _TiXmlNode* _TiXmlNode::NextSibling( const char * _value ) const +{ + const _TiXmlNode* node; + for ( node = next; node; node = node->next ) + { + if ( strcmp( node->Value(), _value ) == 0 ) + return node; + } + return 0; +} + + +const _TiXmlNode* _TiXmlNode::PreviousSibling( const char * _value ) const +{ + const _TiXmlNode* node; + for ( node = prev; node; node = node->prev ) + { + if ( strcmp( node->Value(), _value ) == 0 ) + return node; + } + return 0; +} + + +void _TiXmlElement::RemoveAttribute( const char * name ) +{ + #ifdef TIXML_USE_STL + TIXML_STRING str( name ); + _TiXmlAttribute* node = attributeSet.Find( str ); + #else + _TiXmlAttribute* node = attributeSet.Find( name ); + #endif + if ( node ) + { + attributeSet.Remove( node ); + delete node; + } +} + +const _TiXmlElement* _TiXmlNode::FirstChildElement() const +{ + const _TiXmlNode* node; + + for ( node = FirstChild(); + node; + node = node->NextSibling() ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +const _TiXmlElement* _TiXmlNode::FirstChildElement( const char * _value ) const +{ + const _TiXmlNode* node; + + for ( node = FirstChild( _value ); + node; + node = node->NextSibling( _value ) ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +const _TiXmlElement* _TiXmlNode::NextSiblingElement() const +{ + const _TiXmlNode* node; + + for ( node = NextSibling(); + node; + node = node->NextSibling() ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +const _TiXmlElement* _TiXmlNode::NextSiblingElement( const char * _value ) const +{ + const _TiXmlNode* node; + + for ( node = NextSibling( _value ); + node; + node = node->NextSibling( _value ) ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +const _TiXmlDocument* _TiXmlNode::GetDocument() const +{ + const _TiXmlNode* node; + + for( node = this; node; node = node->parent ) + { + if ( node->ToDocument() ) + return node->ToDocument(); + } + return 0; +} + + +_TiXmlElement::_TiXmlElement (const char * _value) + : _TiXmlNode( _TiXmlNode::TINYXML_ELEMENT ) +{ + firstChild = lastChild = 0; + value = _value; +} + + +#ifdef TIXML_USE_STL +_TiXmlElement::_TiXmlElement( const std::string& _value ) + : _TiXmlNode( _TiXmlNode::TINYXML_ELEMENT ) +{ + firstChild = lastChild = 0; + value = _value; +} +#endif + + +_TiXmlElement::_TiXmlElement( const _TiXmlElement& copy) + : _TiXmlNode( _TiXmlNode::TINYXML_ELEMENT ) +{ + firstChild = lastChild = 0; + copy.CopyTo( this ); +} + + +_TiXmlElement& _TiXmlElement::operator=( const _TiXmlElement& base ) +{ + ClearThis(); + base.CopyTo( this ); + return *this; +} + + +_TiXmlElement::~_TiXmlElement() +{ + ClearThis(); +} + + +void _TiXmlElement::ClearThis() +{ + Clear(); + while( attributeSet.First() ) + { + _TiXmlAttribute* node = attributeSet.First(); + attributeSet.Remove( node ); + delete node; + } +} + + +const char* _TiXmlElement::Attribute( const char* name ) const +{ + const _TiXmlAttribute* node = attributeSet.Find( name ); + if ( node ) + return node->Value(); + return 0; +} + + +#ifdef TIXML_USE_STL +const std::string* _TiXmlElement::Attribute( const std::string& name ) const +{ + const _TiXmlAttribute* attrib = attributeSet.Find( name ); + if ( attrib ) + return &attrib->ValueStr(); + return 0; +} +#endif + + +const char* _TiXmlElement::Attribute( const char* name, int* i ) const +{ + const _TiXmlAttribute* attrib = attributeSet.Find( name ); + const char* result = 0; + + if ( attrib ) { + result = attrib->Value(); + if ( i ) { + attrib->QueryIntValue( i ); + } + } + return result; +} + + +#ifdef TIXML_USE_STL +const std::string* _TiXmlElement::Attribute( const std::string& name, int* i ) const +{ + const _TiXmlAttribute* attrib = attributeSet.Find( name ); + const std::string* result = 0; + + if ( attrib ) { + result = &attrib->ValueStr(); + if ( i ) { + attrib->QueryIntValue( i ); + } + } + return result; +} +#endif + + +const char* _TiXmlElement::Attribute( const char* name, double* d ) const +{ + const _TiXmlAttribute* attrib = attributeSet.Find( name ); + const char* result = 0; + + if ( attrib ) { + result = attrib->Value(); + if ( d ) { + attrib->QueryDoubleValue( d ); + } + } + return result; +} + + +#ifdef TIXML_USE_STL +const std::string* _TiXmlElement::Attribute( const std::string& name, double* d ) const +{ + const _TiXmlAttribute* attrib = attributeSet.Find( name ); + const std::string* result = 0; + + if ( attrib ) { + result = &attrib->ValueStr(); + if ( d ) { + attrib->QueryDoubleValue( d ); + } + } + return result; +} +#endif + + +int _TiXmlElement::QueryIntAttribute( const char* name, int* ival ) const +{ + const _TiXmlAttribute* attrib = attributeSet.Find( name ); + if ( !attrib ) + return TIXML_NO_ATTRIBUTE; + return attrib->QueryIntValue( ival ); +} + + +int _TiXmlElement::QueryUnsignedAttribute( const char* name, unsigned* pvalue ) const +{ + const _TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + + int ival = 0; + int result = node->QueryIntValue( &ival ); + *pvalue = (unsigned)ival; + return result; +} + + +int _TiXmlElement::QueryBoolAttribute( const char* name, bool* bval ) const +{ + const _TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + + int result = TIXML_WRONG_TYPE; + if ( StringEqual( node->Value(), "true", true, TIXML_ENCODING_UNKNOWN ) + || StringEqual( node->Value(), "yes", true, TIXML_ENCODING_UNKNOWN ) + || StringEqual( node->Value(), "1", true, TIXML_ENCODING_UNKNOWN ) ) + { + *bval = true; + result = TIXML_SUCCESS; + } + else if ( StringEqual( node->Value(), "false", true, TIXML_ENCODING_UNKNOWN ) + || StringEqual( node->Value(), "no", true, TIXML_ENCODING_UNKNOWN ) + || StringEqual( node->Value(), "0", true, TIXML_ENCODING_UNKNOWN ) ) + { + *bval = false; + result = TIXML_SUCCESS; + } + return result; +} + + + +#ifdef TIXML_USE_STL +int _TiXmlElement::QueryIntAttribute( const std::string& name, int* ival ) const +{ + const _TiXmlAttribute* attrib = attributeSet.Find( name ); + if ( !attrib ) + return TIXML_NO_ATTRIBUTE; + return attrib->QueryIntValue( ival ); +} +#endif + + +int _TiXmlElement::QueryDoubleAttribute( const char* name, double* dval ) const +{ + const _TiXmlAttribute* attrib = attributeSet.Find( name ); + if ( !attrib ) + return TIXML_NO_ATTRIBUTE; + return attrib->QueryDoubleValue( dval ); +} + + +#ifdef TIXML_USE_STL +int _TiXmlElement::QueryDoubleAttribute( const std::string& name, double* dval ) const +{ + const _TiXmlAttribute* attrib = attributeSet.Find( name ); + if ( !attrib ) + return TIXML_NO_ATTRIBUTE; + return attrib->QueryDoubleValue( dval ); +} +#endif + + +void _TiXmlElement::SetAttribute( const char * name, int val ) +{ + _TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); + if ( attrib ) { + attrib->SetIntValue( val ); + } +} + + +#ifdef TIXML_USE_STL +void _TiXmlElement::SetAttribute( const std::string& name, int val ) +{ + _TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); + if ( attrib ) { + attrib->SetIntValue( val ); + } +} +#endif + + +void _TiXmlElement::SetDoubleAttribute( const char * name, double val ) +{ + _TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); + if ( attrib ) { + attrib->SetDoubleValue( val ); + } +} + + +#ifdef TIXML_USE_STL +void _TiXmlElement::SetDoubleAttribute( const std::string& name, double val ) +{ + _TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); + if ( attrib ) { + attrib->SetDoubleValue( val ); + } +} +#endif + + +void _TiXmlElement::SetAttribute( const char * cname, const char * cvalue ) +{ + _TiXmlAttribute* attrib = attributeSet.FindOrCreate( cname ); + if ( attrib ) { + attrib->SetValue( cvalue ); + } +} + + +#ifdef TIXML_USE_STL +void _TiXmlElement::SetAttribute( const std::string& _name, const std::string& _value ) +{ + _TiXmlAttribute* attrib = attributeSet.FindOrCreate( _name ); + if ( attrib ) { + attrib->SetValue( _value ); + } +} +#endif + + +void _TiXmlElement::Print( FILE* cfile, int depth ) const +{ + int i; + assert( cfile ); + for ( i=0; iNext() ) + { + fprintf( cfile, " " ); + attrib->Print( cfile, depth ); + } + + // There are 3 different formatting approaches: + // 1) An element without children is printed as a node + // 2) An element with only a text child is printed as text + // 3) An element with children is printed on multiple lines. + _TiXmlNode* node; + if ( !firstChild ) + { + fprintf( cfile, " />" ); + } + else if ( firstChild == lastChild && firstChild->ToText() ) + { + fprintf( cfile, ">" ); + firstChild->Print( cfile, depth + 1 ); + fprintf( cfile, "", value.c_str() ); + } + else + { + fprintf( cfile, ">" ); + + for ( node = firstChild; node; node=node->NextSibling() ) + { + if ( !node->ToText() ) + { + fprintf( cfile, "\n" ); + } + node->Print( cfile, depth+1 ); + } + fprintf( cfile, "\n" ); + for( i=0; i", value.c_str() ); + } +} + + +void _TiXmlElement::CopyTo( _TiXmlElement* target ) const +{ + // superclass: + _TiXmlNode::CopyTo( target ); + + // Element class: + // Clone the attributes, then clone the children. + const _TiXmlAttribute* attribute = 0; + for( attribute = attributeSet.First(); + attribute; + attribute = attribute->Next() ) + { + target->SetAttribute( attribute->Name(), attribute->Value() ); + } + + _TiXmlNode* node = 0; + for ( node = firstChild; node; node = node->NextSibling() ) + { + target->LinkEndChild( node->Clone() ); + } +} + +bool _TiXmlElement::Accept( _TiXmlVisitor* visitor ) const +{ + if ( visitor->VisitEnter( *this, attributeSet.First() ) ) + { + for ( const _TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) + { + if ( !node->Accept( visitor ) ) + break; + } + } + return visitor->VisitExit( *this ); +} + + +_TiXmlNode* _TiXmlElement::Clone() const +{ + _TiXmlElement* clone = new _TiXmlElement( Value() ); + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +const char* _TiXmlElement::GetText() const +{ + const _TiXmlNode* child = this->FirstChild(); + if ( child ) { + const _TiXmlText* childText = child->ToText(); + if ( childText ) { + return childText->Value(); + } + } + return 0; +} + + +_TiXmlDocument::_TiXmlDocument() : _TiXmlNode( _TiXmlNode::TINYXML_DOCUMENT ) +{ + tabsize = 4; + useMicrosoftBOM = false; + ClearError(); +} + +_TiXmlDocument::_TiXmlDocument( const char * documentName ) : _TiXmlNode( _TiXmlNode::TINYXML_DOCUMENT ) +{ + tabsize = 4; + useMicrosoftBOM = false; + value = documentName; + ClearError(); +} + + +#ifdef TIXML_USE_STL +_TiXmlDocument::_TiXmlDocument( const std::string& documentName ) : _TiXmlNode( _TiXmlNode::TINYXML_DOCUMENT ) +{ + tabsize = 4; + useMicrosoftBOM = false; + value = documentName; + ClearError(); +} +#endif + + +_TiXmlDocument::_TiXmlDocument( const _TiXmlDocument& copy ) : _TiXmlNode( _TiXmlNode::TINYXML_DOCUMENT ) +{ + copy.CopyTo( this ); +} + + +_TiXmlDocument& _TiXmlDocument::operator=( const _TiXmlDocument& copy ) +{ + Clear(); + copy.CopyTo( this ); + return *this; +} + + +bool _TiXmlDocument::LoadFile( _TiXmlEncoding encoding ) +{ + return LoadFile( Value(), encoding ); +} + + +bool _TiXmlDocument::SaveFile() const +{ + return SaveFile( Value() ); +} + +bool _TiXmlDocument::LoadFile( const char* _filename, _TiXmlEncoding encoding ) +{ + TIXML_STRING filename( _filename ); + value = filename; + + // reading in binary mode so that tinyxml can normalize the EOL + FILE* file = TiXmlFOpen( value.c_str (), "rb" ); + + if ( file ) + { + bool result = LoadFile( file, encoding ); + fclose( file ); + return result; + } + else + { + SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); + return false; + } +} + +bool _TiXmlDocument::LoadFile( FILE* file, _TiXmlEncoding encoding ) +{ + if ( !file ) + { + SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); + return false; + } + + // Delete the existing data: + Clear(); + location.Clear(); + + // Get the file size, so we can pre-allocate the string. HUGE speed impact. + long length = 0; + fseek( file, 0, SEEK_END ); + length = ftell( file ); + fseek( file, 0, SEEK_SET ); + + // Strange case, but good to handle up front. + if ( length <= 0 ) + { + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return false; + } + + // Subtle bug here. TinyXml did use fgets. But from the XML spec: + // 2.11 End-of-Line Handling + // + // + // ...the XML processor MUST behave as if it normalized all line breaks in external + // parsed entities (including the document entity) on input, before parsing, by translating + // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to + // a single #xA character. + // + // + // It is not clear fgets does that, and certainly isn't clear it works cross platform. + // Generally, you expect fgets to translate from the convention of the OS to the c/unix + // convention, and not work generally. + + /* + while( fgets( buf, sizeof(buf), file ) ) + { + data += buf; + } + */ + + char* buf = new char[ length+1 ]; + buf[0] = 0; + + if ( fread( buf, length, 1, file ) != 1 ) { + delete [] buf; + SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); + return false; + } + + // Process the buffer in place to normalize new lines. (See comment above.) + // Copies from the 'p' to 'q' pointer, where p can advance faster if + // a newline-carriage return is hit. + // + // Wikipedia: + // Systems based on ASCII or a compatible character set use either LF (Line feed, '\n', 0x0A, 10 in decimal) or + // CR (Carriage return, '\r', 0x0D, 13 in decimal) individually, or CR followed by LF (CR+LF, 0x0D 0x0A)... + // * LF: Multics, Unix and Unix-like systems (GNU/Linux, AIX, Xenix, Mac OS X, FreeBSD, etc.), BeOS, Amiga, RISC OS, and others + // * CR+LF: DEC RT-11 and most other early non-Unix, non-IBM OSes, CP/M, MP/M, DOS, OS/2, Microsoft Windows, Symbian OS + // * CR: Commodore 8-bit machines, Apple II family, Mac OS up to version 9 and OS-9 + + const char* p = buf; // the read head + char* q = buf; // the write head + const char CR = 0x0d; + const char LF = 0x0a; + + buf[length] = 0; + while( *p ) { + assert( p < (buf+length) ); + assert( q <= (buf+length) ); + assert( q <= p ); + + if ( *p == CR ) { + *q++ = LF; + p++; + if ( *p == LF ) { // check for CR+LF (and skip LF) + p++; + } + } + else { + *q++ = *p++; + } + } + assert( q <= (buf+length) ); + *q = 0; + + Parse( buf, 0, encoding ); + + delete [] buf; + return !Error(); +} + + +bool _TiXmlDocument::SaveFile( const char * filename ) const +{ + // The old c stuff lives on... + FILE* fp = TiXmlFOpen( filename, "w" ); + if ( fp ) + { + bool result = SaveFile( fp ); + fclose( fp ); + return result; + } + return false; +} + + +bool _TiXmlDocument::SaveFile( FILE* fp ) const +{ + if ( useMicrosoftBOM ) + { + const unsigned char TIXML_UTF_LEAD_0 = 0xefU; + const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; + const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; + + fputc( TIXML_UTF_LEAD_0, fp ); + fputc( TIXML_UTF_LEAD_1, fp ); + fputc( TIXML_UTF_LEAD_2, fp ); + } + Print( fp, 0 ); + return (ferror(fp) == 0); +} + + +void _TiXmlDocument::CopyTo( _TiXmlDocument* target ) const +{ + _TiXmlNode::CopyTo( target ); + + target->error = error; + target->errorId = errorId; + target->errorDesc = errorDesc; + target->tabsize = tabsize; + target->errorLocation = errorLocation; + target->useMicrosoftBOM = useMicrosoftBOM; + + _TiXmlNode* node = 0; + for ( node = firstChild; node; node = node->NextSibling() ) + { + target->LinkEndChild( node->Clone() ); + } +} + + +_TiXmlNode* _TiXmlDocument::Clone() const +{ + _TiXmlDocument* clone = new _TiXmlDocument(); + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +void _TiXmlDocument::Print( FILE* cfile, int depth ) const +{ + assert( cfile ); + for ( const _TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) + { + node->Print( cfile, depth ); + fprintf( cfile, "\n" ); + } +} + + +bool _TiXmlDocument::Accept( _TiXmlVisitor* visitor ) const +{ + if ( visitor->VisitEnter( *this ) ) + { + for ( const _TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) + { + if ( !node->Accept( visitor ) ) + break; + } + } + return visitor->VisitExit( *this ); +} + + +const _TiXmlAttribute* _TiXmlAttribute::Next() const +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( next->value.empty() && next->name.empty() ) + return 0; + return next; +} + +/* +TiXmlAttribute* TiXmlAttribute::Next() +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( next->value.empty() && next->name.empty() ) + return 0; + return next; +} +*/ + +const _TiXmlAttribute* _TiXmlAttribute::Previous() const +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( prev->value.empty() && prev->name.empty() ) + return 0; + return prev; +} + +/* +TiXmlAttribute* TiXmlAttribute::Previous() +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( prev->value.empty() && prev->name.empty() ) + return 0; + return prev; +} +*/ + +void _TiXmlAttribute::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const +{ + TIXML_STRING n, v; + + EncodeString( name, &n ); + EncodeString( value, &v ); + + if (value.find ('\"') == TIXML_STRING::npos) { + if ( cfile ) { + fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() ); + } + if ( str ) { + (*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\""; + } + } + else { + if ( cfile ) { + fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() ); + } + if ( str ) { + (*str) += n; (*str) += "='"; (*str) += v; (*str) += "'"; + } + } +} + + +int _TiXmlAttribute::QueryIntValue( int* ival ) const +{ + if ( TIXML_SSCANF( value.c_str(), "%d", ival ) == 1 ) + return TIXML_SUCCESS; + return TIXML_WRONG_TYPE; +} + +int _TiXmlAttribute::QueryDoubleValue( double* dval ) const +{ + if ( TIXML_SSCANF( value.c_str(), "%lf", dval ) == 1 ) + return TIXML_SUCCESS; + return TIXML_WRONG_TYPE; +} + +void _TiXmlAttribute::SetIntValue( int _value ) +{ + char buf [64]; + #if defined(TIXML_SNPRINTF) + TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value); + #else + sprintf (buf, "%d", _value); + #endif + SetValue (buf); +} + +void _TiXmlAttribute::SetDoubleValue( double _value ) +{ + char buf [256]; + #if defined(TIXML_SNPRINTF) + TIXML_SNPRINTF( buf, sizeof(buf), "%g", _value); + #else + sprintf (buf, "%g", _value); + #endif + SetValue (buf); +} + +int _TiXmlAttribute::IntValue() const +{ + return atoi (value.c_str ()); +} + +double _TiXmlAttribute::DoubleValue() const +{ + return atof (value.c_str ()); +} + + +_TiXmlComment::_TiXmlComment( const _TiXmlComment& copy ) : _TiXmlNode( _TiXmlNode::TINYXML_COMMENT ) +{ + copy.CopyTo( this ); +} + + +_TiXmlComment& _TiXmlComment::operator=( const _TiXmlComment& base ) +{ + Clear(); + base.CopyTo( this ); + return *this; +} + + +void _TiXmlComment::Print( FILE* cfile, int depth ) const +{ + assert( cfile ); + for ( int i=0; i", value.c_str() ); +} + + +void _TiXmlComment::CopyTo( _TiXmlComment* target ) const +{ + _TiXmlNode::CopyTo( target ); +} + + +bool _TiXmlComment::Accept( _TiXmlVisitor* visitor ) const +{ + return visitor->Visit( *this ); +} + + +_TiXmlNode* _TiXmlComment::Clone() const +{ + _TiXmlComment* clone = new _TiXmlComment(); + + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +void _TiXmlText::Print( FILE* cfile, int depth ) const +{ + assert( cfile ); + if ( cdata ) + { + int i; + fprintf( cfile, "\n" ); + for ( i=0; i\n", value.c_str() ); // unformatted output + } + else + { + TIXML_STRING buffer; + EncodeString( value, &buffer ); + fprintf( cfile, "%s", buffer.c_str() ); + } +} + + +void _TiXmlText::CopyTo( _TiXmlText* target ) const +{ + _TiXmlNode::CopyTo( target ); + target->cdata = cdata; +} + + +bool _TiXmlText::Accept( _TiXmlVisitor* visitor ) const +{ + return visitor->Visit( *this ); +} + + +_TiXmlNode* _TiXmlText::Clone() const +{ + _TiXmlText* clone = 0; + clone = new _TiXmlText( "" ); + + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +_TiXmlDeclaration::_TiXmlDeclaration( const char * _version, + const char * _encoding, + const char * _standalone ) + : _TiXmlNode( _TiXmlNode::TINYXML_DECLARATION ) +{ + version = _version; + encoding = _encoding; + standalone = _standalone; +} + + +#ifdef TIXML_USE_STL +_TiXmlDeclaration::_TiXmlDeclaration( const std::string& _version, + const std::string& _encoding, + const std::string& _standalone ) + : _TiXmlNode( _TiXmlNode::TINYXML_DECLARATION ) +{ + version = _version; + encoding = _encoding; + standalone = _standalone; +} +#endif + + +_TiXmlDeclaration::_TiXmlDeclaration( const _TiXmlDeclaration& copy ) + : _TiXmlNode( _TiXmlNode::TINYXML_DECLARATION ) +{ + copy.CopyTo( this ); +} + + +_TiXmlDeclaration& _TiXmlDeclaration::operator=( const _TiXmlDeclaration& copy ) +{ + Clear(); + copy.CopyTo( this ); + return *this; +} + + +void _TiXmlDeclaration::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const +{ + if ( cfile ) fprintf( cfile, "" ); + if ( str ) (*str) += "?>"; +} + + +void _TiXmlDeclaration::CopyTo( _TiXmlDeclaration* target ) const +{ + _TiXmlNode::CopyTo( target ); + + target->version = version; + target->encoding = encoding; + target->standalone = standalone; +} + + +bool _TiXmlDeclaration::Accept( _TiXmlVisitor* visitor ) const +{ + return visitor->Visit( *this ); +} + + +_TiXmlNode* _TiXmlDeclaration::Clone() const +{ + _TiXmlDeclaration* clone = new _TiXmlDeclaration(); + + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +void _TiXmlUnknown::Print( FILE* cfile, int depth ) const +{ + for ( int i=0; i", value.c_str() ); +} + + +void _TiXmlUnknown::CopyTo( _TiXmlUnknown* target ) const +{ + _TiXmlNode::CopyTo( target ); +} + + +bool _TiXmlUnknown::Accept( _TiXmlVisitor* visitor ) const +{ + return visitor->Visit( *this ); +} + + +_TiXmlNode* _TiXmlUnknown::Clone() const +{ + _TiXmlUnknown* clone = new _TiXmlUnknown(); + + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +_TiXmlAttributeSet::_TiXmlAttributeSet() +{ + sentinel.next = &sentinel; + sentinel.prev = &sentinel; +} + + +_TiXmlAttributeSet::~_TiXmlAttributeSet() +{ + assert( sentinel.next == &sentinel ); + assert( sentinel.prev == &sentinel ); +} + + +void _TiXmlAttributeSet::Add( _TiXmlAttribute* addMe ) +{ + #ifdef TIXML_USE_STL + assert( !Find( TIXML_STRING( addMe->Name() ) ) ); // Shouldn't be multiply adding to the set. + #else + assert( !Find( addMe->Name() ) ); // Shouldn't be multiply adding to the set. + #endif + + addMe->next = &sentinel; + addMe->prev = sentinel.prev; + + sentinel.prev->next = addMe; + sentinel.prev = addMe; +} + +void _TiXmlAttributeSet::Remove( _TiXmlAttribute* removeMe ) +{ + _TiXmlAttribute* node; + + for( node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( node == removeMe ) + { + node->prev->next = node->next; + node->next->prev = node->prev; + node->next = 0; + node->prev = 0; + return; + } + } + assert( 0 ); // we tried to remove a non-linked attribute. +} + + +#ifdef TIXML_USE_STL +_TiXmlAttribute* _TiXmlAttributeSet::Find( const std::string& name ) const +{ + for( _TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( node->name == name ) + return node; + } + return 0; +} + +_TiXmlAttribute* _TiXmlAttributeSet::FindOrCreate( const std::string& _name ) +{ + _TiXmlAttribute* attrib = Find( _name ); + if ( !attrib ) { + attrib = new _TiXmlAttribute(); + Add( attrib ); + attrib->SetName( _name ); + } + return attrib; +} +#endif + + +_TiXmlAttribute* _TiXmlAttributeSet::Find( const char* name ) const +{ + for( _TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( strcmp( node->name.c_str(), name ) == 0 ) + return node; + } + return 0; +} + + +_TiXmlAttribute* _TiXmlAttributeSet::FindOrCreate( const char* _name ) +{ + _TiXmlAttribute* attrib = Find( _name ); + if ( !attrib ) { + attrib = new _TiXmlAttribute(); + Add( attrib ); + attrib->SetName( _name ); + } + return attrib; +} + + +#ifdef TIXML_USE_STL +std::istream& operator>> (std::istream & in, _TiXmlNode & base) +{ + TIXML_STRING tag; + tag.reserve( 8 * 1000 ); + base.StreamIn( &in, &tag ); + + base.Parse( tag.c_str(), 0, TIXML_DEFAULT_ENCODING ); + return in; +} +#endif + + +#ifdef TIXML_USE_STL +std::ostream& operator<< (std::ostream & out, const _TiXmlNode & base) +{ + _TiXmlPrinter printer; + printer.SetStreamPrinting(); + base.Accept( &printer ); + out << printer.Str(); + + return out; +} + + +std::string& operator<< (std::string& out, const _TiXmlNode& base ) +{ + _TiXmlPrinter printer; + printer.SetStreamPrinting(); + base.Accept( &printer ); + out.append( printer.Str() ); + + return out; +} +#endif + + +_TiXmlHandle _TiXmlHandle::FirstChild() const +{ + if ( node ) + { + _TiXmlNode* child = node->FirstChild(); + if ( child ) + return _TiXmlHandle( child ); + } + return _TiXmlHandle( 0 ); +} + + +_TiXmlHandle _TiXmlHandle::FirstChild( const char * value ) const +{ + if ( node ) + { + _TiXmlNode* child = node->FirstChild( value ); + if ( child ) + return _TiXmlHandle( child ); + } + return _TiXmlHandle( 0 ); +} + + +_TiXmlHandle _TiXmlHandle::FirstChildElement() const +{ + if ( node ) + { + _TiXmlElement* child = node->FirstChildElement(); + if ( child ) + return _TiXmlHandle( child ); + } + return _TiXmlHandle( 0 ); +} + + +_TiXmlHandle _TiXmlHandle::FirstChildElement( const char * value ) const +{ + if ( node ) + { + _TiXmlElement* child = node->FirstChildElement( value ); + if ( child ) + return _TiXmlHandle( child ); + } + return _TiXmlHandle( 0 ); +} + + +_TiXmlHandle _TiXmlHandle::Child( int count ) const +{ + if ( node ) + { + int i; + _TiXmlNode* child = node->FirstChild(); + for ( i=0; + child && iNextSibling(), ++i ) + { + // nothing + } + if ( child ) + return _TiXmlHandle( child ); + } + return _TiXmlHandle( 0 ); +} + + +_TiXmlHandle _TiXmlHandle::Child( const char* value, int count ) const +{ + if ( node ) + { + int i; + _TiXmlNode* child = node->FirstChild( value ); + for ( i=0; + child && iNextSibling( value ), ++i ) + { + // nothing + } + if ( child ) + return _TiXmlHandle( child ); + } + return _TiXmlHandle( 0 ); +} + + +_TiXmlHandle _TiXmlHandle::ChildElement( int count ) const +{ + if ( node ) + { + int i; + _TiXmlElement* child = node->FirstChildElement(); + for ( i=0; + child && iNextSiblingElement(), ++i ) + { + // nothing + } + if ( child ) + return _TiXmlHandle( child ); + } + return _TiXmlHandle( 0 ); +} + + +_TiXmlHandle _TiXmlHandle::ChildElement( const char* value, int count ) const +{ + if ( node ) + { + int i; + _TiXmlElement* child = node->FirstChildElement( value ); + for ( i=0; + child && iNextSiblingElement( value ), ++i ) + { + // nothing + } + if ( child ) + return _TiXmlHandle( child ); + } + return _TiXmlHandle( 0 ); +} + + +bool _TiXmlPrinter::VisitEnter( const _TiXmlDocument& ) +{ + return true; +} + +bool _TiXmlPrinter::VisitExit( const _TiXmlDocument& ) +{ + return true; +} + +bool _TiXmlPrinter::VisitEnter( const _TiXmlElement& element, const _TiXmlAttribute* firstAttribute ) +{ + DoIndent(); + buffer += "<"; + buffer += element.Value(); + + for( const _TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() ) + { + buffer += " "; + attrib->Print( 0, 0, &buffer ); + } + + if ( !element.FirstChild() ) + { + buffer += " />"; + DoLineBreak(); + } + else + { + buffer += ">"; + if ( element.FirstChild()->ToText() + && element.LastChild() == element.FirstChild() + && element.FirstChild()->ToText()->CDATA() == false ) + { + simpleTextPrint = true; + // no DoLineBreak()! + } + else + { + DoLineBreak(); + } + } + ++depth; + return true; +} + + +bool _TiXmlPrinter::VisitExit( const _TiXmlElement& element ) +{ + --depth; + if ( !element.FirstChild() ) + { + // nothing. + } + else + { + if ( simpleTextPrint ) + { + simpleTextPrint = false; + } + else + { + DoIndent(); + } + buffer += ""; + DoLineBreak(); + } + return true; +} + + +bool _TiXmlPrinter::Visit( const _TiXmlText& text ) +{ + if ( text.CDATA() ) + { + DoIndent(); + buffer += ""; + DoLineBreak(); + } + else if ( simpleTextPrint ) + { + TIXML_STRING str; + _TiXmlBase::EncodeString( text.ValueTStr(), &str ); + buffer += str; + } + else + { + DoIndent(); + TIXML_STRING str; + _TiXmlBase::EncodeString( text.ValueTStr(), &str ); + buffer += str; + DoLineBreak(); + } + return true; +} + + +bool _TiXmlPrinter::Visit( const _TiXmlDeclaration& declaration ) +{ + DoIndent(); + declaration.Print( 0, 0, &buffer ); + DoLineBreak(); + return true; +} + + +bool _TiXmlPrinter::Visit( const _TiXmlComment& comment ) +{ + DoIndent(); + buffer += ""; + DoLineBreak(); + return true; +} + + +bool _TiXmlPrinter::Visit( const _TiXmlUnknown& unknown ) +{ + DoIndent(); + buffer += "<"; + buffer += unknown.Value(); + buffer += ">"; + DoLineBreak(); + return true; +} + diff --git a/exchange/exchangesource/PRC2XML/TinyXML/tinyxml.h b/exchange/exchangesource/PRC2XML/TinyXML/tinyxml.h new file mode 100644 index 0000000..1920dc0 --- /dev/null +++ b/exchange/exchangesource/PRC2XML/TinyXML/tinyxml.h @@ -0,0 +1,1805 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code by Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + + +#ifndef TINYXML_INCLUDED +#define TINYXML_INCLUDED + +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable : 4530 ) +#pragma warning( disable : 4786 ) +#endif + +#include +#include +#include +#include +#include + +// Help out windows: +#if defined( _DEBUG ) && !defined( DEBUG ) +#define DEBUG +#endif + +#ifdef TIXML_USE_STL + #include + #include + #include + #define TIXML_STRING std::string +#else + #include "tinystr.h" + #define TIXML_STRING _TiXmlString +#endif + +// Deprecated library function hell. Compilers want to use the +// new safe versions. This probably doesn't fully address the problem, +// but it gets closer. There are too many compilers for me to fully +// test. If you get compilation troubles, undefine TIXML_SAFE +#define TIXML_SAFE + +#ifdef TIXML_SAFE + #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) + // Microsoft visual studio, version 2005 and higher. + #define TIXML_SNPRINTF _snprintf_s + #define TIXML_SSCANF sscanf_s + #elif defined(_MSC_VER) && (_MSC_VER >= 1200 ) + // Microsoft visual studio, version 6 and higher. + //#pragma message( "Using _sn* functions." ) + #define TIXML_SNPRINTF _snprintf + #define TIXML_SSCANF sscanf + #elif defined(__GNUC__) && (__GNUC__ >= 3 ) + // GCC version 3 and higher.s + //#warning( "Using sn* functions." ) + #define TIXML_SNPRINTF snprintf + #define TIXML_SSCANF sscanf + #else + #define TIXML_SNPRINTF snprintf + #define TIXML_SSCANF sscanf + #endif +#endif + +class _TiXmlDocument; +class _TiXmlElement; +class _TiXmlComment; +class _TiXmlUnknown; +class _TiXmlAttribute; +class _TiXmlText; +class _TiXmlDeclaration; +class _TiXmlParsingData; + +const int TIXML_MAJOR_VERSION = 2; +const int TIXML_MINOR_VERSION = 6; +const int TIXML_PATCH_VERSION = 2; + +/* Internal structure for tracking location of items + in the XML file. +*/ +struct _TiXmlCursor +{ + _TiXmlCursor() { Clear(); } + void Clear() { row = col = -1; } + + int row; // 0 based. + int col; // 0 based. +}; + + +/** + Implements the interface to the "Visitor pattern" (see the Accept() method.) + If you call the Accept() method, it requires being passed a TiXmlVisitor + class to handle callbacks. For nodes that contain other nodes (Document, Element) + you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves + are simply called with Visit(). + + If you return 'true' from a Visit method, recursive parsing will continue. If you return + false, no children of this node or its sibilings will be Visited. + + All flavors of Visit methods have a default implementation that returns 'true' (continue + visiting). You need to only override methods that are interesting to you. + + Generally Accept() is called on the TiXmlDocument, although all nodes suppert Visiting. + + You should never change the document from a callback. + + @sa TiXmlNode::Accept() +*/ +class _TiXmlVisitor +{ +public: + virtual ~_TiXmlVisitor() {} + + /// Visit a document. + virtual bool VisitEnter( const _TiXmlDocument& /*doc*/ ) { return true; } + /// Visit a document. + virtual bool VisitExit( const _TiXmlDocument& /*doc*/ ) { return true; } + + /// Visit an element. + virtual bool VisitEnter( const _TiXmlElement& /*element*/, const _TiXmlAttribute* /*firstAttribute*/ ) { return true; } + /// Visit an element. + virtual bool VisitExit( const _TiXmlElement& /*element*/ ) { return true; } + + /// Visit a declaration + virtual bool Visit( const _TiXmlDeclaration& /*declaration*/ ) { return true; } + /// Visit a text node + virtual bool Visit( const _TiXmlText& /*text*/ ) { return true; } + /// Visit a comment node + virtual bool Visit( const _TiXmlComment& /*comment*/ ) { return true; } + /// Visit an unknown node + virtual bool Visit( const _TiXmlUnknown& /*unknown*/ ) { return true; } +}; + +// Only used by Attribute::Query functions +enum +{ + TIXML_SUCCESS, + TIXML_NO_ATTRIBUTE, + TIXML_WRONG_TYPE +}; + + +// Used by the parsing routines. +enum _TiXmlEncoding +{ + TIXML_ENCODING_UNKNOWN, + TIXML_ENCODING_UTF8, + TIXML_ENCODING_LEGACY +}; + +const _TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN; + +/** TiXmlBase is a base class for every class in TinyXml. + It does little except to establish that TinyXml classes + can be printed and provide some utility functions. + + In XML, the document and elements can contain + other elements and other types of nodes. + + @verbatim + A Document can contain: Element (container or leaf) + Comment (leaf) + Unknown (leaf) + Declaration( leaf ) + + An Element can contain: Element (container or leaf) + Text (leaf) + Attributes (not on tree) + Comment (leaf) + Unknown (leaf) + + A Decleration contains: Attributes (not on tree) + @endverbatim +*/ +class _TiXmlBase +{ + friend class _TiXmlNode; + friend class _TiXmlElement; + friend class _TiXmlDocument; + +public: + _TiXmlBase() : userData(0) {} + virtual ~_TiXmlBase() {} + + /** All TinyXml classes can print themselves to a filestream + or the string class (TiXmlString in non-STL mode, std::string + in STL mode.) Either or both cfile and str can be null. + + This is a formatted print, and will insert + tabs and newlines. + + (For an unformatted stream, use the << operator.) + */ + virtual void Print( FILE* cfile, int depth ) const = 0; + + /** The world does not agree on whether white space should be kept or + not. In order to make everyone happy, these global, static functions + are provided to set whether or not TinyXml will condense all white space + into a single space or not. The default is to condense. Note changing this + value is not thread safe. + */ + static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; } + + /// Return the current white space setting. + static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; } + + /** Return the position, in the original source file, of this node or attribute. + The row and column are 1-based. (That is the first row and first column is + 1,1). If the returns values are 0 or less, then the parser does not have + a row and column value. + + Generally, the row and column value will be set when the TiXmlDocument::Load(), + TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set + when the DOM was created from operator>>. + + The values reflect the initial load. Once the DOM is modified programmatically + (by adding or changing nodes and attributes) the new values will NOT update to + reflect changes in the document. + + There is a minor performance cost to computing the row and column. Computation + can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value. + + @sa TiXmlDocument::SetTabSize() + */ + int Row() const { return location.row + 1; } + int Column() const { return location.col + 1; } ///< See Row() + + void SetUserData( void* user ) { userData = user; } ///< Set a pointer to arbitrary user data. + void* GetUserData() { return userData; } ///< Get a pointer to arbitrary user data. + const void* GetUserData() const { return userData; } ///< Get a pointer to arbitrary user data. + + // Table that returs, for a given lead byte, the total number of bytes + // in the UTF-8 sequence. + static const int utf8ByteTable[256]; + + virtual const char* Parse( const char* p, + _TiXmlParsingData* data, + _TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0; + + /** Expands entities in a string. Note this should not contian the tag's '<', '>', etc, + or they will be transformed into entities! + */ + static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out ); + + enum + { + TIXML_NO_ERROR = 0, + TIXML_ERROR, + TIXML_ERROR_OPENING_FILE, + TIXML_ERROR_PARSING_ELEMENT, + TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, + TIXML_ERROR_READING_ELEMENT_VALUE, + TIXML_ERROR_READING_ATTRIBUTES, + TIXML_ERROR_PARSING_EMPTY, + TIXML_ERROR_READING_END_TAG, + TIXML_ERROR_PARSING_UNKNOWN, + TIXML_ERROR_PARSING_COMMENT, + TIXML_ERROR_PARSING_DECLARATION, + TIXML_ERROR_DOCUMENT_EMPTY, + TIXML_ERROR_EMBEDDED_NULL, + TIXML_ERROR_PARSING_CDATA, + TIXML_ERROR_DOCUMENT_TOP_ONLY, + + TIXML_ERROR_STRING_COUNT + }; + +protected: + + static const char* SkipWhiteSpace( const char*, _TiXmlEncoding encoding ); + + inline static bool IsWhiteSpace( char c ) + { + return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); + } + inline static bool IsWhiteSpace( int c ) + { + if ( c < 256 ) + return IsWhiteSpace( (char) c ); + return false; // Again, only truly correct for English/Latin...but usually works. + } + + #ifdef TIXML_USE_STL + static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag ); + static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag ); + #endif + + /* Reads an XML name into the string provided. Returns + a pointer just past the last character of the name, + or 0 if the function has an error. + */ + static const char* ReadName( const char* p, TIXML_STRING* name, _TiXmlEncoding encoding ); + + /* Reads text. Returns a pointer past the given end tag. + Wickedly complex options, but it keeps the (sensitive) code in one place. + */ + static const char* ReadText( const char* in, // where to start + TIXML_STRING* text, // the string read + bool ignoreWhiteSpace, // whether to keep the white space + const char* endTag, // what ends this text + bool ignoreCase, // whether to ignore case in the end tag + _TiXmlEncoding encoding ); // the current encoding + + // If an entity has been found, transform it into a character. + static const char* GetEntity( const char* in, char* value, int* length, _TiXmlEncoding encoding ); + + // Get a character, while interpreting entities. + // The length can be from 0 to 4 bytes. + inline static const char* GetChar( const char* p, char* _value, int* length, _TiXmlEncoding encoding ) + { + assert( p ); + if ( encoding == TIXML_ENCODING_UTF8 ) + { + *length = utf8ByteTable[ *((const unsigned char*)p) ]; + assert( *length >= 0 && *length < 5 ); + } + else + { + *length = 1; + } + + if ( *length == 1 ) + { + if ( *p == '&' ) + return GetEntity( p, _value, length, encoding ); + *_value = *p; + return p+1; + } + else if ( *length ) + { + //strncpy( _value, p, *length ); // lots of compilers don't like this function (unsafe), + // and the null terminator isn't needed + for( int i=0; p[i] && i<*length; ++i ) { + _value[i] = p[i]; + } + return p + (*length); + } + else + { + // Not valid text. + return 0; + } + } + + // Return true if the next characters in the stream are any of the endTag sequences. + // Ignore case only works for english, and should only be relied on when comparing + // to English words: StringEqual( p, "version", true ) is fine. + static bool StringEqual( const char* p, + const char* endTag, + bool ignoreCase, + _TiXmlEncoding encoding ); + + static const char* errorString[ TIXML_ERROR_STRING_COUNT ]; + + _TiXmlCursor location; + + /// Field containing a generic user pointer + void* userData; + + // None of these methods are reliable for any language except English. + // Good for approximation, not great for accuracy. + static int IsAlpha( unsigned char anyByte, _TiXmlEncoding encoding ); + static int IsAlphaNum( unsigned char anyByte, _TiXmlEncoding encoding ); + inline static int ToLower( int v, _TiXmlEncoding encoding ) + { + if ( encoding == TIXML_ENCODING_UTF8 ) + { + if ( v < 128 ) return tolower( v ); + return v; + } + else + { + return tolower( v ); + } + } + static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ); + +private: + _TiXmlBase( const _TiXmlBase& ); // not implemented. + void operator=( const _TiXmlBase& base ); // not allowed. + + struct Entity + { + const char* str; + unsigned int strLength; + char chr; + }; + enum + { + NUM_ENTITY = 5, + MAX_ENTITY_LENGTH = 6 + + }; + static Entity entity[ NUM_ENTITY ]; + static bool condenseWhiteSpace; +}; + + +/** The parent class for everything in the Document Object Model. + (Except for attributes). + Nodes have siblings, a parent, and children. A node can be + in a document, or stand on its own. The type of a TiXmlNode + can be queried, and it can be cast to its more defined type. +*/ +class _TiXmlNode : public _TiXmlBase +{ + friend class _TiXmlDocument; + friend class _TiXmlElement; + +public: + #ifdef TIXML_USE_STL + + /** An input stream operator, for every class. Tolerant of newlines and + formatting, but doesn't expect them. + */ + friend std::istream& operator >> (std::istream& in, _TiXmlNode& base); + + /** An output stream operator, for every class. Note that this outputs + without any newlines or formatting, as opposed to Print(), which + includes tabs and new lines. + + The operator<< and operator>> are not completely symmetric. Writing + a node to a stream is very well defined. You'll get a nice stream + of output, without any extra whitespace or newlines. + + But reading is not as well defined. (As it always is.) If you create + a TiXmlElement (for example) and read that from an input stream, + the text needs to define an element or junk will result. This is + true of all input streams, but it's worth keeping in mind. + + A TiXmlDocument will read nodes until it reads a root element, and + all the children of that root element. + */ + friend std::ostream& operator<< (std::ostream& out, const _TiXmlNode& base); + + /// Appends the XML node or attribute to a std::string. + friend std::string& operator<< (std::string& out, const _TiXmlNode& base ); + + #endif + + /** The types of XML nodes supported by TinyXml. (All the + unsupported types are picked up by UNKNOWN.) + */ + enum NodeType + { + TINYXML_DOCUMENT, + TINYXML_ELEMENT, + TINYXML_COMMENT, + TINYXML_UNKNOWN, + TINYXML_TEXT, + TINYXML_DECLARATION, + TINYXML_TYPECOUNT + }; + + virtual ~_TiXmlNode(); + + /** The meaning of 'value' changes for the specific type of + TiXmlNode. + @verbatim + Document: filename of the xml file + Element: name of the element + Comment: the comment text + Unknown: the tag contents + Text: the text string + @endverbatim + + The subclasses will wrap this function. + */ + const char *Value() const { return value.c_str (); } + + #ifdef TIXML_USE_STL + /** Return Value() as a std::string. If you only use STL, + this is more efficient than calling Value(). + Only available in STL mode. + */ + const std::string& ValueStr() const { return value; } + #endif + + const TIXML_STRING& ValueTStr() const { return value; } + + /** Changes the value of the node. Defined as: + @verbatim + Document: filename of the xml file + Element: name of the element + Comment: the comment text + Unknown: the tag contents + Text: the text string + @endverbatim + */ + void SetValue(const char * _value) { value = _value;} + + #ifdef TIXML_USE_STL + /// STL std::string form. + void SetValue( const std::string& _value ) { value = _value; } + #endif + + /// Delete all the children of this node. Does not affect 'this'. + void Clear(); + + /// One step up the DOM. + _TiXmlNode* Parent() { return parent; } + const _TiXmlNode* Parent() const { return parent; } + + const _TiXmlNode* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children. + _TiXmlNode* FirstChild() { return firstChild; } + const _TiXmlNode* FirstChild( const char * value ) const; ///< The first child of this node with the matching 'value'. Will be null if none found. + /// The first child of this node with the matching 'value'. Will be null if none found. + _TiXmlNode* FirstChild( const char * _value ) { + // Call through to the const version - safe since nothing is changed. Exiting syntax: cast this to a const (always safe) + // call the method, cast the return back to non-const. + return const_cast< _TiXmlNode* > ((const_cast< const _TiXmlNode* >(this))->FirstChild( _value )); + } + const _TiXmlNode* LastChild() const { return lastChild; } /// The last child of this node. Will be null if there are no children. + _TiXmlNode* LastChild() { return lastChild; } + + const _TiXmlNode* LastChild( const char * value ) const; /// The last child of this node matching 'value'. Will be null if there are no children. + _TiXmlNode* LastChild( const char * _value ) { + return const_cast< _TiXmlNode* > ((const_cast< const _TiXmlNode* >(this))->LastChild( _value )); + } + + #ifdef TIXML_USE_STL + const _TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); } ///< STL std::string form. + _TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); } ///< STL std::string form. + const _TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); } ///< STL std::string form. + _TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); } ///< STL std::string form. + #endif + + /** An alternate way to walk the children of a node. + One way to iterate over nodes is: + @verbatim + for( child = parent->FirstChild(); child; child = child->NextSibling() ) + @endverbatim + + IterateChildren does the same thing with the syntax: + @verbatim + child = 0; + while( child = parent->IterateChildren( child ) ) + @endverbatim + + IterateChildren takes the previous child as input and finds + the next one. If the previous child is null, it returns the + first. IterateChildren will return null when done. + */ + const _TiXmlNode* IterateChildren( const _TiXmlNode* previous ) const; + _TiXmlNode* IterateChildren( const _TiXmlNode* previous ) { + return const_cast< _TiXmlNode* >( (const_cast< const _TiXmlNode* >(this))->IterateChildren( previous ) ); + } + + /// This flavor of IterateChildren searches for children with a particular 'value' + const _TiXmlNode* IterateChildren( const char * value, const _TiXmlNode* previous ) const; + _TiXmlNode* IterateChildren( const char * _value, const _TiXmlNode* previous ) { + return const_cast< _TiXmlNode* >( (const_cast< const _TiXmlNode* >(this))->IterateChildren( _value, previous ) ); + } + + #ifdef TIXML_USE_STL + const _TiXmlNode* IterateChildren( const std::string& _value, const _TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. + _TiXmlNode* IterateChildren( const std::string& _value, const _TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. + #endif + + /** Add a new node related to this. Adds a child past the LastChild. + Returns a pointer to the new object or NULL if an error occured. + */ + _TiXmlNode* InsertEndChild( const _TiXmlNode& addThis ); + + + /** Add a new node related to this. Adds a child past the LastChild. + + NOTE: the node to be added is passed by pointer, and will be + henceforth owned (and deleted) by tinyXml. This method is efficient + and avoids an extra copy, but should be used with care as it + uses a different memory model than the other insert functions. + + @sa InsertEndChild + */ + _TiXmlNode* LinkEndChild( _TiXmlNode* addThis ); + + /** Add a new node related to this. Adds a child before the specified child. + Returns a pointer to the new object or NULL if an error occured. + */ + _TiXmlNode* InsertBeforeChild( _TiXmlNode* beforeThis, const _TiXmlNode& addThis ); + + /** Add a new node related to this. Adds a child after the specified child. + Returns a pointer to the new object or NULL if an error occured. + */ + _TiXmlNode* InsertAfterChild( _TiXmlNode* afterThis, const _TiXmlNode& addThis ); + + /** Replace a child of this node. + Returns a pointer to the new object or NULL if an error occured. + */ + _TiXmlNode* ReplaceChild( _TiXmlNode* replaceThis, const _TiXmlNode& withThis ); + + /// Delete a child of this node. + bool RemoveChild( _TiXmlNode* removeThis ); + + /// Navigate to a sibling node. + const _TiXmlNode* PreviousSibling() const { return prev; } + _TiXmlNode* PreviousSibling() { return prev; } + + /// Navigate to a sibling node. + const _TiXmlNode* PreviousSibling( const char * ) const; + _TiXmlNode* PreviousSibling( const char *_prev ) { + return const_cast< _TiXmlNode* >( (const_cast< const _TiXmlNode* >(this))->PreviousSibling( _prev ) ); + } + + #ifdef TIXML_USE_STL + const _TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. + _TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. + const _TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); } ///< STL std::string form. + _TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); } ///< STL std::string form. + #endif + + /// Navigate to a sibling node. + const _TiXmlNode* NextSibling() const { return next; } + _TiXmlNode* NextSibling() { return next; } + + /// Navigate to a sibling node with the given 'value'. + const _TiXmlNode* NextSibling( const char * ) const; + _TiXmlNode* NextSibling( const char* _next ) { + return const_cast< _TiXmlNode* >( (const_cast< const _TiXmlNode* >(this))->NextSibling( _next ) ); + } + + /** Convenience function to get through elements. + Calls NextSibling and ToElement. Will skip all non-Element + nodes. Returns 0 if there is not another element. + */ + const _TiXmlElement* NextSiblingElement() const; + _TiXmlElement* NextSiblingElement() { + return const_cast< _TiXmlElement* >( (const_cast< const _TiXmlNode* >(this))->NextSiblingElement() ); + } + + /** Convenience function to get through elements. + Calls NextSibling and ToElement. Will skip all non-Element + nodes. Returns 0 if there is not another element. + */ + const _TiXmlElement* NextSiblingElement( const char * ) const; + _TiXmlElement* NextSiblingElement( const char *_next ) { + return const_cast< _TiXmlElement* >( (const_cast< const _TiXmlNode* >(this))->NextSiblingElement( _next ) ); + } + + #ifdef TIXML_USE_STL + const _TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. + _TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. + #endif + + /// Convenience function to get through elements. + const _TiXmlElement* FirstChildElement() const; + _TiXmlElement* FirstChildElement() { + return const_cast< _TiXmlElement* >( (const_cast< const _TiXmlNode* >(this))->FirstChildElement() ); + } + + /// Convenience function to get through elements. + const _TiXmlElement* FirstChildElement( const char * _value ) const; + _TiXmlElement* FirstChildElement( const char * _value ) { + return const_cast< _TiXmlElement* >( (const_cast< const _TiXmlNode* >(this))->FirstChildElement( _value ) ); + } + + #ifdef TIXML_USE_STL + const _TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. + _TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. + #endif + + /** Query the type (as an enumerated value, above) of this node. + The possible types are: TINYXML_DOCUMENT, TINYXML_ELEMENT, TINYXML_COMMENT, + TINYXML_UNKNOWN, TINYXML_TEXT, and TINYXML_DECLARATION. + */ + int Type() const { return type; } + + /** Return a pointer to the Document this node lives in. + Returns null if not in a document. + */ + const _TiXmlDocument* GetDocument() const; + _TiXmlDocument* GetDocument() { + return const_cast< _TiXmlDocument* >( (const_cast< const _TiXmlNode* >(this))->GetDocument() ); + } + + /// Returns true if this node has no children. + bool NoChildren() const { return !firstChild; } + + virtual const _TiXmlDocument* ToDocument() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual const _TiXmlElement* ToElement() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual const _TiXmlComment* ToComment() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual const _TiXmlUnknown* ToUnknown() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual const _TiXmlText* ToText() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual const _TiXmlDeclaration* ToDeclaration() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + + virtual _TiXmlDocument* ToDocument() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual _TiXmlElement* ToElement() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual _TiXmlComment* ToComment() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual _TiXmlUnknown* ToUnknown() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual _TiXmlText* ToText() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual _TiXmlDeclaration* ToDeclaration() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + + /** Create an exact duplicate of this node and return it. The memory must be deleted + by the caller. + */ + virtual _TiXmlNode* Clone() const = 0; + + /** Accept a hierchical visit the nodes in the TinyXML DOM. Every node in the + XML tree will be conditionally visited and the host will be called back + via the TiXmlVisitor interface. + + This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse + the XML for the callbacks, so the performance of TinyXML is unchanged by using this + interface versus any other.) + + The interface has been based on ideas from: + + - http://www.saxproject.org/ + - http://c2.com/cgi/wiki?HierarchicalVisitorPattern + + Which are both good references for "visiting". + + An example of using Accept(): + @verbatim + TiXmlPrinter printer; + tinyxmlDoc.Accept( &printer ); + const char* xmlcstr = printer.CStr(); + @endverbatim + */ + virtual bool Accept( _TiXmlVisitor* visitor ) const = 0; + +protected: + _TiXmlNode( NodeType _type ); + + // Copy to the allocated object. Shared functionality between Clone, Copy constructor, + // and the assignment operator. + void CopyTo( _TiXmlNode* target ) const; + + #ifdef TIXML_USE_STL + // The real work of the input operator. + virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0; + #endif + + // Figure out what is at *p, and parse it. Returns null if it is not an xml node. + _TiXmlNode* Identify( const char* start, _TiXmlEncoding encoding ); + + _TiXmlNode* parent; + NodeType type; + + _TiXmlNode* firstChild; + _TiXmlNode* lastChild; + + TIXML_STRING value; + + _TiXmlNode* prev; + _TiXmlNode* next; + +private: + _TiXmlNode( const _TiXmlNode& ); // not implemented. + void operator=( const _TiXmlNode& base ); // not allowed. +}; + + +/** An attribute is a name-value pair. Elements have an arbitrary + number of attributes, each with a unique name. + + @note The attributes are not TiXmlNodes, since they are not + part of the tinyXML document object model. There are other + suggested ways to look at this problem. +*/ +class _TiXmlAttribute : public _TiXmlBase +{ + friend class _TiXmlAttributeSet; + +public: + /// Construct an empty attribute. + _TiXmlAttribute() : _TiXmlBase() + { + document = 0; + prev = next = 0; + } + + #ifdef TIXML_USE_STL + /// std::string constructor. + _TiXmlAttribute( const std::string& _name, const std::string& _value ) + { + name = _name; + value = _value; + document = 0; + prev = next = 0; + } + #endif + + /// Construct an attribute with a name and value. + _TiXmlAttribute( const char * _name, const char * _value ) + { + name = _name; + value = _value; + document = 0; + prev = next = 0; + } + + const char* Name() const { return name.c_str(); } ///< Return the name of this attribute. + const char* Value() const { return value.c_str(); } ///< Return the value of this attribute. + #ifdef TIXML_USE_STL + const std::string& ValueStr() const { return value; } ///< Return the value of this attribute. + #endif + int IntValue() const; ///< Return the value of this attribute, converted to an integer. + double DoubleValue() const; ///< Return the value of this attribute, converted to a double. + + // Get the tinyxml string representation + const TIXML_STRING& NameTStr() const { return name; } + + /** QueryIntValue examines the value string. It is an alternative to the + IntValue() method with richer error checking. + If the value is an integer, it is stored in 'value' and + the call returns TIXML_SUCCESS. If it is not + an integer, it returns TIXML_WRONG_TYPE. + + A specialized but useful call. Note that for success it returns 0, + which is the opposite of almost all other TinyXml calls. + */ + int QueryIntValue( int* _value ) const; + /// QueryDoubleValue examines the value string. See QueryIntValue(). + int QueryDoubleValue( double* _value ) const; + + void SetName( const char* _name ) { name = _name; } ///< Set the name of this attribute. + void SetValue( const char* _value ) { value = _value; } ///< Set the value. + + void SetIntValue( int _value ); ///< Set the value from an integer. + void SetDoubleValue( double _value ); ///< Set the value from a double. + + #ifdef TIXML_USE_STL + /// STL std::string form. + void SetName( const std::string& _name ) { name = _name; } + /// STL std::string form. + void SetValue( const std::string& _value ) { value = _value; } + #endif + + /// Get the next sibling attribute in the DOM. Returns null at end. + const _TiXmlAttribute* Next() const; + _TiXmlAttribute* Next() { + return const_cast< _TiXmlAttribute* >( (const_cast< const _TiXmlAttribute* >(this))->Next() ); + } + + /// Get the previous sibling attribute in the DOM. Returns null at beginning. + const _TiXmlAttribute* Previous() const; + _TiXmlAttribute* Previous() { + return const_cast< _TiXmlAttribute* >( (const_cast< const _TiXmlAttribute* >(this))->Previous() ); + } + + bool operator==( const _TiXmlAttribute& rhs ) const { return rhs.name == name; } + bool operator<( const _TiXmlAttribute& rhs ) const { return name < rhs.name; } + bool operator>( const _TiXmlAttribute& rhs ) const { return name > rhs.name; } + + /* Attribute parsing starts: first letter of the name + returns: the next char after the value end quote + */ + virtual const char* Parse( const char* p, _TiXmlParsingData* data, _TiXmlEncoding encoding ); + + // Prints this Attribute to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const { + Print( cfile, depth, 0 ); + } + void Print( FILE* cfile, int depth, TIXML_STRING* str ) const; + + // [internal use] + // Set the document pointer so the attribute can report errors. + void SetDocument( _TiXmlDocument* doc ) { document = doc; } + +private: + _TiXmlAttribute( const _TiXmlAttribute& ); // not implemented. + void operator=( const _TiXmlAttribute& base ); // not allowed. + + _TiXmlDocument* document; // A pointer back to a document, for error reporting. + TIXML_STRING name; + TIXML_STRING value; + _TiXmlAttribute* prev; + _TiXmlAttribute* next; +}; + + +/* A class used to manage a group of attributes. + It is only used internally, both by the ELEMENT and the DECLARATION. + + The set can be changed transparent to the Element and Declaration + classes that use it, but NOT transparent to the Attribute + which has to implement a next() and previous() method. Which makes + it a bit problematic and prevents the use of STL. + + This version is implemented with circular lists because: + - I like circular lists + - it demonstrates some independence from the (typical) doubly linked list. +*/ +class _TiXmlAttributeSet +{ +public: + _TiXmlAttributeSet(); + ~_TiXmlAttributeSet(); + + void Add( _TiXmlAttribute* attribute ); + void Remove( _TiXmlAttribute* attribute ); + + const _TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } + _TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } + const _TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } + _TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } + + _TiXmlAttribute* Find( const char* _name ) const; + _TiXmlAttribute* FindOrCreate( const char* _name ); + +# ifdef TIXML_USE_STL + _TiXmlAttribute* Find( const std::string& _name ) const; + _TiXmlAttribute* FindOrCreate( const std::string& _name ); +# endif + + +private: + //*ME: Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element), + //*ME: this class must be also use a hidden/disabled copy-constructor !!! + _TiXmlAttributeSet( const _TiXmlAttributeSet& ); // not allowed + void operator=( const _TiXmlAttributeSet& ); // not allowed (as TiXmlAttribute) + + _TiXmlAttribute sentinel; +}; + + +/** The element is a container class. It has a value, the element name, + and can contain other elements, text, comments, and unknowns. + Elements also contain an arbitrary number of attributes. +*/ +class _TiXmlElement : public _TiXmlNode +{ +public: + /// Construct an element. + _TiXmlElement (const char * in_value); + + #ifdef TIXML_USE_STL + /// std::string constructor. + _TiXmlElement( const std::string& _value ); + #endif + + _TiXmlElement( const _TiXmlElement& ); + + _TiXmlElement& operator=( const _TiXmlElement& base ); + + virtual ~_TiXmlElement(); + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + */ + const char* Attribute( const char* name ) const; + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + If the attribute exists and can be converted to an integer, + the integer value will be put in the return 'i', if 'i' + is non-null. + */ + const char* Attribute( const char* name, int* i ) const; + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + If the attribute exists and can be converted to an double, + the double value will be put in the return 'd', if 'd' + is non-null. + */ + const char* Attribute( const char* name, double* d ) const; + + /** QueryIntAttribute examines the attribute - it is an alternative to the + Attribute() method with richer error checking. + If the attribute is an integer, it is stored in 'value' and + the call returns TIXML_SUCCESS. If it is not + an integer, it returns TIXML_WRONG_TYPE. If the attribute + does not exist, then TIXML_NO_ATTRIBUTE is returned. + */ + int QueryIntAttribute( const char* name, int* _value ) const; + /// QueryUnsignedAttribute examines the attribute - see QueryIntAttribute(). + int QueryUnsignedAttribute( const char* name, unsigned* _value ) const; + /** QueryBoolAttribute examines the attribute - see QueryIntAttribute(). + Note that '1', 'true', or 'yes' are considered true, while '0', 'false' + and 'no' are considered false. + */ + int QueryBoolAttribute( const char* name, bool* _value ) const; + /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). + int QueryDoubleAttribute( const char* name, double* _value ) const; + /// QueryFloatAttribute examines the attribute - see QueryIntAttribute(). + int QueryFloatAttribute( const char* name, float* _value ) const { + double d; + int result = QueryDoubleAttribute( name, &d ); + if ( result == TIXML_SUCCESS ) { + *_value = (float)d; + } + return result; + } + + #ifdef TIXML_USE_STL + /// QueryStringAttribute examines the attribute - see QueryIntAttribute(). + int QueryStringAttribute( const char* name, std::string* _value ) const { + const char* cstr = Attribute( name ); + if ( cstr ) { + *_value = std::string( cstr ); + return TIXML_SUCCESS; + } + return TIXML_NO_ATTRIBUTE; + } + + /** Template form of the attribute query which will try to read the + attribute into the specified type. Very easy, very powerful, but + be careful to make sure to call this with the correct type. + + NOTE: This method doesn't work correctly for 'string' types that contain spaces. + + @return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE + */ + template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const + { + const _TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + + std::stringstream sstream( node->ValueStr() ); + sstream >> *outValue; + if ( !sstream.fail() ) + return TIXML_SUCCESS; + return TIXML_WRONG_TYPE; + } + + int QueryValueAttribute( const std::string& name, std::string* outValue ) const + { + const _TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + *outValue = node->ValueStr(); + return TIXML_SUCCESS; + } + #endif + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetAttribute( const char* name, const char * _value ); + + #ifdef TIXML_USE_STL + const std::string* Attribute( const std::string& name ) const; + const std::string* Attribute( const std::string& name, int* i ) const; + const std::string* Attribute( const std::string& name, double* d ) const; + int QueryIntAttribute( const std::string& name, int* _value ) const; + int QueryDoubleAttribute( const std::string& name, double* _value ) const; + + /// STL std::string form. + void SetAttribute( const std::string& name, const std::string& _value ); + ///< STL std::string form. + void SetAttribute( const std::string& name, int _value ); + ///< STL std::string form. + void SetDoubleAttribute( const std::string& name, double value ); + #endif + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetAttribute( const char * name, int value ); + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetDoubleAttribute( const char * name, double value ); + + /** Deletes an attribute with the given name. + */ + void RemoveAttribute( const char * name ); + #ifdef TIXML_USE_STL + void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); } ///< STL std::string form. + #endif + + const _TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); } ///< Access the first attribute in this element. + _TiXmlAttribute* FirstAttribute() { return attributeSet.First(); } + const _TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); } ///< Access the last attribute in this element. + _TiXmlAttribute* LastAttribute() { return attributeSet.Last(); } + + /** Convenience function for easy access to the text inside an element. Although easy + and concise, GetText() is limited compared to getting the TiXmlText child + and accessing it directly. + + If the first child of 'this' is a TiXmlText, the GetText() + returns the character string of the Text node, else null is returned. + + This is a convenient method for getting the text of simple contained text: + @verbatim + This is text + const char* str = fooElement->GetText(); + @endverbatim + + 'str' will be a pointer to "This is text". + + Note that this function can be misleading. If the element foo was created from + this XML: + @verbatim + This is text + @endverbatim + + then the value of str would be null. The first child node isn't a text node, it is + another element. From this XML: + @verbatim + This is text + @endverbatim + GetText() will return "This is ". + + WARNING: GetText() accesses a child node - don't become confused with the + similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are + safe type casts on the referenced node. + */ + const char* GetText() const; + + /// Creates a new Element and returns it - the returned element is a copy. + virtual _TiXmlNode* Clone() const; + // Print the Element to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + /* Attribtue parsing starts: next char past '<' + returns: next char past '>' + */ + virtual const char* Parse( const char* p, _TiXmlParsingData* data, _TiXmlEncoding encoding ); + + virtual const _TiXmlElement* ToElement() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual _TiXmlElement* ToElement() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( _TiXmlVisitor* visitor ) const; + +protected: + + void CopyTo( _TiXmlElement* target ) const; + void ClearThis(); // like clear, but initializes 'this' object as well + + // Used to be public [internal use] + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif + /* [internal use] + Reads the "value" of the element -- another element, or text. + This should terminate with the current end tag. + */ + const char* ReadValue( const char* in, _TiXmlParsingData* prevData, _TiXmlEncoding encoding ); + +private: + _TiXmlAttributeSet attributeSet; +}; + + +/** An XML comment. +*/ +class _TiXmlComment : public _TiXmlNode +{ +public: + /// Constructs an empty comment. + _TiXmlComment() : _TiXmlNode( _TiXmlNode::TINYXML_COMMENT ) {} + /// Construct a comment from text. + _TiXmlComment( const char* _value ) : _TiXmlNode( _TiXmlNode::TINYXML_COMMENT ) { + SetValue( _value ); + } + _TiXmlComment( const _TiXmlComment& ); + _TiXmlComment& operator=( const _TiXmlComment& base ); + + virtual ~_TiXmlComment() {} + + /// Returns a copy of this Comment. + virtual _TiXmlNode* Clone() const; + // Write this Comment to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + /* Attribtue parsing starts: at the ! of the !-- + returns: next char past '>' + */ + virtual const char* Parse( const char* p, _TiXmlParsingData* data, _TiXmlEncoding encoding ); + + virtual const _TiXmlComment* ToComment() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual _TiXmlComment* ToComment() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( _TiXmlVisitor* visitor ) const; + +protected: + void CopyTo( _TiXmlComment* target ) const; + + // used to be public + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif +// virtual void StreamOut( TIXML_OSTREAM * out ) const; + +private: + +}; + + +/** XML text. A text node can have 2 ways to output the next. "normal" output + and CDATA. It will default to the mode it was parsed from the XML file and + you generally want to leave it alone, but you can change the output mode with + SetCDATA() and query it with CDATA(). +*/ +class _TiXmlText : public _TiXmlNode +{ + friend class _TiXmlElement; +public: + /** Constructor for text element. By default, it is treated as + normal, encoded text. If you want it be output as a CDATA text + element, set the parameter _cdata to 'true' + */ + _TiXmlText (const char * initValue ) : _TiXmlNode (_TiXmlNode::TINYXML_TEXT) + { + SetValue( initValue ); + cdata = false; + } + virtual ~_TiXmlText() {} + + #ifdef TIXML_USE_STL + /// Constructor. + _TiXmlText( const std::string& initValue ) : _TiXmlNode (_TiXmlNode::TINYXML_TEXT) + { + SetValue( initValue ); + cdata = false; + } + #endif + + _TiXmlText( const _TiXmlText& copy ) : _TiXmlNode( _TiXmlNode::TINYXML_TEXT ) { copy.CopyTo( this ); } + _TiXmlText& operator=( const _TiXmlText& base ) { base.CopyTo( this ); return *this; } + + // Write this text object to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + /// Queries whether this represents text using a CDATA section. + bool CDATA() const { return cdata; } + /// Turns on or off a CDATA representation of text. + void SetCDATA( bool _cdata ) { cdata = _cdata; } + + virtual const char* Parse( const char* p, _TiXmlParsingData* data, _TiXmlEncoding encoding ); + + virtual const _TiXmlText* ToText() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual _TiXmlText* ToText() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( _TiXmlVisitor* content ) const; + +protected : + /// [internal use] Creates a new Element and returns it. + virtual _TiXmlNode* Clone() const; + void CopyTo( _TiXmlText* target ) const; + + bool Blank() const; // returns true if all white space and new lines + // [internal use] + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif + +private: + bool cdata; // true if this should be input and output as a CDATA style text element +}; + + +/** In correct XML the declaration is the first entry in the file. + @verbatim + + @endverbatim + + TinyXml will happily read or write files without a declaration, + however. There are 3 possible attributes to the declaration: + version, encoding, and standalone. + + Note: In this version of the code, the attributes are + handled as special cases, not generic attributes, simply + because there can only be at most 3 and they are always the same. +*/ +class _TiXmlDeclaration : public _TiXmlNode +{ +public: + /// Construct an empty declaration. + _TiXmlDeclaration() : _TiXmlNode( _TiXmlNode::TINYXML_DECLARATION ) {} + +#ifdef TIXML_USE_STL + /// Constructor. + _TiXmlDeclaration( const std::string& _version, + const std::string& _encoding, + const std::string& _standalone ); +#endif + + /// Construct. + _TiXmlDeclaration( const char* _version, + const char* _encoding, + const char* _standalone ); + + _TiXmlDeclaration( const _TiXmlDeclaration& copy ); + _TiXmlDeclaration& operator=( const _TiXmlDeclaration& copy ); + + virtual ~_TiXmlDeclaration() {} + + /// Version. Will return an empty string if none was found. + const char *Version() const { return version.c_str (); } + /// Encoding. Will return an empty string if none was found. + const char *Encoding() const { return encoding.c_str (); } + /// Is this a standalone document? + const char *Standalone() const { return standalone.c_str (); } + + /// Creates a copy of this Declaration and returns it. + virtual _TiXmlNode* Clone() const; + // Print this declaration to a FILE stream. + virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const; + virtual void Print( FILE* cfile, int depth ) const { + Print( cfile, depth, 0 ); + } + + virtual const char* Parse( const char* p, _TiXmlParsingData* data, _TiXmlEncoding encoding ); + + virtual const _TiXmlDeclaration* ToDeclaration() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual _TiXmlDeclaration* ToDeclaration() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( _TiXmlVisitor* visitor ) const; + +protected: + void CopyTo( _TiXmlDeclaration* target ) const; + // used to be public + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif + +private: + + TIXML_STRING version; + TIXML_STRING encoding; + TIXML_STRING standalone; +}; + + +/** Any tag that tinyXml doesn't recognize is saved as an + unknown. It is a tag of text, but should not be modified. + It will be written back to the XML, unchanged, when the file + is saved. + + DTD tags get thrown into TiXmlUnknowns. +*/ +class _TiXmlUnknown : public _TiXmlNode +{ +public: + _TiXmlUnknown() : _TiXmlNode( _TiXmlNode::TINYXML_UNKNOWN ) {} + virtual ~_TiXmlUnknown() {} + + _TiXmlUnknown( const _TiXmlUnknown& copy ) : _TiXmlNode( _TiXmlNode::TINYXML_UNKNOWN ) { copy.CopyTo( this ); } + _TiXmlUnknown& operator=( const _TiXmlUnknown& copy ) { copy.CopyTo( this ); return *this; } + + /// Creates a copy of this Unknown and returns it. + virtual _TiXmlNode* Clone() const; + // Print this Unknown to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + virtual const char* Parse( const char* p, _TiXmlParsingData* data, _TiXmlEncoding encoding ); + + virtual const _TiXmlUnknown* ToUnknown() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual _TiXmlUnknown* ToUnknown() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( _TiXmlVisitor* content ) const; + +protected: + void CopyTo( _TiXmlUnknown* target ) const; + + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif + +private: + +}; + + +/** Always the top level node. A document binds together all the + XML pieces. It can be saved, loaded, and printed to the screen. + The 'value' of a document node is the xml file name. +*/ +class _TiXmlDocument : public _TiXmlNode +{ +public: + /// Create an empty document, that has no name. + _TiXmlDocument(); + /// Create a document with a name. The name of the document is also the filename of the xml. + _TiXmlDocument( const char * documentName ); + + #ifdef TIXML_USE_STL + /// Constructor. + _TiXmlDocument( const std::string& documentName ); + #endif + + _TiXmlDocument( const _TiXmlDocument& copy ); + _TiXmlDocument& operator=( const _TiXmlDocument& copy ); + + virtual ~_TiXmlDocument() {} + + /** Load a file using the current document value. + Returns true if successful. Will delete any existing + document data before loading. + */ + bool LoadFile( _TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); + /// Save a file using the current document value. Returns true if successful. + bool SaveFile() const; + /// Load a file using the given filename. Returns true if successful. + bool LoadFile( const char * filename, _TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); + /// Save a file using the given filename. Returns true if successful. + bool SaveFile( const char * filename ) const; + /** Load a file using the given FILE*. Returns true if successful. Note that this method + doesn't stream - the entire object pointed at by the FILE* + will be interpreted as an XML file. TinyXML doesn't stream in XML from the current + file location. Streaming may be added in the future. + */ + bool LoadFile( FILE*, _TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); + /// Save a file using the given FILE*. Returns true if successful. + bool SaveFile( FILE* ) const; + + #ifdef TIXML_USE_STL + bool LoadFile( const std::string& filename, _TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ) ///< STL std::string version. + { + return LoadFile( filename.c_str(), encoding ); + } + bool SaveFile( const std::string& filename ) const ///< STL std::string version. + { + return SaveFile( filename.c_str() ); + } + #endif + + /** Parse the given null terminated block of xml data. Passing in an encoding to this + method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml + to use that encoding, regardless of what TinyXml might otherwise try to detect. + */ + virtual const char* Parse( const char* p, _TiXmlParsingData* data = 0, _TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); + + /** Get the root element -- the only top level element -- of the document. + In well formed XML, there should only be one. TinyXml is tolerant of + multiple elements at the document level. + */ + const _TiXmlElement* RootElement() const { return FirstChildElement(); } + _TiXmlElement* RootElement() { return FirstChildElement(); } + + /** If an error occurs, Error will be set to true. Also, + - The ErrorId() will contain the integer identifier of the error (not generally useful) + - The ErrorDesc() method will return the name of the error. (very useful) + - The ErrorRow() and ErrorCol() will return the location of the error (if known) + */ + bool Error() const { return error; } + + /// Contains a textual (english) description of the error if one occurs. + const char * ErrorDesc() const { return errorDesc.c_str (); } + + /** Generally, you probably want the error string ( ErrorDesc() ). But if you + prefer the ErrorId, this function will fetch it. + */ + int ErrorId() const { return errorId; } + + /** Returns the location (if known) of the error. The first column is column 1, + and the first row is row 1. A value of 0 means the row and column wasn't applicable + (memory errors, for example, have no row/column) or the parser lost the error. (An + error in the error reporting, in that case.) + + @sa SetTabSize, Row, Column + */ + int ErrorRow() const { return errorLocation.row+1; } + int ErrorCol() const { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow() + + /** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol()) + to report the correct values for row and column. It does not change the output + or input in any way. + + By calling this method, with a tab size + greater than 0, the row and column of each node and attribute is stored + when the file is loaded. Very useful for tracking the DOM back in to + the source file. + + The tab size is required for calculating the location of nodes. If not + set, the default of 4 is used. The tabsize is set per document. Setting + the tabsize to 0 disables row/column tracking. + + Note that row and column tracking is not supported when using operator>>. + + The tab size needs to be enabled before the parse or load. Correct usage: + @verbatim + TiXmlDocument doc; + doc.SetTabSize( 8 ); + doc.Load( "myfile.xml" ); + @endverbatim + + @sa Row, Column + */ + void SetTabSize( int _tabsize ) { tabsize = _tabsize; } + + int TabSize() const { return tabsize; } + + /** If you have handled the error, it can be reset with this call. The error + state is automatically cleared if you Parse a new XML block. + */ + void ClearError() { error = false; + errorId = 0; + errorDesc = ""; + errorLocation.row = errorLocation.col = 0; + //errorLocation.last = 0; + } + + /** Write the document to standard out using formatted printing ("pretty print"). */ + void Print() const { Print( stdout, 0 ); } + + /* Write the document to a string using formatted printing ("pretty print"). This + will allocate a character array (new char[]) and return it as a pointer. The + calling code pust call delete[] on the return char* to avoid a memory leak. + */ + //char* PrintToMemory() const; + + /// Print this Document to a FILE stream. + virtual void Print( FILE* cfile, int depth = 0 ) const; + // [internal use] + void SetError( int err, const char* errorLocation, _TiXmlParsingData* prevData, _TiXmlEncoding encoding ); + + virtual const _TiXmlDocument* ToDocument() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual _TiXmlDocument* ToDocument() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( _TiXmlVisitor* content ) const; + +protected : + // [internal use] + virtual _TiXmlNode* Clone() const; + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif + +private: + void CopyTo( _TiXmlDocument* target ) const; + + bool error; + int errorId; + TIXML_STRING errorDesc; + int tabsize; + _TiXmlCursor errorLocation; + bool useMicrosoftBOM; // the UTF-8 BOM were found when read. Note this, and try to write. +}; + + +/** + A TiXmlHandle is a class that wraps a node pointer with null checks; this is + an incredibly useful thing. Note that TiXmlHandle is not part of the TinyXml + DOM structure. It is a separate utility class. + + Take an example: + @verbatim + + + + + + + @endverbatim + + Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very + easy to write a *lot* of code that looks like: + + @verbatim + TiXmlElement* root = document.FirstChildElement( "Document" ); + if ( root ) + { + TiXmlElement* element = root->FirstChildElement( "Element" ); + if ( element ) + { + TiXmlElement* child = element->FirstChildElement( "Child" ); + if ( child ) + { + TiXmlElement* child2 = child->NextSiblingElement( "Child" ); + if ( child2 ) + { + // Finally do something useful. + @endverbatim + + And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity + of such code. A TiXmlHandle checks for null pointers so it is perfectly safe + and correct to use: + + @verbatim + TiXmlHandle docHandle( &document ); + TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).ToElement(); + if ( child2 ) + { + // do something useful + @endverbatim + + Which is MUCH more concise and useful. + + It is also safe to copy handles - internally they are nothing more than node pointers. + @verbatim + TiXmlHandle handleCopy = handle; + @endverbatim + + What they should not be used for is iteration: + + @verbatim + int i=0; + while ( true ) + { + TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).ToElement(); + if ( !child ) + break; + // do something + ++i; + } + @endverbatim + + It seems reasonable, but it is in fact two embedded while loops. The Child method is + a linear walk to find the element, so this code would iterate much more than it needs + to. Instead, prefer: + + @verbatim + TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).ToElement(); + + for( child; child; child=child->NextSiblingElement() ) + { + // do something + } + @endverbatim +*/ +class _TiXmlHandle +{ +public: + /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. + _TiXmlHandle( _TiXmlNode* _node ) { this->node = _node; } + /// Copy constructor + _TiXmlHandle( const _TiXmlHandle& ref ) { this->node = ref.node; } + _TiXmlHandle operator=( const _TiXmlHandle& ref ) { if ( &ref != this ) this->node = ref.node; return *this; } + + /// Return a handle to the first child node. + _TiXmlHandle FirstChild() const; + /// Return a handle to the first child node with the given name. + _TiXmlHandle FirstChild( const char * value ) const; + /// Return a handle to the first child element. + _TiXmlHandle FirstChildElement() const; + /// Return a handle to the first child element with the given name. + _TiXmlHandle FirstChildElement( const char * value ) const; + + /** Return a handle to the "index" child with the given name. + The first child is 0, the second 1, etc. + */ + _TiXmlHandle Child( const char* value, int index ) const; + /** Return a handle to the "index" child. + The first child is 0, the second 1, etc. + */ + _TiXmlHandle Child( int index ) const; + /** Return a handle to the "index" child element with the given name. + The first child element is 0, the second 1, etc. Note that only TiXmlElements + are indexed: other types are not counted. + */ + _TiXmlHandle ChildElement( const char* value, int index ) const; + /** Return a handle to the "index" child element. + The first child element is 0, the second 1, etc. Note that only TiXmlElements + are indexed: other types are not counted. + */ + _TiXmlHandle ChildElement( int index ) const; + + #ifdef TIXML_USE_STL + _TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); } + _TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); } + + _TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); } + _TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); } + #endif + + /** Return the handle as a TiXmlNode. This may return null. + */ + _TiXmlNode* ToNode() const { return node; } + /** Return the handle as a TiXmlElement. This may return null. + */ + _TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); } + /** Return the handle as a TiXmlText. This may return null. + */ + _TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); } + /** Return the handle as a TiXmlUnknown. This may return null. + */ + _TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); } + + /** @deprecated use ToNode. + Return the handle as a TiXmlNode. This may return null. + */ + _TiXmlNode* Node() const { return ToNode(); } + /** @deprecated use ToElement. + Return the handle as a TiXmlElement. This may return null. + */ + _TiXmlElement* Element() const { return ToElement(); } + /** @deprecated use ToText() + Return the handle as a TiXmlText. This may return null. + */ + _TiXmlText* Text() const { return ToText(); } + /** @deprecated use ToUnknown() + Return the handle as a TiXmlUnknown. This may return null. + */ + _TiXmlUnknown* Unknown() const { return ToUnknown(); } + +private: + _TiXmlNode* node; +}; + + +/** Print to memory functionality. The TiXmlPrinter is useful when you need to: + + -# Print to memory (especially in non-STL mode) + -# Control formatting (line endings, etc.) + + When constructed, the TiXmlPrinter is in its default "pretty printing" mode. + Before calling Accept() you can call methods to control the printing + of the XML document. After TiXmlNode::Accept() is called, the printed document can + be accessed via the CStr(), Str(), and Size() methods. + + TiXmlPrinter uses the Visitor API. + @verbatim + TiXmlPrinter printer; + printer.SetIndent( "\t" ); + + doc.Accept( &printer ); + fprintf( stdout, "%s", printer.CStr() ); + @endverbatim +*/ +class _TiXmlPrinter : public _TiXmlVisitor +{ +public: + _TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ), + buffer(), indent( " " ), lineBreak( "\n" ) {} + + virtual bool VisitEnter( const _TiXmlDocument& doc ); + virtual bool VisitExit( const _TiXmlDocument& doc ); + + virtual bool VisitEnter( const _TiXmlElement& element, const _TiXmlAttribute* firstAttribute ); + virtual bool VisitExit( const _TiXmlElement& element ); + + virtual bool Visit( const _TiXmlDeclaration& declaration ); + virtual bool Visit( const _TiXmlText& text ); + virtual bool Visit( const _TiXmlComment& comment ); + virtual bool Visit( const _TiXmlUnknown& unknown ); + + /** Set the indent characters for printing. By default 4 spaces + but tab (\t) is also useful, or null/empty string for no indentation. + */ + void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; } + /// Query the indention string. + const char* Indent() { return indent.c_str(); } + /** Set the line breaking string. By default set to newline (\n). + Some operating systems prefer other characters, or can be + set to the null/empty string for no indenation. + */ + void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; } + /// Query the current line breaking string. + const char* LineBreak() { return lineBreak.c_str(); } + + /** Switch over to "stream printing" which is the most dense formatting without + linebreaks. Common when the XML is needed for network transmission. + */ + void SetStreamPrinting() { indent = ""; + lineBreak = ""; + } + /// Return the result. + const char* CStr() { return buffer.c_str(); } + /// Return the length of the result string. + size_t Size() { return buffer.size(); } + + #ifdef TIXML_USE_STL + /// Return the result. + const std::string& Str() { return buffer; } + #endif + +private: + void DoIndent() { + for( int i=0; i +#include + +#include "tinyxml.h" + +//#define DEBUG_PARSER +#if defined( DEBUG_PARSER ) +# if defined( DEBUG ) && defined( _MSC_VER ) +# include +# define TIXML_LOG OutputDebugString +# else +# define TIXML_LOG printf +# endif +#endif + +// Note tha "PutString" hardcodes the same list. This +// is less flexible than it appears. Changing the entries +// or order will break putstring. +_TiXmlBase::Entity _TiXmlBase::entity[ _TiXmlBase::NUM_ENTITY ] = +{ + { "&", 5, '&' }, + { "<", 4, '<' }, + { ">", 4, '>' }, + { """, 6, '\"' }, + { "'", 6, '\'' } +}; + +// Bunch of unicode info at: +// http://www.unicode.org/faq/utf_bom.html +// Including the basic of this table, which determines the #bytes in the +// sequence from the lead byte. 1 placed for invalid sequences -- +// although the result will be junk, pass it through as much as possible. +// Beware of the non-characters in UTF-8: +// ef bb bf (Microsoft "lead bytes") +// ef bf be +// ef bf bf + +const unsigned char TIXML_UTF_LEAD_0 = 0xefU; +const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; +const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; + +const int _TiXmlBase::utf8ByteTable[256] = +{ + // 0 1 2 3 4 5 6 7 8 9 a b c d e f + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x00 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x10 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x20 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x30 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x50 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x70 End of ASCII range + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x80 0x80 to 0xc1 invalid + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x90 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xa0 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xb0 + 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xc0 0xc2 to 0xdf 2 byte + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xd0 + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xe0 0xe0 to 0xef 3 byte + 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // 0xf0 0xf0 to 0xf4 4 byte, 0xf5 and higher invalid +}; + + +void _TiXmlBase::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ) +{ + const unsigned long BYTE_MASK = 0xBF; + const unsigned long BYTE_MARK = 0x80; + const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; + + if (input < 0x80) + *length = 1; + else if ( input < 0x800 ) + *length = 2; + else if ( input < 0x10000 ) + *length = 3; + else if ( input < 0x200000 ) + *length = 4; + else + { *length = 0; return; } // This code won't covert this correctly anyway. + + output += *length; + + // Scary scary fall throughs. + switch (*length) + { + case 4: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + case 3: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + case 2: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + case 1: + --output; + *output = (char)(input | FIRST_BYTE_MARK[*length]); + } +} + + +/*static*/ int _TiXmlBase::IsAlpha( unsigned char anyByte, _TiXmlEncoding /*encoding*/ ) +{ + // This will only work for low-ascii, everything else is assumed to be a valid + // letter. I'm not sure this is the best approach, but it is quite tricky trying + // to figure out alhabetical vs. not across encoding. So take a very + // conservative approach. + +// if ( encoding == TIXML_ENCODING_UTF8 ) +// { + if ( anyByte < 127 ) + return isalpha( anyByte ); + else + return 1; // What else to do? The unicode set is huge...get the english ones right. +// } +// else +// { +// return isalpha( anyByte ); +// } +} + + +/*static*/ int _TiXmlBase::IsAlphaNum( unsigned char anyByte, _TiXmlEncoding /*encoding*/ ) +{ + // This will only work for low-ascii, everything else is assumed to be a valid + // letter. I'm not sure this is the best approach, but it is quite tricky trying + // to figure out alhabetical vs. not across encoding. So take a very + // conservative approach. + +// if ( encoding == TIXML_ENCODING_UTF8 ) +// { + if ( anyByte < 127 ) + return isalnum( anyByte ); + else + return 1; // What else to do? The unicode set is huge...get the english ones right. +// } +// else +// { +// return isalnum( anyByte ); +// } +} + + +class _TiXmlParsingData +{ + friend class _TiXmlDocument; + public: + void Stamp( const char* now, _TiXmlEncoding encoding ); + + const _TiXmlCursor& Cursor() const { return cursor; } + + private: + // Only used by the document! + _TiXmlParsingData( const char* start, int _tabsize, int row, int col ) + { + assert( start ); + stamp = start; + tabsize = _tabsize; + cursor.row = row; + cursor.col = col; + } + + _TiXmlCursor cursor; + const char* stamp; + int tabsize; +}; + + +void _TiXmlParsingData::Stamp( const char* now, _TiXmlEncoding encoding ) +{ + assert( now ); + + // Do nothing if the tabsize is 0. + if ( tabsize < 1 ) + { + return; + } + + // Get the current row, column. + int row = cursor.row; + int col = cursor.col; + const char* p = stamp; + assert( p ); + + while ( p < now ) + { + // Treat p as unsigned, so we have a happy compiler. + const unsigned char* pU = (const unsigned char*)p; + + // Code contributed by Fletcher Dunn: (modified by lee) + switch (*pU) { + case 0: + // We *should* never get here, but in case we do, don't + // advance past the terminating null character, ever + return; + + case '\r': + // bump down to the next line + ++row; + col = 0; + // Eat the character + ++p; + + // Check for \r\n sequence, and treat this as a single character + if (*p == '\n') { + ++p; + } + break; + + case '\n': + // bump down to the next line + ++row; + col = 0; + + // Eat the character + ++p; + + // Check for \n\r sequence, and treat this as a single + // character. (Yes, this bizarre thing does occur still + // on some arcane platforms...) + if (*p == '\r') { + ++p; + } + break; + + case '\t': + // Eat the character + ++p; + + // Skip to next tab stop + col = (col / tabsize + 1) * tabsize; + break; + + case TIXML_UTF_LEAD_0: + if ( encoding == TIXML_ENCODING_UTF8 ) + { + if ( *(p+1) && *(p+2) ) + { + // In these cases, don't advance the column. These are + // 0-width spaces. + if ( *(pU+1)==TIXML_UTF_LEAD_1 && *(pU+2)==TIXML_UTF_LEAD_2 ) + p += 3; + else if ( *(pU+1)==0xbfU && *(pU+2)==0xbeU ) + p += 3; + else if ( *(pU+1)==0xbfU && *(pU+2)==0xbfU ) + p += 3; + else + { p +=3; ++col; } // A normal character. + } + } + else + { + ++p; + ++col; + } + break; + + default: + if ( encoding == TIXML_ENCODING_UTF8 ) + { + // Eat the 1 to 4 byte utf8 character. + int step = _TiXmlBase::utf8ByteTable[*((const unsigned char*)p)]; + if ( step == 0 ) + step = 1; // Error case from bad encoding, but handle gracefully. + p += step; + + // Just advance one column, of course. + ++col; + } + else + { + ++p; + ++col; + } + break; + } + } + cursor.row = row; + cursor.col = col; + assert( cursor.row >= -1 ); + assert( cursor.col >= -1 ); + stamp = p; + assert( stamp ); +} + + +const char* _TiXmlBase::SkipWhiteSpace( const char* p, _TiXmlEncoding encoding ) +{ + if ( !p || !*p ) + { + return 0; + } + if ( encoding == TIXML_ENCODING_UTF8 ) + { + while ( *p ) + { + const unsigned char* pU = (const unsigned char*)p; + + // Skip the stupid Microsoft UTF-8 Byte order marks + if ( *(pU+0)==TIXML_UTF_LEAD_0 + && *(pU+1)==TIXML_UTF_LEAD_1 + && *(pU+2)==TIXML_UTF_LEAD_2 ) + { + p += 3; + continue; + } + else if(*(pU+0)==TIXML_UTF_LEAD_0 + && *(pU+1)==0xbfU + && *(pU+2)==0xbeU ) + { + p += 3; + continue; + } + else if(*(pU+0)==TIXML_UTF_LEAD_0 + && *(pU+1)==0xbfU + && *(pU+2)==0xbfU ) + { + p += 3; + continue; + } + + if ( IsWhiteSpace( *p ) ) // Still using old rules for white space. + ++p; + else + break; + } + } + else + { + while ( *p && IsWhiteSpace( *p ) ) + ++p; + } + + return p; +} + +#ifdef TIXML_USE_STL +/*static*/ bool _TiXmlBase::StreamWhiteSpace( std::istream * in, TIXML_STRING * tag ) +{ + for( ;; ) + { + if ( !in->good() ) return false; + + int c = in->peek(); + // At this scope, we can't get to a document. So fail silently. + if ( !IsWhiteSpace( c ) || c <= 0 ) + return true; + + *tag += (char) in->get(); + } +} + +/*static*/ bool _TiXmlBase::StreamTo( std::istream * in, int character, TIXML_STRING * tag ) +{ + //assert( character > 0 && character < 128 ); // else it won't work in utf-8 + while ( in->good() ) + { + int c = in->peek(); + if ( c == character ) + return true; + if ( c <= 0 ) // Silent failure: can't get document at this scope + return false; + + in->get(); + *tag += (char) c; + } + return false; +} +#endif + +// One of TinyXML's more performance demanding functions. Try to keep the memory overhead down. The +// "assign" optimization removes over 10% of the execution time. +// +const char* _TiXmlBase::ReadName( const char* p, TIXML_STRING * name, _TiXmlEncoding encoding ) +{ + // Oddly, not supported on some comilers, + //name->clear(); + // So use this: + *name = ""; + assert( p ); + + // Names start with letters or underscores. + // Of course, in unicode, tinyxml has no idea what a letter *is*. The + // algorithm is generous. + // + // After that, they can be letters, underscores, numbers, + // hyphens, or colons. (Colons are valid ony for namespaces, + // but tinyxml can't tell namespaces from names.) + if ( p && *p + && ( IsAlpha( (unsigned char) *p, encoding ) || *p == '_' ) ) + { + const char* start = p; + while( p && *p + && ( IsAlphaNum( (unsigned char ) *p, encoding ) + || *p == '_' + || *p == '-' + || *p == '.' + || *p == ':' ) ) + { + //(*name) += *p; // expensive + ++p; + } + if ( p-start > 0 ) { + name->assign( start, p-start ); + } + return p; + } + return 0; +} + +const char* _TiXmlBase::GetEntity( const char* p, char* value, int* length, _TiXmlEncoding encoding ) +{ + // Presume an entity, and pull it out. + TIXML_STRING ent; + int i; + *length = 0; + + if ( *(p+1) && *(p+1) == '#' && *(p+2) ) + { + unsigned long ucs = 0; + ptrdiff_t delta = 0; + unsigned mult = 1; + + if ( *(p+2) == 'x' ) + { + // Hexadecimal. + if ( !*(p+3) ) return 0; + + const char* q = p+3; + q = strchr( q, ';' ); + + if ( !q || !*q ) return 0; + + delta = q-p; + --q; + + while ( *q != 'x' ) + { + if ( *q >= '0' && *q <= '9' ) + ucs += mult * (*q - '0'); + else if ( *q >= 'a' && *q <= 'f' ) + ucs += mult * (*q - 'a' + 10); + else if ( *q >= 'A' && *q <= 'F' ) + ucs += mult * (*q - 'A' + 10 ); + else + return 0; + mult *= 16; + --q; + } + } + else + { + // Decimal. + if ( !*(p+2) ) return 0; + + const char* q = p+2; + q = strchr( q, ';' ); + + if ( !q || !*q ) return 0; + + delta = q-p; + --q; + + while ( *q != '#' ) + { + if ( *q >= '0' && *q <= '9' ) + ucs += mult * (*q - '0'); + else + return 0; + mult *= 10; + --q; + } + } + if ( encoding == TIXML_ENCODING_UTF8 ) + { + // convert the UCS to UTF-8 + ConvertUTF32ToUTF8( ucs, value, length ); + } + else + { + *value = (char)ucs; + *length = 1; + } + return p + delta + 1; + } + + // Now try to match it. + for( i=0; iappend( cArr, len ); + } + } + else + { + bool whitespace = false; + + // Remove leading white space: + p = SkipWhiteSpace( p, encoding ); + while ( p && *p + && !StringEqual( p, endTag, caseInsensitive, encoding ) ) + { + if ( *p == '\r' || *p == '\n' ) + { + whitespace = true; + ++p; + } + else if ( IsWhiteSpace( *p ) ) + { + whitespace = true; + ++p; + } + else + { + // If we've found whitespace, add it before the + // new character. Any whitespace just becomes a space. + if ( whitespace ) + { + (*text) += ' '; + whitespace = false; + } + int len; + char cArr[4] = { 0, 0, 0, 0 }; + p = GetChar( p, cArr, &len, encoding ); + if ( len == 1 ) + (*text) += cArr[0]; // more efficient + else + text->append( cArr, len ); + } + } + } + if ( p && *p ) + p += strlen( endTag ); + return ( p && *p ) ? p : 0; +} + +#ifdef TIXML_USE_STL + +void _TiXmlDocument::StreamIn( std::istream * in, TIXML_STRING * tag ) +{ + // The basic issue with a document is that we don't know what we're + // streaming. Read something presumed to be a tag (and hope), then + // identify it, and call the appropriate stream method on the tag. + // + // This "pre-streaming" will never read the closing ">" so the + // sub-tag can orient itself. + + if ( !StreamTo( in, '<', tag ) ) + { + SetError( TIXML_ERROR_PARSING_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return; + } + + while ( in->good() ) + { + int tagIndex = (int) tag->length(); + while ( in->good() && in->peek() != '>' ) + { + int c = in->get(); + if ( c <= 0 ) + { + SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); + break; + } + (*tag) += (char) c; + } + + if ( in->good() ) + { + // We now have something we presume to be a node of + // some sort. Identify it, and call the node to + // continue streaming. + _TiXmlNode* node = Identify( tag->c_str() + tagIndex, TIXML_DEFAULT_ENCODING ); + + if ( node ) + { + node->StreamIn( in, tag ); + bool isElement = node->ToElement() != 0; + delete node; + node = 0; + + // If this is the root element, we're done. Parsing will be + // done by the >> operator. + if ( isElement ) + { + return; + } + } + else + { + SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); + return; + } + } + } + // We should have returned sooner. + SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); +} + +#endif + +const char* _TiXmlDocument::Parse( const char* p, _TiXmlParsingData* prevData, _TiXmlEncoding encoding ) +{ + ClearError(); + + // Parse away, at the document level. Since a document + // contains nothing but other tags, most of what happens + // here is skipping white space. + if ( !p || !*p ) + { + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + // Note that, for a document, this needs to come + // before the while space skip, so that parsing + // starts from the pointer we are given. + location.Clear(); + if ( prevData ) + { + location.row = prevData->cursor.row; + location.col = prevData->cursor.col; + } + else + { + location.row = 0; + location.col = 0; + } + _TiXmlParsingData data( p, TabSize(), location.row, location.col ); + location = data.Cursor(); + + if ( encoding == TIXML_ENCODING_UNKNOWN ) + { + // Check for the Microsoft UTF-8 lead bytes. + const unsigned char* pU = (const unsigned char*)p; + if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0 + && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1 + && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 ) + { + encoding = TIXML_ENCODING_UTF8; + useMicrosoftBOM = true; + } + } + + p = SkipWhiteSpace( p, encoding ); + if ( !p ) + { + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + while ( p && *p ) + { + _TiXmlNode* node = Identify( p, encoding ); + if ( node ) + { + p = node->Parse( p, &data, encoding ); + LinkEndChild( node ); + } + else + { + break; + } + + // Did we get encoding info? + if ( encoding == TIXML_ENCODING_UNKNOWN + && node->ToDeclaration() ) + { + _TiXmlDeclaration* dec = node->ToDeclaration(); + const char* enc = dec->Encoding(); + assert( enc ); + + if ( *enc == 0 ) + encoding = TIXML_ENCODING_UTF8; + else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) ) + encoding = TIXML_ENCODING_UTF8; + else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) ) + encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice + else + encoding = TIXML_ENCODING_LEGACY; + } + + p = SkipWhiteSpace( p, encoding ); + } + + // Was this empty? + if ( !firstChild ) { + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding ); + return 0; + } + + // All is well. + return p; +} + +void _TiXmlDocument::SetError( int err, const char* pError, _TiXmlParsingData* data, _TiXmlEncoding encoding ) +{ + // The first error in a chain is more accurate - don't set again! + if ( error ) + return; + + assert( err > 0 && err < TIXML_ERROR_STRING_COUNT ); + error = true; + errorId = err; + errorDesc = errorString[ errorId ]; + + errorLocation.Clear(); + if ( pError && data ) + { + data->Stamp( pError, encoding ); + errorLocation = data->Cursor(); + } +} + + +_TiXmlNode* _TiXmlNode::Identify( const char* p, _TiXmlEncoding encoding ) +{ + _TiXmlNode* returnNode = 0; + + p = SkipWhiteSpace( p, encoding ); + if( !p || !*p || *p != '<' ) + { + return 0; + } + + p = SkipWhiteSpace( p, encoding ); + + if ( !p || !*p ) + { + return 0; + } + + // What is this thing? + // - Elements start with a letter or underscore, but xml is reserved. + // - Comments: "; + + if ( !StringEqual( p, startTag, false, encoding ) ) + { + if ( document ) + document->SetError( TIXML_ERROR_PARSING_COMMENT, p, data, encoding ); + return 0; + } + p += strlen( startTag ); + + // [ 1475201 ] TinyXML parses entities in comments + // Oops - ReadText doesn't work, because we don't want to parse the entities. + // p = ReadText( p, &value, false, endTag, false, encoding ); + // + // from the XML spec: + /* + [Definition: Comments may appear anywhere in a document outside other markup; in addition, + they may appear within the document type declaration at places allowed by the grammar. + They are not part of the document's character data; an XML processor MAY, but need not, + make it possible for an application to retrieve the text of comments. For compatibility, + the string "--" (double-hyphen) MUST NOT occur within comments.] Parameter entity + references MUST NOT be recognized within comments. + + An example of a comment: + + + */ + + value = ""; + // Keep all the white space. + while ( p && *p && !StringEqual( p, endTag, false, encoding ) ) + { + value.append( p, 1 ); + ++p; + } + if ( p && *p ) + p += strlen( endTag ); + + return p; +} + + +const char* _TiXmlAttribute::Parse( const char* p, _TiXmlParsingData* data, _TiXmlEncoding encoding ) +{ + p = SkipWhiteSpace( p, encoding ); + if ( !p || !*p ) return 0; + + if ( data ) + { + data->Stamp( p, encoding ); + location = data->Cursor(); + } + // Read the name, the '=' and the value. + const char* pErr = p; + p = ReadName( p, &name, encoding ); + if ( !p || !*p ) + { + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding ); + return 0; + } + p = SkipWhiteSpace( p, encoding ); + if ( !p || !*p || *p != '=' ) + { + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); + return 0; + } + + ++p; // skip '=' + p = SkipWhiteSpace( p, encoding ); + if ( !p || !*p ) + { + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); + return 0; + } + + const char* end; + const char SINGLE_QUOTE = '\''; + const char DOUBLE_QUOTE = '\"'; + + if ( *p == SINGLE_QUOTE ) + { + ++p; + end = "\'"; // single quote in string + p = ReadText( p, &value, false, end, false, encoding ); + } + else if ( *p == DOUBLE_QUOTE ) + { + ++p; + end = "\""; // double quote in string + p = ReadText( p, &value, false, end, false, encoding ); + } + else + { + // All attribute values should be in single or double quotes. + // But this is such a common error that the parser will try + // its best, even without them. + value = ""; + while ( p && *p // existence + && !IsWhiteSpace( *p ) // whitespace + && *p != '/' && *p != '>' ) // tag end + { + if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) { + // [ 1451649 ] Attribute values with trailing quotes not handled correctly + // We did not have an opening quote but seem to have a + // closing one. Give up and throw an error. + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); + return 0; + } + value += *p; + ++p; + } + } + return p; +} + +#ifdef TIXML_USE_STL +void _TiXmlText::StreamIn( std::istream * in, TIXML_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->peek(); + if ( !cdata && (c == '<' ) ) + { + return; + } + if ( c <= 0 ) + { + _TiXmlDocument* document = GetDocument(); + if ( document ) + document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); + return; + } + + (*tag) += (char) c; + in->get(); // "commits" the peek made above + + if ( cdata && c == '>' && tag->size() >= 3 ) { + size_t len = tag->size(); + if ( (*tag)[len-2] == ']' && (*tag)[len-3] == ']' ) { + // terminator of cdata. + return; + } + } + } +} +#endif + +const char* _TiXmlText::Parse( const char* p, _TiXmlParsingData* data, _TiXmlEncoding encoding ) +{ + value = ""; + _TiXmlDocument* document = GetDocument(); + + if ( data ) + { + data->Stamp( p, encoding ); + location = data->Cursor(); + } + + const char* const startTag = ""; + + if ( cdata || StringEqual( p, startTag, false, encoding ) ) + { + cdata = true; + + if ( !StringEqual( p, startTag, false, encoding ) ) + { + if ( document ) + document->SetError( TIXML_ERROR_PARSING_CDATA, p, data, encoding ); + return 0; + } + p += strlen( startTag ); + + // Keep all the white space, ignore the encoding, etc. + while ( p && *p + && !StringEqual( p, endTag, false, encoding ) + ) + { + value += *p; + ++p; + } + + TIXML_STRING dummy; + p = ReadText( p, &dummy, false, endTag, false, encoding ); + return p; + } + else + { + bool ignoreWhite = true; + + const char* end = "<"; + p = ReadText( p, &value, ignoreWhite, end, false, encoding ); + if ( p && *p ) + return p-1; // don't truncate the '<' + return 0; + } +} + +#ifdef TIXML_USE_STL +void _TiXmlDeclaration::StreamIn( std::istream * in, TIXML_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->get(); + if ( c <= 0 ) + { + _TiXmlDocument* document = GetDocument(); + if ( document ) + document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); + return; + } + (*tag) += (char) c; + + if ( c == '>' ) + { + // All is well. + return; + } + } +} +#endif + +const char* _TiXmlDeclaration::Parse( const char* p, _TiXmlParsingData* data, _TiXmlEncoding _encoding ) +{ + p = SkipWhiteSpace( p, _encoding ); + // Find the beginning, find the end, and look for + // the stuff in-between. + _TiXmlDocument* document = GetDocument(); + if ( !p || !*p || !StringEqual( p, "SetError( TIXML_ERROR_PARSING_DECLARATION, 0, 0, _encoding ); + return 0; + } + if ( data ) + { + data->Stamp( p, _encoding ); + location = data->Cursor(); + } + p += 5; + + version = ""; + encoding = ""; + standalone = ""; + + while ( p && *p ) + { + if ( *p == '>' ) + { + ++p; + return p; + } + + p = SkipWhiteSpace( p, _encoding ); + if ( StringEqual( p, "version", true, _encoding ) ) + { + _TiXmlAttribute attrib; + p = attrib.Parse( p, data, _encoding ); + version = attrib.Value(); + } + else if ( StringEqual( p, "encoding", true, _encoding ) ) + { + _TiXmlAttribute attrib; + p = attrib.Parse( p, data, _encoding ); + encoding = attrib.Value(); + } + else if ( StringEqual( p, "standalone", true, _encoding ) ) + { + _TiXmlAttribute attrib; + p = attrib.Parse( p, data, _encoding ); + standalone = attrib.Value(); + } + else + { + // Read over whatever it is. + while( p && *p && *p != '>' && !IsWhiteSpace( *p ) ) + ++p; + } + } + return 0; +} + +bool _TiXmlText::Blank() const +{ + for ( unsigned i=0; i + +#define INITIALIZE_A3D_API +#include "PRC2XML.h" + + +//###################################################################################################################### +A3DStatus ProcessFile( + A3DSDKHOOPSExchangeLoader& sHoopsExchangeLoader, + A3DImport& sImport, + const MY_CHAR* pcPRCFile, + const MY_CHAR* pcXMLFile); + +//###################################################################################################################### +// Main function +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, wchar_t** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + // ### COMMAND LINE ARGUMENTS + // + + if (iArgc > 4) + { + MY_PRINTF2("Usage:\n %s [input CAD file] [output XML file] [output LOG file]\n", ppcArgv[0]); + MY_PRINTF(" Default output XML file is [input CAD file].xml\n"); + MY_PRINTF(" Default output LOG file is [output XML file]_Log.txt\n\n"); + return A3D_ERROR; + } + + MY_CHAR acSrcFileName[_MAX_PATH * 2]; + MY_CHAR acDstFileName[_MAX_PATH * 2]; + MY_CHAR acLogFileName[_MAX_PATH * 2]; + + if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]); + else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD); + if (iArgc > 2) MY_STRCPY(acDstFileName, ppcArgv[2]); + else MY_SPRINTF(acDstFileName, "%s.xml", acSrcFileName); + if (iArgc > 3) MY_STRCPY(acLogFileName, ppcArgv[3]); + else MY_SPRINTF(acLogFileName, "%s_Log.txt", acDstFileName); + GetLogFile(acLogFileName); // Initialize log file + + // + // ### INITIALIZE HOOPS EXCHANGE + // + + A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); + CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus); + + // Initialize callbacks + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + // + // ### PROCESS SAMPLE CODE + // + + A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + + ProcessFile(sHoopsExchangeLoader, sImport, acSrcFileName, acDstFileName); + + // + // ### TERMINATE HOOPS EXCHANGE + // + + // Check memory allocations + return (int)ListLeaks(); +} diff --git a/exchange/exchangesource/PRC2XML/read_me.txt b/exchange/exchangesource/PRC2XML/read_me.txt new file mode 100644 index 0000000..344639e --- /dev/null +++ b/exchange/exchangesource/PRC2XML/read_me.txt @@ -0,0 +1,9 @@ +sdumont@techsoft3d.com - 2019-01-08 +----------------------------------- + +From now the source code for the Windows/Linux/MacOS version of PRC2XML will be shared with the Android and iOS versions. +The main.cpp file is used exclusively by the former. +The ExchangeManagement.cpp and .h files are used exclusively by the latters. +The source code files are copied to the Android and iOS-specific projets when creating their packages. + +Please do not forget to update the Android and iOS projects when making changes to the Windows/Linux/MacOS one (files added or removed, compilation flags). diff --git a/exchange/exchangesource/SewBrep/SewBrep.cpp b/exchange/exchangesource/SewBrep/SewBrep.cpp new file mode 100644 index 0000000..8da42f7 --- /dev/null +++ b/exchange/exchangesource/SewBrep/SewBrep.cpp @@ -0,0 +1,104 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file SewBrep.cpp + +This file demonstrates how to programmatically adapt B-rep models to particular needs using HOOPS Exchange. +The only input is the CAD file path. + +- Load a CAD file +- Traverse the entire data structure +- Call A3DSewBrep for each B-rep model +- New modified data is populated +- PRC is exported from the modified data + +***********************************************************************************************************************/ + +#define INITIALIZE_A3D_API +#include + +#include "../common.hpp" + +#include +#include + +//###################################################################################################################### +#define DTOL 1e-3 // The maximum tolerance for the sewing (in mm). + +static MY_CHAR acSrcFileName[_MAX_PATH * 2]; +static MY_CHAR acDstFileName[_MAX_PATH * 2]; +static MY_CHAR acLogFileName[_MAX_PATH * 2]; + +//###################################################################################################################### +// Main function +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + // + // ### COMMAND LINE ARGUMENTS + // + + if (iArgc > 4 ) + { + MY_PRINTF2("Usage:\n %s [input CAD file] [output CAD file] [output LOG file]\n", ppcArgv[0]); + MY_PRINTF(" Default output PRC file is [input CAD file].prc\n"); + MY_PRINTF(" Default output LOG file is [output CAD file]_Log.txt\n\n"); + return A3D_ERROR; + } + + if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]); + else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD); + if (iArgc > 2) MY_STRCPY(acDstFileName, ppcArgv[2]); + else MY_SPRINTF(acDstFileName, "%s.prc", acSrcFileName); + if (iArgc > 3) MY_STRCPY(acLogFileName, ppcArgv[3]); + else MY_SPRINTF(acLogFileName, "%s_Log.txt", acDstFileName); + GetLogFile(acLogFileName); // Initialize log file + + // + // ### INITIALIZE HOOPS EXCHANGE + // + + A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); + CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus); + + // Initialize callbacks + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + // + // ### PROCESS SAMPLE CODE + // + + // Load a CAD File + A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + A3DStatus iRet = sHoopsExchangeLoader.Import(sImport); + if (iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS) + CHECK_RET(iRet); + + A3DSewOptionsData sSewData; + A3D_INITIALIZE_DATA(A3DSewOptionsData, sSewData); + CHECK_RET(A3DAsmModelFileSew(&sHoopsExchangeLoader.m_psModelFile, DTOL, &sSewData)); + + // Save the SewBrep to PRC File + A3DExport sExport(acDstFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + CHECK_RET(sHoopsExchangeLoader.Export(sExport)); + + // + // ### TERMINATE HOOPS EXCHANGE + // + + // Check memory allocations + return (int)ListLeaks(); + +} diff --git a/exchange/exchangesource/SewBrep/SewBrep.vcxproj b/exchange/exchangesource/SewBrep/SewBrep.vcxproj new file mode 100644 index 0000000..dd8d27f --- /dev/null +++ b/exchange/exchangesource/SewBrep/SewBrep.vcxproj @@ -0,0 +1,164 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {8BCFAE5D-00F9-41A6-9A15-A1A5AE1EFAEA} + SewBrep + Win32Proj + 10.0 + + + + Application + v145 + true + + + Application + v145 + + + Application + v145 + true + + + Application + v145 + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + Level4 + ProgramDatabase + false + + + true + Console + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + true + Console + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + MaxSpeed + true + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + Level4 + ProgramDatabase + false + + + true + Console + true + true + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + MaxSpeed + true + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + Level4 + ProgramDatabase + false + + + true + Console + true + true + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/SewBrep/SewBrep.vcxproj.filters b/exchange/exchangesource/SewBrep/SewBrep.vcxproj.filters new file mode 100644 index 0000000..fa2ab04 --- /dev/null +++ b/exchange/exchangesource/SewBrep/SewBrep.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + Source Files + + + \ No newline at end of file diff --git a/exchange/exchangesource/Shattered/Shattered.cpp b/exchange/exchangesource/Shattered/Shattered.cpp new file mode 100644 index 0000000..d085813 --- /dev/null +++ b/exchange/exchangesource/Shattered/Shattered.cpp @@ -0,0 +1,272 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file Shattered.cpp + +PRC Can be used as a multi-file format using our shattered mode. +This sample demonstrates how to load a CAD file independently from each other. +Then it creates one PRC per file. Finally the full model is reloaded in memory from these multiple files. + +***********************************************************************************************************************/ + +#ifndef _MSC_VER +# include // for dirname +# define MAX_PATH 512 +#endif + +#define INITIALIZE_A3D_API +#include + +#include "../common.hpp" + +//###################################################################################################################### +#ifndef _MSC_VER + +void SplitPathLinux( + const char *pcPath, /* I: Path to split */ + char pcDir[MAX_PATH], /* O: Extracted dir */ + char pcFile[MAX_PATH], /* O: Extracted file name */ + char pcExt[8]) /* O: Extracted file extension */ +{ + char acBuf[MAX_PATH*3]; + char *pcDirName, *pcFileName, *pcCur; + int iLen, iLenExt; + + strcpy(acBuf, pcPath); + pcDirName = dirname(acBuf ); + strcpy(pcDir, pcDirName); + + strcpy(acBuf, pcPath); + pcFileName = basename(acBuf); + if(*pcFileName == '/') + pcFileName++; + + iLen = strlen(pcFileName); + pcCur = pcFileName+iLen-1; + iLenExt = 0; + while(pcCur >= pcFileName) + { + if(*pcCur == '.') + break; + pcCur--; + iLenExt++; + } + if(iLenExt == iLen) + { + strcpy(pcFile, pcFileName); + *pcExt = '\0'; + } + else if(iLenExt) + { + strncpy(pcFile, pcFileName, pcCur-pcFileName); + pcFile[pcCur-pcFileName] = '\0'; + strncpy(pcExt, pcCur+1, iLenExt); + pcExt[iLenExt] = '\0'; + } + else + { + strncpy(pcFile, pcFileName, iLen-1); + pcFile[iLen] = '\0'; + *pcExt = '\0'; + } +} +#endif + +static MY_CHAR acSrcFileName[_MAX_PATH * 2]; +static MY_CHAR acDstPathName[_MAX_PATH * 2]; +static MY_CHAR acLogFileName[_MAX_PATH * 2]; + +//###################################################################################################################### +// Main function +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + // + // ### COMMAND LINE ARGUMENTS + // + + if (iArgc > 4) + { + MY_PRINTF2("Usage:\n %s [input CAD file] [output PRC directory] [output LOG file]\n", ppcArgv[0]); + MY_PRINTF(" Default output PRC directory is the same as [input CAD file]\n"); + MY_PRINTF(" Default output LOG file is [input CAD file]_Log.txt\n\n"); + return A3D_ERROR; + } + + if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]); + else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD); + if (iArgc > 2) MY_STRCPY(acDstPathName, ppcArgv[2]); + else MY_STRCPY(acDstPathName, _T(SAMPLES_DEFAULT_OUTPUT_PATH)); + if (iArgc > 3) MY_STRCPY(acLogFileName, ppcArgv[3]); + else MY_SPRINTF(acLogFileName, "%s_Log.txt", acSrcFileName); + GetLogFile(acLogFileName); // Initialize log file + + // + // ### INITIALIZE HOOPS EXCHANGE + // + + A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); + CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus); + + // Initialize callbacks + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + // + // ### PROCESS SAMPLE CODE + // + + A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + A3DStatus iRet = sHoopsExchangeLoader.Import(sImport); + if (iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS) + CHECK_RET(iRet); + + //Extract all dependencies from a CAD file - This step is not necessary when the assemblies dependencies are known + A3DUTF8Char** ppPart, ** ppAssembly, ** ppMissing; + A3DUns32 uNbPart, uNbAssembly, uNbMissing; + A3DAsmGetFilesPathFromModelFile(sHoopsExchangeLoader.m_psModelFile, &uNbPart, &ppPart, &uNbAssembly, &ppAssembly, &uNbMissing, &ppMissing); + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // Load and convert Each CAD to a PRC. + // Each part is managed independently because sImport.m_sLoadData.m_sIncremental.m_bLoadNoDependencies is set to true + // + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + A3DUniChar acDrive[8]; + A3DUniChar acDir[_MAX_PATH]; + A3DUniChar acName[_MAX_PATH]; + A3DUniChar acExt[_MAX_PATH]; + A3DUniChar acPrcFileName[_MAX_PATH * 3]; + + A3DUTF8Char** acPrcFilePath = (A3DUTF8Char**)malloc(sizeof(A3DUTF8Char*) * (uNbPart + uNbAssembly + 1)); + memset(acPrcFilePath, 0, sizeof(A3DUTF8Char*) * (uNbPart + uNbAssembly + 1)); + const MemoryGuard sGuardPrcFilePath(acPrcFilePath); + A3DUTF8Char** acCADFilePath = (A3DUTF8Char**)malloc(sizeof(A3DUTF8Char*) * (uNbPart + uNbAssembly + 1)); + memset(acCADFilePath, 0, sizeof(A3DUTF8Char*) * (uNbPart + uNbAssembly + 1)); + const MemoryGuard sGuardCADFilePath(acCADFilePath); + + for (unsigned int uI = 0; uI < uNbAssembly; ++uI) + { + if (sHoopsExchangeLoader.m_psModelFile) + { + A3DAsmModelFileDelete(sHoopsExchangeLoader.m_psModelFile); + sHoopsExchangeLoader.m_psModelFile = NULL; + } + + // Determine PRc File Name + Unicode to UT8 conversions +#ifdef _MSC_VER + wchar_t* pucString = (wchar_t*)malloc(_MAX_PATH * 3 * sizeof(wchar_t)); + A3DMiscUTF8ToUnicode(ppAssembly[uI], (A3DUTF8Char*)pucString); + _wsplitpath(pucString, acDrive, acDir, acName, acExt); + free(pucString); + pucString = NULL; + swprintf(&acPrcFileName[0], _MAX_PATH * 3, L"%s\\%s.prc", &acDstPathName[0], acName); + + acPrcFilePath[uI] = (A3DUTF8Char*)malloc(_MAX_PATH * 3 * sizeof(A3DUTF8Char)); + A3DMiscUnicodeToUTF8((A3DUTF8Char*)&acPrcFileName[0], acPrcFilePath[uI]); +#else + SplitPathLinux(ppAssembly[uI], acDir, acName, acExt); + acPrcFilePath[uI] = (A3DUTF8Char*)malloc(_MAX_PATH * 3 * sizeof(A3DUTF8Char)); + sprintf(acPrcFilePath[uI], "%s/%s.prc", &acDstPathName[0], acName); +#endif + acCADFilePath[uI] = ppAssembly[uI]; + + //Convert assembly files to PRC + A3DImport sSubImport(ppAssembly[uI]); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + sSubImport.m_sLoadData.m_sIncremental.m_bLoadNoDependencies = true; + + A3DExport sExport(acPrcFilePath[uI]); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + iRet = sHoopsExchangeLoader.Convert(sSubImport, sExport); + } + + //Convert CAD part files to PRC + for (unsigned int uI = 0; uI < uNbPart; ++uI) + { + if (sHoopsExchangeLoader.m_psModelFile) + { + A3DAsmModelFileDelete(sHoopsExchangeLoader.m_psModelFile); + sHoopsExchangeLoader.m_psModelFile = NULL; + } + +#ifdef _MSC_VER + //Generate PRC filename; convert wchar_t path to UTF-8 + wchar_t* pucString = (wchar_t*)malloc(_MAX_PATH * 3 * sizeof(wchar_t)); + A3DMiscUTF8ToUnicode(ppPart[uI], (A3DUTF8Char*)pucString); + _wsplitpath(pucString, acDrive, acDir, acName, acExt); + free(pucString); + pucString = NULL; + swprintf(&acPrcFileName[0], _MAX_PATH * 3, L"%s\\%s.prc", &acDstPathName[0], acName); + + acPrcFilePath[uI + uNbAssembly] = (A3DUTF8Char*)malloc(_MAX_PATH * 3 * sizeof(A3DUTF8Char)); + A3DMiscUnicodeToUTF8((A3DUTF8Char*)&acPrcFileName[0], acPrcFilePath[uI + uNbAssembly]); +#else + SplitPathLinux(ppPart[uI], acDir, acName, acExt); + acPrcFilePath[uI + uNbAssembly] = (A3DUTF8Char*)malloc(_MAX_PATH * 3 * sizeof(A3DUTF8Char)); + sprintf(acPrcFilePath[uI + uNbAssembly], "%s/%s.prc", &acDstPathName[0], acName); +#endif + acCADFilePath[uI + uNbAssembly] = ppPart[uI]; + + //Convert assembly files to PRC + A3DImport sSubImport(ppPart[uI]); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + sSubImport.m_sLoadData.m_sIncremental.m_bLoadNoDependencies = true; + + A3DExport sExport(acPrcFilePath[uI + uNbAssembly]); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + iRet = sHoopsExchangeLoader.Convert(sSubImport, sExport); + } + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // Load the full Model from PRC. + // A mapping between CAD filepath and PRC filepath needs to be maintained by customers to use this fuction. + // + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + if (sHoopsExchangeLoader.m_psModelFile) + { + A3DAsmModelFileDelete(sHoopsExchangeLoader.m_psModelFile); + sHoopsExchangeLoader.m_psModelFile = NULL; + } + + A3DRWParamsLoadData sParamsLoadData; + A3D_INITIALIZE_DATA(A3DRWParamsLoadData, sParamsLoadData); + A3DUTF8Char acRootPrcFilePath[_MAX_PATH * 3]; + +#ifdef _MSC_VER + _wsplitpath(iArgc > 1 ? ppcArgv[1] : DEFAULT_INPUT_CAD, acDrive, acDir, acName, acExt); + swprintf(acPrcFileName, _MAX_PATH * 3, L"%s\\%s.prc", &acDstPathName[0], acName); + A3DMiscUnicodeToUTF8((A3DUTF8Char*)&acPrcFileName[0], &acRootPrcFilePath[0]); +#else + SplitPathLinux(iArgc > 1 ? ppcArgv[1] : DEFAULT_INPUT_CAD, acDir, acName, acExt); + sprintf(acRootPrcFilePath, "%s/%s.prc", &acDstPathName[0], acName); +#endif + + iRet = A3DAsmModelFileLoadFromPRCFiles(&acRootPrcFilePath[0], uNbPart + uNbAssembly, + (const A3DUTF8Char**)acPrcFilePath, (const A3DUTF8Char**)acCADFilePath, &sParamsLoadData, + &(sHoopsExchangeLoader.m_psModelFile)); + + A3DAsmGetFilesPathFromModelFile(NULL, &uNbPart, &ppPart, &uNbAssembly, &ppAssembly, &uNbMissing, &ppMissing); + + for (unsigned int uI = 0; uI < uNbAssembly + uNbPart; ++uI) + { + free(acPrcFilePath[uI]); + } + + // + // ### TERMINATE HOOPS EXCHANGE + // + + // Check memory allocations + return (int)ListLeaks(); +} diff --git a/exchange/exchangesource/Shattered/Shattered.vcxproj b/exchange/exchangesource/Shattered/Shattered.vcxproj new file mode 100644 index 0000000..b16fcb0 --- /dev/null +++ b/exchange/exchangesource/Shattered/Shattered.vcxproj @@ -0,0 +1,164 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {ACEC4E45-AA20-4C1F-94FB-034459E3ABC7} + SewBrep + Win32Proj + 10.0 + + + + Application + v145 + true + + + Application + v145 + + + Application + v145 + true + + + Application + v145 + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + Level4 + ProgramDatabase + false + + + true + Console + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + Level4 + ProgramDatabase + false + + + true + Console + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + MaxSpeed + true + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + Level4 + ProgramDatabase + false + + + true + Console + true + true + MachineX86 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + X64 + + + MaxSpeed + true + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + Level4 + ProgramDatabase + false + + + true + Console + true + true + MachineX64 + legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/Shattered/Shattered.vcxproj.filters b/exchange/exchangesource/Shattered/Shattered.vcxproj.filters new file mode 100644 index 0000000..47ae77c --- /dev/null +++ b/exchange/exchangesource/Shattered/Shattered.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + Source Files + + + \ No newline at end of file diff --git a/exchange/exchangesource/TranslateToPkParts/PARA.props b/exchange/exchangesource/TranslateToPkParts/PARA.props new file mode 100644 index 0000000..ce6f6ee --- /dev/null +++ b/exchange/exchangesource/TranslateToPkParts/PARA.props @@ -0,0 +1,24 @@ + + + + + + please_set_your_parasolid_install_path_here + please_set_your_parasolid_install_path_here + + + <_ProjectFileVersion>12.0.30501.0 + <_PropertySheetDisplayName>PARASOLID + + + + + $(PARASOLID_INSTALL_DIR) + true + + + $(PARASOLID_INSTALL_DIR_64) + true + + + \ No newline at end of file diff --git a/exchange/exchangesource/TranslateToPkParts/TranslateToPkParts.cpp b/exchange/exchangesource/TranslateToPkParts/TranslateToPkParts.cpp new file mode 100644 index 0000000..4baa4ba --- /dev/null +++ b/exchange/exchangesource/TranslateToPkParts/TranslateToPkParts.cpp @@ -0,0 +1,481 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file TranslateToPkParts.cpp + +This file demonstrates how to load a CAD file and import the data into a Parasolid session. + +- Load a CAD file with HOOPS Exchange +- Call the A3DSDKHOOPSExchangeLoader::Export() function +- Export to Parasolid with PK_PART_transmit (Parasolid API) + +In order to compile, you need to: +1. On Windows + - Set up the PARASOLID_INSTALL_DIR and PARASOLID_INSTALL_DIR_64 environment variables to your Parasolid folder using the property sheet PARASOLID with the "User macros" field; + - Save the property sheet. + - Then you can build it. +2. On Linux + - Set up the PARASOLID_INSTALL_DIR environment variable to your Parasolid folder in the makefile + - Then you can build it. + +In order to run, you need to: +Common: + - Set up the P_SCHEMA environment variable to your Parasolid schema folder (ending with \base\schema); + - Copy pskernel.dll or libpskernel.so to your working directory (the HOOPS Exchange library binary folder). +Windows-specific: + - Provide the correct working directory, i.e. the HOOPS Exchange binary folder (i.e. ..\..\..\..\bin\win32); + this setting is located in Project Properties --> Configuration Properties --> Debugging --> Working Directory; + - Set up the command line + - Then you can run it. +Linux-specific: + - Set up the LD_LIBRARY_PATH=$PARASOLID_INSTALL_DIR/shared_object:../../../../bin/linux32|linux64 + - Then you can run it. +***********************************************************************************************************************/ + +#if defined(_MSC_VER) && !defined(PARASOLID_INSTALL_DIR) +# error PARASOLID_INSTALL_DIR environment variable required +#endif + +#include + +#ifndef _MSC_VER +# include +#endif + +#define INITIALIZE_A3D_API +#include + +#include "../common.hpp" +//###################################################################################################################### +extern "C" +{ + extern void FSTART(int*); + extern void FABORT(int*); + extern void FSTOP(int*); + extern void FMALLO(int*, char**, int*); + extern void FMFREE(int*, char**, int*); + extern void GOSGMT(const int*, const int*, const int*, const int*, const double*, const int*, const int*, int*); + extern void GOOPSG(const int*, const int*, const int*, const int*, const double*, const int*, const int*, int*); + extern void GOCLSG(const int*, const int*, const int*, const int*, const double*, const int*, const int*, int*); + extern void GOPIXL(const int*, const double*, const int*, const int*, int*); + extern void GOOPPX(const int*, const double*, const int*, const int*, int*); + extern void GOCLPX(const int*, const double*, const int*, const int*, int*); + extern void FFOPRD(const int*, const int*, const char*, const int*, const int*, int*, int*); + extern void FFOPWR(const int*, const int*, const char*, const int*, const char*, const int*, int*, int*); + extern void FFCLOS(const int*, const int*, const int*, int*); + extern void FFREAD(const int*, const int*, const int*, char*, int*, int*); + extern void FFWRIT(const int*, const int*, const int*, const char*, int*); + extern void FFOPRB(const int*, const int*, const int*, int*, int*, int*); + extern void FFSEEK(const int*, const int*, const int*, int*); + extern void FFTELL(const int*, const int*, int*, int*); + extern PK_ERROR_code_t FRU_delta_open_for_write(PK_PMARK_t, PK_DELTA_t*); + extern PK_ERROR_code_t FRU_delta_open_for_read(PK_DELTA_t); + extern PK_ERROR_code_t FRU_delta_write(PK_DELTA_t, unsigned, const char*); + extern PK_ERROR_code_t FRU_delta_read(PK_DELTA_t, unsigned, char*); + extern PK_ERROR_code_t FRU_delta_delete(PK_DELTA_t); + extern PK_ERROR_code_t FRU_delta_close(PK_DELTA_t); + + extern int FRU__delta_init(int action); +} + +//###################################################################################################################### +bool ParasolidInitialize() +{ + PK_ERROR_code_t pk_error; + PK_SESSION_frustrum_t ps_file_handlers; + PK_MEMORY_frustrum_t ps_memory_handlers; + PK_SESSION_frustrum_o_m(ps_file_handlers); + ps_file_handlers.fstart = FSTART; + ps_file_handlers.fabort = FABORT; + ps_file_handlers.fstop = FSTOP; + ps_file_handlers.fmallo = FMALLO; + ps_file_handlers.fmfree = FMFREE; + ps_file_handlers.gosgmt = GOSGMT; + ps_file_handlers.goopsg = GOOPSG; + ps_file_handlers.goclsg = GOCLSG; + ps_file_handlers.gopixl = GOPIXL; + ps_file_handlers.gooppx = GOOPPX; + ps_file_handlers.goclpx = GOCLPX; + ps_file_handlers.ffoprd = FFOPRD; + ps_file_handlers.ffopwr = FFOPWR; + ps_file_handlers.ffclos = FFCLOS; + ps_file_handlers.ffread = FFREAD; + ps_file_handlers.ffwrit = FFWRIT; + ps_file_handlers.ffoprb = FFOPRB; + ps_file_handlers.ffseek = FFSEEK; + ps_file_handlers.fftell = FFTELL; + pk_error = PK_SESSION_register_frustrum(&ps_file_handlers); + if (pk_error != PK_ERROR_no_errors) + return false; + + ps_memory_handlers.alloc_fn = malloc; + ps_memory_handlers.free_fn = free; + pk_error = PK_MEMORY_register_callbacks(ps_memory_handlers); + if (pk_error != PK_ERROR_no_errors) + return false; + + PK_DELTA_frustrum_t deltaFrustrum; + deltaFrustrum.open_for_write_fn = FRU_delta_open_for_write; + deltaFrustrum.open_for_read_fn = FRU_delta_open_for_read; + deltaFrustrum.close_fn = FRU_delta_close; + deltaFrustrum.write_fn = FRU_delta_write; + deltaFrustrum.read_fn = FRU_delta_read; + deltaFrustrum.delete_fn = FRU_delta_delete; + pk_error = PK_DELTA_register_callbacks(deltaFrustrum); + if (pk_error != PK_ERROR_no_errors) + return false; + + FRU__delta_init(1); + + PK_SESSION_start_o_t session_options; + PK_SESSION_start_o_m(session_options); + session_options.user_field = 0; + session_options.journal_file = NULL; + pk_error = PK_SESSION_start(&session_options); + return pk_error == PK_ERROR_no_errors; +} + +//###################################################################################################################### +void ParasolidTerminate() +{ + FRU__delta_init(2); + PK_SESSION_stop(); +} + +#ifdef _MSC_VER +# include +#elif defined (__linux__) && !defined(__APPLE__) +# include +#elif defined (__APPLE__) +# include +# include +#else +#error TSystem not implemented on this platform +#endif +static int getLogicalProcessor() +{ +#ifdef _MSC_VER + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + return sysinfo.dwNumberOfProcessors; +#elif defined (__APPLE__) + int nm[2]; + size_t len = 4; + uint32_t count; + + nm[0] = CTL_HW; nm[1] = HW_AVAILCPU; + sysctl(nm, 2, &count, &len, NULL, 0); + + if (count < 1) { + nm[1] = HW_NCPU; + sysctl(nm, 2, &count, &len, NULL, 0); + if (count < 1) { count = 1; } + } + return count; +#elif defined (__linux__) && !defined (__APPLE__) + return sysconf(_SC_NPROCESSORS_ONLN); +#else + return 1; +#endif +} + +static MY_CHAR acSrcFileName[_MAX_PATH * 2]; +static MY_CHAR acDstFileName[_MAX_PATH * 2]; +static MY_CHAR acLogFileName[_MAX_PATH * 2]; + +//###################################################################################################################### +// Main function +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + // + // ### COMMAND LINE ARGUMENTS + // + + for (int iArg = 0; iArg < iArgc; iArg++) + MY_PRINTF2("%s ", ppcArgv[iArg]); + MY_PRINTF("\n"); + + if (iArgc < 2) + { + MY_PRINTF2("Usage:\n %s [options]\n", ppcArgv[0]); + MY_PRINTF(" Default output Parasolid file is [input CAD file].xmt_txt\n\n"); + MY_PRINTF(" Default output LOG file is [output Parasolid file].xmt_txt_Log.txt\n\n"); + MY_PRINTF(" options:\n"); + MY_PRINTF(" -log filename : file to dump messages into. Default is _Log.txt\n"); + MY_PRINTF(" -healing 0|1|2 : healing mode (it activates the Parasolid healing); 0 = off (by default), 1 = on all the time, 2 = on only for data not coming from Parasolid\n"); + MY_PRINTF(" -accurate 0|1|2 : accurate mode (it replaces tolerant edges by accurate ones if possible); 0 = off (by default), 1 = on all the time, 2 = on only for data not coming from Parasolid \n"); + MY_PRINTF(" -simplify 0|1|2 : simplify mode (it replaces curves and surfaces by simplified geometry if possible); 0 = off (by default), 1 = on all the time, 2 = on only for data not coming from Parasolid \n"); + MY_PRINTF(" -merge 0|1|2 : merge mode (it merges geomerties and topologies if possible); 0 = off (by default), 1 = on all the time, 2 = on only for data not coming from Parasolid \n"); + MY_PRINTF(" -disjoin 0|1 : disjoin mode (it removes some faces from the bodies to avoid PK_FACE_state_bad_face_face_c errors); 0 = off (by default), 1 = on\n"); + MY_PRINTF(" -sew 0|1 : sew mode (it sews bodies together if possible); 0 = off, 1 = on (by default)\n"); + MY_PRINTF(" -sewexchange 0|1 : sew mode (it sews bodies together if possible); 0 = off, 1 = on (by default) Only applied to non parasolid based formats \n"); + MY_PRINTF(" -sewingtolerance real: sewing tolerance for sew mode (1e-4 millimeters by default)\n"); + MY_PRINTF(" -iges 0|1 : export to iges file format 0 = off (by default), 1 = on\n"); + MY_PRINTF(" -step 0|1 : export to step file format 0 = off (by default), 1 = on\n"); + return A3D_ERROR; + } + + int iNbPkParts = 0; + PK_PART_t* pPkParts = 0; + A3DExport sExport(&iNbPkParts, &pPkParts); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + sExport.m_sTranslateToPkPartsData.m_eHealing = kA3DE_HEALING_NO; // Use healing if needed, and on-demand if possible + sExport.m_sTranslateToPkPartsData.m_eComputeAccurateEdges = kA3DE_ACCURATE_NO; + sExport.m_sTranslateToPkPartsData.m_eSimplifyGeometry = kA3DE_SIMPLIFY_NO; + sExport.m_sTranslateToPkPartsData.m_eMergeEntities = kA3DE_MERGE_NO; + sExport.m_sTranslateToPkPartsData.m_bDisjoinIfFaceFaceError = false; + sExport.m_sTranslateToPkPartsData.m_bSew = true; + sExport.m_sTranslateToPkPartsData.m_dSewingTolerance = 1e-4; + sExport.m_sTranslateToPkPartsData.m_pcPSBodyShopPath = ""; + sExport.m_sTranslateToPkPartsData.m_bUseColour2Attribute = true; + sExport.m_sTranslateToPkPartsData.m_uiNbProc = 0; //getLogicalProcessor(); + sExport.m_sExportParasolidData.m_bBStrictAssemblyStructure = true; + + bool bStep = false; + bool bIges = false; + bool bSewExchange = true; + double dSewTolerance = 0.1; + MY_CHAR* _pSrcFileName = NULL; + MY_CHAR* _pDstFileName = NULL; + MY_CHAR* _pLogFileName = NULL; + for (int iArg = 1; iArg < iArgc; iArg++) + { + if (ppcArgv[iArg] != NULL && ppcArgv[iArg][0] == '-') + { + if (!MY_STRCMP(ppcArgv[iArg], "-log") && iArg + 1 < iArgc) + { + _pLogFileName = ppcArgv[iArg + 1]; + iArg++; + } + else if (!MY_STRCMP(ppcArgv[iArg], "-healing")) + switch (MY_ATOI(ppcArgv[++iArg])) + { + case 0: sExport.m_sTranslateToPkPartsData.m_eHealing = kA3DE_HEALING_NO; break; + case 1: sExport.m_sTranslateToPkPartsData.m_eHealing = kA3DE_HEALING_YES; break; + case 2: sExport.m_sTranslateToPkPartsData.m_eHealing = kA3DE_HEALING_ONLY_IF_NOT_PARASOLID; break; + } + else if (!MY_STRCMP(ppcArgv[iArg], "-accurate")) + switch (MY_ATOI(ppcArgv[++iArg])) + { + case 0: sExport.m_sTranslateToPkPartsData.m_eComputeAccurateEdges = kA3DE_ACCURATE_NO; break; + case 1: sExport.m_sTranslateToPkPartsData.m_eComputeAccurateEdges = kA3DE_ACCURATE_YES; break; + case 2: sExport.m_sTranslateToPkPartsData.m_eComputeAccurateEdges = kA3DE_ACCURATE_ONLY_IF_NOT_PARASOLID; break; + } + else if (!MY_STRCMP(ppcArgv[iArg], "-simplify")) + switch (MY_ATOI(ppcArgv[++iArg])) + { + case 0: sExport.m_sTranslateToPkPartsData.m_eSimplifyGeometry = kA3DE_SIMPLIFY_NO; break; + case 1: sExport.m_sTranslateToPkPartsData.m_eSimplifyGeometry = kA3DE_SIMPLIFY_YES; break; + case 2: sExport.m_sTranslateToPkPartsData.m_eSimplifyGeometry = kA3DE_SIMPLIFY_ONLY_IF_NOT_PARASOLID; break; + } + else if (!MY_STRCMP(ppcArgv[iArg], "-merge")) + switch (MY_ATOI(ppcArgv[++iArg])) + { + case 0: sExport.m_sTranslateToPkPartsData.m_eMergeEntities = kA3DE_MERGE_NO; break; + case 1: sExport.m_sTranslateToPkPartsData.m_eMergeEntities = kA3DE_MERGE_YES; break; + case 2: sExport.m_sTranslateToPkPartsData.m_eMergeEntities = kA3DE_MERGE_ONLY_IF_NOT_PARASOLID; break; + } + else if (!MY_STRCMP(ppcArgv[iArg], "-disjoin")) + switch (MY_ATOI(ppcArgv[++iArg])) + { + case 0: sExport.m_sTranslateToPkPartsData.m_bDisjoinIfFaceFaceError = false; break; + case 1: sExport.m_sTranslateToPkPartsData.m_bDisjoinIfFaceFaceError = true; break; + } + else if (!MY_STRCMP(ppcArgv[iArg], "-sew")) + switch (MY_ATOI(ppcArgv[++iArg])) + { + case 0: sExport.m_sTranslateToPkPartsData.m_bSew = false; break; + case 1: sExport.m_sTranslateToPkPartsData.m_bSew = true; break; + } + else if (!MY_STRCMP(ppcArgv[iArg], "-sewingtolerance")) + { + dSewTolerance = (MY_ATOF(ppcArgv[++iArg])); + sExport.m_sTranslateToPkPartsData.m_dSewingTolerance = dSewTolerance * 0.001; + } + else if (!MY_STRCMP(ppcArgv[iArg], "-bodyshop")) + { + if ((MY_ATOI(ppcArgv[++iArg])) == 0) + sExport.m_sTranslateToPkPartsData.m_pcPSBodyShopPath = NULL; + } + else if (!MY_STRCMP(ppcArgv[iArg], "-step")) + switch (MY_ATOI(ppcArgv[++iArg])) + { + case 1: bStep = true; break; + } + else if (!MY_STRCMP(ppcArgv[iArg], "-iges")) + switch (MY_ATOI(ppcArgv[++iArg])) + { + case 1: bIges = true; break; + } + else if (!MY_STRCMP(ppcArgv[iArg], "-sewexchange")) + switch (MY_ATOI(ppcArgv[++iArg])) + { + case 0: bSewExchange = false; break; + case 1: bSewExchange = true; break; + } + } + else + { + if (_pSrcFileName == NULL) _pSrcFileName = ppcArgv[iArg]; + else if (_pDstFileName == NULL) _pDstFileName = ppcArgv[iArg]; + else if (_pLogFileName == NULL) _pLogFileName = ppcArgv[iArg]; + } + } + + // + if (_pSrcFileName == NULL) MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD); + else MY_STRCPY(acSrcFileName, _pSrcFileName); + + if (_pDstFileName == NULL) MY_STRCPY(acDstFileName, acSrcFileName); // The extension .xmt_txt will be added by the API + else MY_STRCPY(acDstFileName, _pDstFileName); + + if (_pLogFileName == NULL) MY_SPRINTF(acLogFileName, "%s.xmt_txt_Log.txt", acDstFileName); + else MY_STRCPY(acLogFileName, _pLogFileName); + GetLogFile(acLogFileName); // Initialize log file + + // + // ### INITIALIZE HOOPS EXCHANGE + // + +#ifdef _MSC_VER + const TCHAR* pcLibPath = _T(""); // As Documented, working directory must be install directory. +#else + const char* pcLibPath = ""; +#endif + A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(pcLibPath); + CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus); + + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + + //Check Parsolid Schema path + char *workbuff = getenv("P_SCHEMA"); + if (workbuff) + { + PrintLogMessage("P_SCHEMA="); PrintLogMessage(workbuff); PrintLogMessage("\n"); + } + else + PrintLogMessage("P_SCHEMA= missing\n"); + + // initialize Parasolid + PrintLogMessage("Initializing Parasolid...\n"); + if (!ParasolidInitialize()) + { + PrintLogError(0, "Parasolid initialization failure\n"); + return A3D_ERROR; + } + + const struct ParasolidCleaner + { + ~ParasolidCleaner() + { + ParasolidTerminate(); + } + } sParasolidCleaner; + + // + // ### PROCESS SAMPLE CODE + // + + // Import Input CAD file + A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters + if (bStep || bIges) + { + // direct export to Iges or Step +#ifdef _MSC_VER + A3DUniChar sDirectOutputPath[_MAX_PATH]; + swprintf(sDirectOutputPath, _MAX_PATH, (bIges) ? _T("%s.igs") : _T("%s.stp"), acDstFileName); +#else + A3DUTF8Char sDirectOutputPath[_MAX_PATH]; + sprintf(sDirectOutputPath, (bIges) ? "%s.igs" : "%s.stp", acDstFileName); +#endif + + A3DExport sDirectExport(sDirectOutputPath); + PrintLogMessage("Conversion...\n"); + CHECK_RET(sHoopsExchangeLoader.Convert(sImport, sDirectExport)); + return A3D_SUCCESS; + } + + // ---------------------------------------------------------------------------- + // export to parasolid with the bridge + sImport.m_sLoadData.m_sSpecifics.m_sParasolid.m_bKeepParsedEntities = true; + sImport.m_sLoadData.m_sSpecifics.m_sStep.m_bHealOrientations = true; + sImport.m_sLoadData.m_sGeneral.m_eReadGeomTessMode = kA3DReadGeomAndTess; + sImport.m_sLoadData.m_sTessellation.m_eTessellationLevelOfDetail = kA3DTessLODMedium; + PrintLogMessage("TranslateToPkParts...\n"); + A3DStatus iRet = sHoopsExchangeLoader.Import(sImport); + if (iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS) + CHECK_RET(iRet); + + if (bSewExchange) + { + A3DAsmModelFileData sModelFileData; + A3D_INITIALIZE_DATA(A3DAsmModelFileData, sModelFileData); + CHECK_RET(A3DAsmModelFileGet(sHoopsExchangeLoader.m_psModelFile, &sModelFileData)); + A3DSewOptionsData sSewData; + A3D_INITIALIZE_DATA(A3DSewOptionsData, sSewData); + if (sModelFileData.m_eModellerType != kA3DModellerJt + && sModelFileData.m_eModellerType != kA3DModellerSlw + && sModelFileData.m_eModellerType != kA3DModellerUnigraphics + && sModelFileData.m_eModellerType != kA3DModellerParasolid + && sModelFileData.m_eModellerType != kA3DModellerSE) + CHECK_RET(A3DAsmModelFileSew(&sHoopsExchangeLoader.m_psModelFile, dSewTolerance, &sSewData)); + + CHECK_RET(A3DAsmModelFileGet(nullptr, &sModelFileData)); + } + + // ---------------------------------------------------------------------------- + switch (sHoopsExchangeLoader.Export(sExport)) + { + case A3D_SUCCESS: break; + case A3D_HEPB_MISSING: PrintLogError(0, "Can't load HEPB library"); return A3D_ERROR; + case A3D_PARASOLID_ERROR_970: PrintLogError(0, "Can't access Parasolid schema"); return A3D_ERROR; + case A3D_BODYSHOP_MISSING: PrintLogError(0, "Can't load BodyShop library"); return A3D_ERROR; + case A3D_WRITE_KEEPPARSEDENTITIES_DISABLED: PrintLogError(0, "KeepParsedEntities reading option must be enabled when using TranslateToPkParts"); return A3D_ERROR; + default: PrintLogError(0, "TranslateToPkParts Failure"); return A3D_ERROR; + } + + A3DUTF8Char acOutPutKeyUTF8[_MAX_PATH]; +#ifdef _MSC_VER + A3DMiscUTF16ToUTF8(acDstFileName, acOutPutKeyUTF8); +#else + MY_STRCPY(acOutPutKeyUTF8, acDstFileName); +#endif + + if (!iNbPkParts) + { + PrintLogError(0, "No part to transmit\n"); + return A3D_SUCCESS; + } + + PrintLogMessage("PK_PART_transmit...\n"); + + PK_PART_transmit_o_t sTransmitOptions; + PK_PART_transmit_o_m(sTransmitOptions); + sTransmitOptions.transmit_format = PK_transmit_format_text_c; + // in order to use PK_PART_transmit_u (for Unicode names), an Unicode frustrum must be defined + PK_ERROR_code_t eTransmitStatus = PK_PART_transmit(iNbPkParts, pPkParts, acOutPutKeyUTF8, &sTransmitOptions); + + // Free Parasolid table (user has to free this pointer) + PK_MEMORY_free(pPkParts); + if (eTransmitStatus) + return eTransmitStatus; + // + // ### TERMINATE HOOPS EXCHANGE + // + + // Check memory allocations + return (int)ListLeaks(); +} diff --git a/exchange/exchangesource/TranslateToPkParts/TranslateToPkParts.vcxproj b/exchange/exchangesource/TranslateToPkParts/TranslateToPkParts.vcxproj new file mode 100644 index 0000000..4ee21c3 --- /dev/null +++ b/exchange/exchangesource/TranslateToPkParts/TranslateToPkParts.vcxproj @@ -0,0 +1,182 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {D77B7B37-01D4-463A-B24F-4EDF3D5B979B} + TranslateToPkParts + 10.0 + + + + Application + v145 + true + + + Application + v145 + + + Application + v145 + true + + + Application + v145 + + + + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + $(PARASOLID_INSTALL_DIR)\base;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;PARASOLID_INSTALL_DIR=$(PARASOLID_INSTALL_DIR);%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + Level4 + ProgramDatabase + false + + + legacy_stdio_float_rounding.obj;pskernel.lib;%(AdditionalDependencies) + $(PARASOLID_INSTALL_DIR)\base\dll;%(AdditionalLibraryDirectories) + true + MachineX86 + + + + + X64 + + + Disabled + $(PARASOLID_INSTALL_DIR_64)\base;%(AdditionalIncludeDirectories) + WIN32;;_DEBUG;_CONSOLE;PARASOLID_INSTALL_DIR=$(PARASOLID_INSTALL_DIR_64);%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + Level4 + ProgramDatabase + false + + + legacy_stdio_float_rounding.obj;pskernel.lib;%(AdditionalDependencies) + $(PARASOLID_INSTALL_DIR_64)\base\dll;%(AdditionalLibraryDirectories) + true + MachineX64 + + + + + MaxSpeed + true + $(PARASOLID_INSTALL_DIR)\base;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;PARASOLID_INSTALL_DIR=$(PARASOLID_INSTALL_DIR);%(PreprocessorDefinitions) + MultiThreadedDLL + true + Level4 + ProgramDatabase + false + + + legacy_stdio_float_rounding.obj;pskernel.lib;%(AdditionalDependencies) + $(PARASOLID_INSTALL_DIR)\base\dll;%(AdditionalLibraryDirectories) + true + true + true + MachineX86 + + + + + X64 + + + MaxSpeed + true + $(PARASOLID_INSTALL_DIR_64)\base;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;PARASOLID_INSTALL_DIR=$(PARASOLID_INSTALL_DIR_64);%(PreprocessorDefinitions) + MultiThreadedDLL + true + Level4 + ProgramDatabase + false + + + legacy_stdio_float_rounding.obj;pskernel.lib;%(AdditionalDependencies) + $(PARASOLID_INSTALL_DIR_64)\base\dll;%(AdditionalLibraryDirectories) + true + true + true + MachineX64 + + + + + + 4267;%(DisableSpecificWarnings) + 4267;%(DisableSpecificWarnings) + 4267;%(DisableSpecificWarnings) + 4267;%(DisableSpecificWarnings) + + + 4267;%(DisableSpecificWarnings) + 4267;%(DisableSpecificWarnings) + 4267;%(DisableSpecificWarnings) + 4267;%(DisableSpecificWarnings) + + + _UNICODE;UNICODE;WIN32;%(PreprocessorDefinitions) + _UNICODE;UNICODE;WIN32;%(PreprocessorDefinitions) + _UNICODE;UNICODE;WIN32;%(PreprocessorDefinitions) + _UNICODE;UNICODE;WIN32;%(PreprocessorDefinitions) + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/TranslateToPkParts/TranslateToPkParts.vcxproj.filters b/exchange/exchangesource/TranslateToPkParts/TranslateToPkParts.vcxproj.filters new file mode 100644 index 0000000..04b14f6 --- /dev/null +++ b/exchange/exchangesource/TranslateToPkParts/TranslateToPkParts.vcxproj.filters @@ -0,0 +1,31 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/exchange/exchangesource/TranslateToPkParts/fg.c b/exchange/exchangesource/TranslateToPkParts/fg.c new file mode 100644 index 0000000..c3adf91 --- /dev/null +++ b/exchange/exchangesource/TranslateToPkParts/fg.c @@ -0,0 +1,8 @@ +#ifdef WIN32 +# pragma warning(disable: 4018 4100 4244) +#endif + +#ifndef PARASOLID_INSTALL_DIR +# error PARASOLID_INSTALL_DIR environment variable required +#endif +#include \ No newline at end of file diff --git a/exchange/exchangesource/TranslateToPkParts/frustrum.c b/exchange/exchangesource/TranslateToPkParts/frustrum.c new file mode 100644 index 0000000..342c884 --- /dev/null +++ b/exchange/exchangesource/TranslateToPkParts/frustrum.c @@ -0,0 +1,15 @@ +#ifdef WIN32 +# pragma warning(disable: 4018 4100 4244 4701 4703) +# ifdef _UNICODE +# undef _UNICODE +# endif + +# ifdef UNICODE +# undef UNICODE +# endif +#endif + +#ifndef PARASOLID_INSTALL_DIR +# error PARASOLID_INSTALL_DIR environment variable required +#endif +#include \ No newline at end of file diff --git a/exchange/exchangesource/TranslateToPkParts/frustrum_delta.c b/exchange/exchangesource/TranslateToPkParts/frustrum_delta.c new file mode 100644 index 0000000..410e0c6 --- /dev/null +++ b/exchange/exchangesource/TranslateToPkParts/frustrum_delta.c @@ -0,0 +1,5 @@ + +#ifndef PARASOLID_INSTALL_DIR +#error PARASOLID_INSTALL_DIR environment variable required +#endif +#include \ No newline at end of file diff --git a/exchange/exchangesource/Viewer/A3DVector.h b/exchange/exchangesource/Viewer/A3DVector.h new file mode 100644 index 0000000..f486297 --- /dev/null +++ b/exchange/exchangesource/Viewer/A3DVector.h @@ -0,0 +1,211 @@ +#ifndef A3DVECTOR_H +#define A3DVECTOR_H + +#include +#include +#include +#include +#include +#include +#include + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +class A3DVector3d +{ +public: + double x; + double y; + double z; + + ////////////////////////////////////// + ////////////////////////////////////// + A3DVector3d() + { + // EMPTY + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DVector3d(double dX, double dY, double dZ) : + x(dX), + y(dY), + z(dZ) + { + // EMPTY + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DVector3d(const A3DVector3dData& sV) : + x(sV.m_dX), + y(sV.m_dY), + z(sV.m_dZ) + { + // EMPTY + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DVector3d(const A3DVector3d& toCopy) : + x(toCopy.x), y(toCopy.y), z(toCopy.z) + { + // EMPTY + } + + ////////////////////////////////////// + ////////////////////////////////////// + void set(double dX, double dY, double dZ) + { + x = dX; + y = dY; + z = dZ; + } + + + ////////////////////////////////////// + ////////////////////////////////////// + double Length() const + { + return sqrt(x*x + y*y + z*z); + } + + ////////////////////////////////////// + ////////////////////////////////////// + double LenghtSquared() const + { + return x*x + y*y + z*z; + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DStatus normalize() + { + double d = this->Length(); + if(d == 0) + { + return A3D_ERROR; + } + + x /= d; + y /= d; + z /= d; + + return A3D_SUCCESS; + } + + ////////////////////////////////////// + ////////////////////////////////////// + double Distance(const A3DVector3d& sOther) const + { + return sqrt(this->SquareDistance(sOther)); + } + + ////////////////////////////////////// + ////////////////////////////////////// + double SquareDistance(const A3DVector3d& sOther) const + { + double d=0,dd; + dd = x; dd -= sOther.x; dd *= dd; d += dd; + dd = y; dd -= sOther.y; dd *= dd; d += dd; + dd = z; dd -= sOther.z; dd *= dd; d += dd; + return d; + } + + ////////////////////////////////////// + ////////////////////////////////////// + double Dot(const A3DVector3d& sOther) const + { + return x*sOther.x + y*sOther.y + z*sOther.z; + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DVector3d Cross(const A3DVector3d& sOther) + { + return A3DVector3d( + y * sOther.z - z * sOther.y, + z * sOther.x - x * sOther.z, + x * sOther.y - y * sOther.x + ); + } + + + ////////////////////////////////////// + ////////////////////////////////////// + A3DVector3d& operator += ( const A3DVector3d& sOther ) + { + x += sOther.x; + y += sOther.y; + z += sOther.z; + return *this; + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DVector3d& operator -= ( const A3DVector3d& sOther ) + { + x -= sOther.x; + y -= sOther.y; + z -= sOther.z; + return *this; + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DVector3d operator + ( const A3DVector3d& sOther ) const + { + return A3DVector3d(x+sOther.x, y+sOther.y, z+sOther.z); + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DVector3d operator - ( const A3DVector3d& sOther ) const + { + return A3DVector3d(x-sOther.x, y-sOther.y, z-sOther.z); + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DVector3d& operator *= ( double dValue ) + { + x *= dValue; + y *= dValue; + z *= dValue; + return *this; + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DVector3d& operator /= ( double dValue ) + { + x /= dValue; + y /= dValue; + z /= dValue; + return *this; + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DVector3d operator * ( double dValue ) const + { + return A3DVector3d( + x*dValue, + y*dValue, + z*dValue + ); + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DVector3d operator / ( double dValue ) const + { + return A3DVector3d( + x / dValue, + y / dValue, + z / dValue + ); + } +}; + +#endif diff --git a/exchange/exchangesource/Viewer/BrepTraverse.h b/exchange/exchangesource/Viewer/BrepTraverse.h new file mode 100644 index 0000000..41d52b7 --- /dev/null +++ b/exchange/exchangesource/Viewer/BrepTraverse.h @@ -0,0 +1,146 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef TOPO_TRAVERSE +#define TOPO_TRAVERSE + +#include "Connector.h" + +class A3DVisitor; + +//////////////////////////////////////////////// +// Brep +//////////////////////////////////////////////// +class A3DBrepDataConnector : public A3DConnector +{ +public: + + A3DTopoBrepDataData m_sBrepData; + + A3DBrepDataConnector(const A3DTopoBrepData *pBrep); + ~A3DBrepDataConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + +//////////////////////////////////////////////// +// connex +//////////////////////////////////////////////// +class A3DConnexConnector : public A3DConnector +{ +public: + A3DTopoConnexData m_sConnexData; + + A3DConnexConnector(const A3DTopoConnex *pConnex); + ~A3DConnexConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + +//////////////////////////////////////////////// +// Shell +//////////////////////////////////////////////// +class A3DShellConnector : public A3DConnector +{ +public: + A3DTopoShellData m_sShellData; + + A3DShellConnector(const A3DTopoShell *pShell); + ~A3DShellConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + +//////////////////////////////////////////////// +// Face +//////////////////////////////////////////////// +class A3DFaceConnector : public A3DConnector +{ +public: + A3DTopoFaceData m_sFaceData; + + A3DFaceConnector(const A3DTopoFace *pFace); + ~A3DFaceConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + +//////////////////////////////////////////////// +// Loop +//////////////////////////////////////////////// +class A3DLoopConnector : public A3DConnector +{ +public: + A3DTopoLoopData m_sLoopData; + + A3DLoopConnector(const A3DTopoLoop *pLoop); + ~A3DLoopConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + +//////////////////////////////////////////////// +// CoEdge +//////////////////////////////////////////////// +class A3DCoEdgeConnector : public A3DConnector +{ +public: + A3DTopoCoEdgeData m_sCoEdgeData; + + A3DCoEdgeConnector(const A3DTopoCoEdge *pCoEdge); + ~A3DCoEdgeConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + +//////////////////////////////////////////////// +// Edge +//////////////////////////////////////////////// +class A3DEdgeConnector : public A3DConnector +{ +public: + A3DTopoEdgeData m_sEdgeData; + + A3DEdgeConnector(const A3DTopoEdge *pEdge); + ~A3DEdgeConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + +//////////////////////////////////////////////// +// Vertex +//////////////////////////////////////////////// +class A3DUniqueVertexConnector : public A3DConnector +{ +public: + + A3DTopoUniqueVertexData m_sVertexData; + + A3DUniqueVertexConnector(const A3DTopoVertex *pVertex); + ~A3DUniqueVertexConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + + +class A3DMultipleVertexConnector : public A3DConnector +{ +public: + A3DTopoMultipleVertexData m_sVertexData; + + A3DMultipleVertexConnector(const A3DTopoVertex *pVertex); + ~A3DMultipleVertexConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor) const; +}; + + +#endif \ No newline at end of file diff --git a/exchange/exchangesource/Viewer/CascadedAttributeConnector.h b/exchange/exchangesource/Viewer/CascadedAttributeConnector.h new file mode 100644 index 0000000..ca51b19 --- /dev/null +++ b/exchange/exchangesource/Viewer/CascadedAttributeConnector.h @@ -0,0 +1,59 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_CASCADED_ATTRIBUTE_CLASS +#define A3D_CASCADED_ATTRIBUTE_CLASS + +#include "Connector.h" + + +class ColorMaterialsConnector : public A3DConnector +{ + + A3DMiscCascadedAttributesData m_sCascadedAttributeData; + +public: + ColorMaterialsConnector(A3DMiscCascadedAttributes* pAttr); + + virtual ~ColorMaterialsConnector(); + + bool IsShow(); + + bool IsRemoved(); + + bool IsTexture(); + + bool IsMaterial(); + //A3DStatus GetMaterial(A3DMaterial& sMaterial); + enum eMaterialState + { + eBAD_Emissive = 1, + eBAD_Diffuse = 2, + eBAD_Ambient = 4, + eBAD_Specular = 8 + }; + + + int GetMaterial(double dEmisive[4], double dDiffuse[4], double dAmbient[4], double dSpecular[4], double& dShininess ); + + bool IsRGBColor(); + A3DStatus GetRGB(double adRG[3]); + //From 0 (transparent) to 255 (opaque). + bool IsTranparent(); + A3DStatus Transparency(unsigned char& cTransparenty); + + A3DStatus Compare( + ColorMaterialsConnector const & sOtherCascadedAttribute, + bool& bSameColor, + bool& bSameFaceColor); + +}; +#endif diff --git a/exchange/exchangesource/Viewer/ComputeHLR.cpp b/exchange/exchangesource/Viewer/ComputeHLR.cpp new file mode 100644 index 0000000..8cb8154 --- /dev/null +++ b/exchange/exchangesource/Viewer/ComputeHLR.cpp @@ -0,0 +1,299 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include "Viewer.h" +#include + +//###################################################################################################################### +void DrawError(char const * acMessage, A3DStatus sStatus); + +//###################################################################################################################### +void stCleanHLRResults(A3DHLRRepresentationItemData & sRIData) +{ + unsigned int uiCrv, uiNbCrv = sRIData.m_uiNumberHLRCurves; + for (uiCrv = 0; uiCrv +#include +#else +#include "GL/gl.h" +#include "GL/glu.h" +#endif +static void CALLBACK tessBegin(GLenum which) +{ + glBegin(which); +} + +static void CALLBACK tessEnd() +{ + glEnd(); +} + +static void CALLBACK tessVertex(const GLvoid *data) +{ + const GLdouble *ptr = (const GLdouble*)data; + glVertex3dv(ptr); +} + +static void CALLBACK tessError(GLenum errorCode) +{ + const GLubyte * errorStr = gluErrorString(errorCode); + DrawError( (char const *)errorStr, A3D_ERROR); +} + +//###################################################################################################################### +void stDrawPolyline(std::vector apPoly) +{ + for (auto pPoly : apPoly) + { + A3DCrvPolyLineData sPolyData; + A3D_INITIALIZE_DATA(A3DCrvPolyLineData, sPolyData); + A3DCrvPolyLineGet(pPoly, &sPolyData); + + glBegin(GL_LINE_STRIP); + A3DVector3dData const * pPt = sPolyData.m_pPts; + for (A3DUns32 uiPt = 0; uiPt < sPolyData.m_uiSize; uiPt++, pPt++) + { + glVertex3d(pPt->m_dX, pPt->m_dY, pPt->m_dZ); + } + glEnd(); + + A3DCrvPolyLineGet(nullptr, &sPolyData); + } +} + +#include +//###################################################################################################################### +void ComputeHLR( A3DAsmModelFile const * pModelFile, + A3DMkpView const *pActiveView, + A3DHLRViewPlaneData const &sHLRViewPlaneData, + GLuint &uiHLRDisplayList, + GLuint &uiHLRTanEdgeDisplayList, + GLuint &uiHLRHiddenDisplayList, + GLuint &uiHLRHiddenTanEdgeDisplayList, + GLuint &uiHLRSectionDisplayList) +{ + A3DHLROptionsData sHLROptionsData; + A3D_INITIALIZE_DATA(A3DHLROptionsData, sHLROptionsData); + sHLROptionsData.m_bTangentEdgeDetect = true; + sHLROptionsData.m_dTangentEdgeAngle = 0.0001*M_PI / 180.; + + A3DUns32 uiNumberHLRRepItem = 0; + A3DHLRRepresentationItem **apHLRRepItem = nullptr; + A3DStatus iRet = A3DComputeOrthoHLROnModelFile3(pModelFile, + pActiveView, + &sHLRViewPlaneData, + &sHLROptionsData, + &uiNumberHLRRepItem, + &apHLRRepItem); + if (iRet != A3D_SUCCESS) + { + DrawError("A3DComputeOrthoHLROnModelFile3 return error", iRet); + return; + } + + std::vector apVisible, apTanEdge, apHidden, apHiddenTanEdge; + + // Section + glDeleteLists(uiHLRSectionDisplayList, 1); + uiHLRSectionDisplayList = glGenLists(1); + glNewList(uiHLRSectionDisplayList, GL_COMPILE); + glPushAttrib(GL_BLEND | GL_LINE_STIPPLE | GL_LIGHTING_BIT | GL_LINE_BIT | GL_TEXTURE_BIT); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_TEXTURE); + glDisable(GL_LIGHTING); + glShadeModel(GL_FLAT); + glColor4f(8., 0., 0., 0.5); + glLineWidth(2); + + for (A3DUns32 uiResultRI = 0; uiResultRI < uiNumberHLRRepItem; uiResultRI++) + { + A3DHLRRepresentationItem const * pHLRRI = apHLRRepItem[uiResultRI]; + A3DHLRRepresentationItemData sRIData; + A3D_INITIALIZE_DATA(A3DHLRRepresentationItemData, sRIData); + A3DHLRRepresentationItemGet(pHLRRI, &sRIData); + + unsigned int uiCrv, uiNbCrv = sRIData.m_uiNumberHLRCurves; + for (uiCrv = 0; uiCrv < uiNbCrv; uiCrv++) + { + A3DHLRCurveData const & sCurveData = sRIData.m_pppHLRCurves[uiCrv]; + if (sCurveData.m_bIsHidden) + { + if (sCurveData.m_bIsTanEdge && !sCurveData.m_bIsSilhouette) + apHiddenTanEdge.push_back(sCurveData.m_pProjectedPolyLine); + else + apHidden.push_back(sCurveData.m_pProjectedPolyLine); + } + else + { + if (sCurveData.m_bIsTanEdge && !sCurveData.m_bIsSilhouette) + apTanEdge.push_back(sCurveData.m_pProjectedPolyLine); + else + apVisible.push_back(sCurveData.m_pProjectedPolyLine); + } + } + + // Section face treatment ... + A3DUns32 uiNbFace = sRIData.m_uiNumberSectionFace; + for (A3DUns32 uiFace = 0; uiFace < uiNbFace; ++uiFace) + { + A3DHLRSectionFaceData const & sFaceData = sRIData.m_pHLRSectionFaces[uiFace]; + + GLUtriangulatorObj *tess = gluNewTess(); + gluTessCallback(tess, GLU_TESS_VERTEX, (GLvoid(CALLBACK *) ()) &tessVertex); + gluTessCallback(tess, GLU_TESS_BEGIN, (GLvoid(CALLBACK *) ()) &tessBegin); + gluTessCallback(tess, GLU_TESS_END, (GLvoid(CALLBACK *) ()) &tessEnd); + gluTessCallback(tess, GLU_TESS_ERROR, (void (CALLBACK *)())tessError); + + std::vector< A3DCrvPolyLineData > asObjToDelete; + + gluTessBeginPolygon(tess, nullptr); + + for (A3DUns32 uiLoop = 0; uiLoop < sFaceData.m_uiNbLoop; ++uiLoop) + { + gluTessBeginContour(tess); + + A3DUns32 uiNbLoopCrv = sFaceData.m_puiLoopSize[uiLoop]; + for (A3DUns32 uiLoopCrv = 0; uiLoopCrv < uiNbLoopCrv; ++uiLoopCrv) + { + A3DUns32 uiCrvIndex = sFaceData.m_puiCurveIndex[uiLoop][uiLoopCrv]; + A3DBool bCrvOrient = sFaceData.m_pbCurveOrientation[uiLoop][uiLoopCrv]; + + A3DHLRCurveData const & sCurveData = sRIData.m_pppHLRCurves[uiCrvIndex]; + + + A3DCrvPolyLineData sPolyData; + A3D_INITIALIZE_DATA(A3DCrvPolyLineData, sPolyData); + A3DCrvPolyLineGet(sCurveData.m_pProjectedPolyLine, &sPolyData); + asObjToDelete.push_back(sPolyData); + + if (bCrvOrient) + { + A3DVector3dData const *pPt = sPolyData.m_pPts; + for (A3DUns32 uiPt = 0; uiPt < sPolyData.m_uiSize; uiPt++, pPt++) + { + gluTessVertex(tess, (GLdouble*)&pPt->m_dX, (void*)&pPt->m_dX); + } + } + else + { + A3DVector3dData const *pPt = &sPolyData.m_pPts[sPolyData.m_uiSize - 1]; + for (A3DUns32 uiPt = 0; uiPt < sPolyData.m_uiSize; uiPt++, pPt--) + { + gluTessVertex(tess, (GLdouble*)&pPt->m_dX, (void*)&pPt->m_dX); + } + } + } + + gluTessEndContour(tess); + } + + gluTessEndPolygon(tess); + gluDeleteTess(tess); + + for (size_t i = 0; i < asObjToDelete.size(); ++i) + { + A3DCrvPolyLineGet(nullptr, &asObjToDelete[i]); + } + } + + A3DHLRRepresentationItemGet(nullptr, &sRIData); + } + + glPopAttrib(); + glEndList(); + + // Visible ... + glDeleteLists(uiHLRDisplayList, 1); + uiHLRDisplayList = glGenLists(1); + glNewList(uiHLRDisplayList, GL_COMPILE); + glPushAttrib(GL_LINE_STIPPLE | GL_LIGHTING_BIT | GL_LINE_BIT | GL_TEXTURE_BIT); + glDisable(GL_TEXTURE); + glDisable(GL_LIGHTING); + glColor3f(1., 1., 1.); // white + glLineWidth(2); + stDrawPolyline(apVisible); + glPopAttrib(); + glEndList(); + + // Visible TanEdge + glDeleteLists(uiHLRTanEdgeDisplayList, 1); + uiHLRTanEdgeDisplayList = glGenLists(1); + glNewList(uiHLRTanEdgeDisplayList, GL_COMPILE); + glPushAttrib(GL_LINE_STIPPLE | GL_LIGHTING_BIT | GL_LINE_BIT | GL_TEXTURE_BIT); + glDisable(GL_TEXTURE); + glDisable(GL_LIGHTING); + glColor3f(1., 1., 0.); // white + glLineWidth(2); + stDrawPolyline(apTanEdge); + glPopAttrib(); + glEndList(); + + // Hidden + glDeleteLists(uiHLRHiddenDisplayList, 1); + uiHLRHiddenDisplayList = glGenLists(1); + glNewList(uiHLRHiddenDisplayList, GL_COMPILE); + glPushAttrib(GL_LINE_STIPPLE | GL_LIGHTING_BIT | GL_LINE_BIT | GL_TEXTURE_BIT); + glDisable(GL_TEXTURE); + glDisable(GL_LIGHTING); + glLineStipple(2, 0xAAAA); + glEnable(GL_LINE_STIPPLE); + glColor3f(0.0, 0.5, 0.7); // midnight blue + glLineWidth(1); + stDrawPolyline(apHidden); + glPopAttrib(); + glEndList(); + + // Hidden Tan Edge + glDeleteLists(uiHLRHiddenTanEdgeDisplayList, 1); + uiHLRHiddenTanEdgeDisplayList = glGenLists(1); + glNewList(uiHLRHiddenTanEdgeDisplayList, GL_COMPILE); + glPushAttrib(GL_LINE_STIPPLE | GL_LIGHTING_BIT | GL_LINE_BIT | GL_TEXTURE_BIT); + glDisable(GL_TEXTURE); + glDisable(GL_LIGHTING); + glLineStipple(2, 0xAAAA); + glEnable(GL_LINE_STIPPLE); + //glColor3f(0.0, 0.5, 0.7); // midnight blue + glColor3f(1., 1., 0.); // white + glLineWidth(1); + stDrawPolyline(apHiddenTanEdge); + glPopAttrib(); + glEndList(); + + // Delete geometry + for (A3DUns32 uiResultRI = 0; uiResultRI < uiNumberHLRRepItem; uiResultRI++) + { + A3DHLRRepresentationItem const * pHLRRI = apHLRRepItem[uiResultRI]; + A3DHLRRepresentationItemData sRIData; + A3D_INITIALIZE_DATA(A3DHLRRepresentationItemData, sRIData); + A3DHLRRepresentationItemGet(pHLRRI, &sRIData); + + stCleanHLRResults(sRIData); + + A3DHLRRepresentationItemGet(nullptr, &sRIData); + } + + // Delete HLRstructure + A3DComputeOrthoHLROnModelFile3(nullptr, nullptr, nullptr, nullptr, &uiNumberHLRRepItem, &apHLRRepItem); +} diff --git a/exchange/exchangesource/Viewer/ComputeSection.cpp b/exchange/exchangesource/Viewer/ComputeSection.cpp new file mode 100644 index 0000000..69797c0 --- /dev/null +++ b/exchange/exchangesource/Viewer/ComputeSection.cpp @@ -0,0 +1,133 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include +#include "Viewer.h" + + +static A3DUns32 NumberOfSections = 0; + +//###################################################################################################################### +// create RISet with the planar section +A3DRiSet* stCreateRISet(A3DRiSet * pRISectionElements) +{ + A3DRiSet* pp = nullptr; + + A3DRiSetData sData; + A3D_INITIALIZE_DATA(A3DRiSetData, sData); + + A3DRiSetData sSectionData; + A3D_INITIALIZE_DATA(A3DRiSetData, sSectionData); + A3DRiSetGet(pRISectionElements, &sSectionData); + + sData.m_uiRepItemsSize = sSectionData.m_uiRepItemsSize; + sData.m_ppRepItems = new A3DRiRepresentationItem*[sSectionData.m_uiRepItemsSize]; + + for(A3DUns32 ui = 0; ui < sSectionData.m_uiRepItemsSize; ++ui) + { + sData.m_ppRepItems[ui] = sSectionData.m_ppRepItems[ui]; + } + + A3DRiSetCreate(&sData, &pp); + + A3DRiSetGet(nullptr, &sSectionData); + delete [] sData.m_ppRepItems; + + return pp; +} + +//###################################################################################################################### +// create part definition +A3DAsmPartDefinition* stCreatePart(A3DRiSet** pRISectionElements) +{ + + A3DAsmPartDefinition* pp = nullptr; + A3DAsmPartDefinitionData sData; + A3D_INITIALIZE_DATA(A3DAsmPartDefinitionData, sData); + + sData.m_uiRepItemsSize = NumberOfSections; + sData.m_ppRepItems = new A3DRiRepresentationItem*[sData.m_uiRepItemsSize]; + + for(A3DUns32 iSet = 0; iSet < NumberOfSections; ++iSet) + { + A3DRiSet* p = nullptr; + p = stCreateRISet(pRISectionElements[iSet]); + if(p != nullptr) + sData.m_ppRepItems[iSet] = p; + } + + A3DAsmPartDefinitionCreate(&sData, &pp); + delete [] sData.m_ppRepItems; + + return pp; +} + + +//###################################################################################################################### +// create product occurence +A3DAsmProductOccurrence* stCreateOccurrence(A3DRiSet** pRISectionElements) +{ + A3DAsmProductOccurrence* pp = nullptr; + + A3DAsmPartDefinition* p = stCreatePart(pRISectionElements); + if(p != nullptr) + { + A3DAsmProductOccurrenceData sData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sData); + + sData.m_pPart = p; + + A3DAsmProductOccurrenceCreate(&sData, &pp); + } + + return pp; +} + +//###################################################################################################################### +// create model file +A3DAsmModelFile* stCreateModel(A3DRiSet** pRISectionElements) +{ + A3DAsmModelFile* pp = nullptr; + + A3DAsmProductOccurrence* p = stCreateOccurrence(pRISectionElements); + if(p != nullptr) + { + A3DAsmModelFileData sData; + A3D_INITIALIZE_DATA(A3DAsmModelFileData, sData); + + sData.m_uiPOccurrencesSize = 1; + sData.m_dUnit = 1.0; + sData.m_ppPOccurrences = &p; + + A3DAsmModelFileCreate(&sData, &pp); + } + + return pp; +} + +//###################################################################################################################### +// create an empty model file containing the section of the previous model file +A3DAsmModelFile* ComputeSection(A3DAsmModelFile* pModelFile, A3DPlanarSectionData sSectionParametersData) +{ + A3DAsmModelFile* pSectionnedModelFile = nullptr; + A3DRiSet** ppRISectionElements = nullptr; + + A3DStatus iRet = A3DComputePlanarSectionOnModelFile(pModelFile, &sSectionParametersData, &NumberOfSections, &ppRISectionElements); + + if (iRet == A3D_SUCCESS) + { + pSectionnedModelFile = stCreateModel(ppRISectionElements); + A3DComputePlanarSectionOnModelFile(nullptr, &sSectionParametersData, &NumberOfSections, &ppRISectionElements); + } + + return pSectionnedModelFile; +} diff --git a/exchange/exchangesource/Viewer/Connector.h b/exchange/exchangesource/Viewer/Connector.h new file mode 100644 index 0000000..bc1592f --- /dev/null +++ b/exchange/exchangesource/Viewer/Connector.h @@ -0,0 +1,39 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_CONNECTOR +#define A3D_CONNECTOR + +#include +#ifdef TF_A3DLIBS +# define A3DAPI_INTERNAL +#else +#include +#endif +#ifndef WIN32 +#define strcpy_s(dst, dst_size, src) strcpy((dst), (src)) +#endif +class A3DConnector +{ +protected: + + const A3DEntity* m_pEntity; + + A3DConnector(const A3DEntity* pEntity) : m_pEntity(pEntity) {} + A3DConnector() : m_pEntity(NULL) {}; +public: + + const A3DEntity* GetA3DEntity() const { return m_pEntity; } + virtual A3DEEntityType GetType() const { return kA3DTypeUnknown; } + +}; + +#endif \ No newline at end of file diff --git a/exchange/exchangesource/Viewer/Draw.cpp b/exchange/exchangesource/Viewer/Draw.cpp new file mode 100644 index 0000000..343afc4 --- /dev/null +++ b/exchange/exchangesource/Viewer/Draw.cpp @@ -0,0 +1,3819 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include +#include + +#include "callback_opengl.h" + +#define VIEWS + + + +//###################################################################################################################### +static bool stbUseCallbacks = true; +static A3DDrawCallbacksData stsCallbacks; +static bool stbCallbacksInitialized = false; +static A3DBoundingBoxData* stpsBoundingBox = NULL; +static bool stbDraw3D = false; +static bool stbDrawMarkups = false; + +//###################################################################################################################### +static void stDefaultPushMatrix() {} +static void stDefaultPopMatrix() {} +static void stDefaultMultMatrix(const A3DDouble /*adMatrix*/[16]) {} +static void stDefaultBegin(A3DEDrawBeginEndType /*eType*/, const A3DUTF8Char* /*pcName*/, A3DUns32 /*uiTrianglesCount*/) {} +static void stDefaultEnd(A3DEDrawBeginEndType /*eType*/) {} +static void stDefaultSetTessellationPoints(const A3DVector3dData* /*pasPoint*/, A3DUns32 /*uiPointsSize*/) {} +#ifdef A3D_DRAW_WITH_INDICES +static void stDefaultSetTessellationNormals(const A3DVector3dData* /*pasNormal*/, A3DUns32 /*uiPointsSize*/) {} +#endif +static void stDefaultTriangle(const A3DVector3dData* /*pasNormals*/, const A3DVector3dData* /*pasPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleFan(const A3DVector3dData* /*pasNormals*/, const A3DVector3dData* /*pasPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleStripe(const A3DVector3dData* /*pasNormals*/, const A3DVector3dData* /*pasPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleOneNormal(const A3DVector3dData* /*pasNormals*/, const A3DVector3dData* /*pasPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleFanOneNormal(const A3DVector3dData* /*psNormal*/, const A3DVector3dData* /*pasPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleStripeOneNormal(const A3DVector3dData* /*psNormal*/, const A3DVector3dData* /*pasPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleTextured(const A3DVector3dData* /*pasNormals*/, const A3DVector3dData* /*pasPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleFanTextured(const A3DVector3dData* /*pasNormals*/, const A3DVector3dData* /*pasPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleStripeTextured(const A3DVector3dData* /*pasNormals*/, const A3DVector3dData* /*pasPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleOneNormalTextured(const A3DVector3dData* /*pasNormals*/, const A3DVector3dData* /*pasPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleFanOneNormalTextured(const A3DVector3dData* /*psNormal*/, const A3DVector3dData* /*pasPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleStripeOneNormalTextured(const A3DVector3dData* /*psNormal*/, const A3DVector3dData* /*pasPoints*/, A3DUns32 /*uiPointsSize*/) {} +#ifdef A3D_DRAW_WITH_INDICES +static void stDefaultTriangleWithIndices(const A3DUns32* /*pauiNormals*/, const A3DUns32* /*pauiPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleFanWithIndices(const A3DUns32* /*pauiNormals*/, const A3DUns32* /*pauiPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleStripeWithIndices(const A3DUns32* /*pauiNormals*/, const A3DUns32* /*pauiPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleOneNormalWithIndices(const A3DUns32* /*pauiNormals*/, const A3DUns32* /*pauiPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleFanOneNormalWithIndices(A3DUns32 uiNormal, const A3DUns32* /*pauiPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleStripeOneNormalWithIndices(A3DUns32 uiNormal, const A3DUns32* /*pauiPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleTexturedWithIndices(const A3DUns32* /*pauiNormals*/, const A3DUns32* /*pauiPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleFanTexturedWithIndices(const A3DUns32* /*pauiNormals*/, const A3DUns32* /*pauiPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleStripeTexturedWithIndices(const A3DUns32* /*pauiNormals*/, const A3DUns32* /*pauiPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleOneNormalTexturedWithIndices(const A3DUns32* /*pauiNormals*/, const A3DUns32* /*pauiPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleFanOneNormalTexturedWithIndices(A3DUns32 /*uiNormal*/, const A3DUns32* /*pauiPoints*/, A3DUns32 /*uiPointsSize*/) {} +static void stDefaultTriangleStripeOneNormalTexturedWithIndices(A3DUns32 /*uiNormal*/, const A3DUns32* /*pauiPoints*/, A3DUns32 /*uiPointsSize*/) {} +#endif +static void stDefaultMaterial(A3DEDrawMaterialType /*eType*/, const A3DDouble* /*pdValues*/, A3DUns32 /*uiValuesSize*/) {} +static void stDefaultColor(const A3DDouble [3]/*adValues*/) {} +static void stDefaultGetDrawContext(A3DDouble /*adProjection*/[16], A3DDouble /*adModelView*/[16], A3DInt32 /*aiViewport*/[4]) {} +static void stDefaultMarkupTriangle(const A3DDouble* /*pdPoints*/, A3DUns32 /*uiPointSize*/) {} +static void stDefaultUnProject(const A3DVector3dData* /*psPoint*/, A3DVector3dData* /*psResult*/) {} +static void stDefaultBeginFrameDraw(const A3DVector3dData* /*psPoint3d*/, A3DBool /*bIsZoomable*/, A3DDouble /*dFixedSize*/) {} +static void stDefaultEndFrameDraw(void) {} +static void stDefaultBeginFixedSize(const A3DVector3dData* /*psPoint3d*/) {} +static void stDefaultEndFixedSize(void) {} +static void stDefaultCylinder(A3DDouble /*dBaseRadius*/, A3DDouble /*dTopRadius*/, A3DDouble /*dHeight*/) {} +static void stDefaultPolygon(const A3DDouble* /*pdPoints*/, A3DUns32 /*uiPointSize*/) {} +static void stDefaultBeginLineWidth(A3DDouble /*dWidth*/) {} +static void stDefaultEndLineWidth(void) {} +static void stDefaultPoint(const A3DDouble* /*pdPoints*/, A3DUns32 /*uiPointSize*/) {} +static void stDefaultFont(const A3DFontKeyData* /*psFontKeyData*/) {} +static void stDefaultBeginLineStipple(const A3DGraphStyleData* /*psGraphStyleData*/) {} +static void stDefaultEndLineStipple(void) {} +static void stDefaultSymbol(const A3DGraphVPicturePatternData* /*psPatternData*/, const A3DVector3dData* /*psPosition*/) {} +static void stDefaultPolyLine(const A3DDouble* /*pdPoints*/, A3DUns32 /*uiPointSize*/) {} +static void stDefaultText(const A3DUTF8Char* /*pcBuffer*/, A3DDouble /*dWidth*/, A3DDouble /*dHeight*/) {} +static void stDefaultPattern(A3DUns32 /*uiLoopsSize*/, A3DUns32 /*uiPatternId*/, A3DUns32 /*uiFilledMode*/, A3DUns32 /*uiBehavior*/, const A3DDouble* /*pdPoints*/, const A3DUns32* /*puiLoopsPointSize*/) {} +static void stDefaultPicture(const A3DGraphPictureData* /*psPictureData*/) {} +static void stDefaultBeginMaterial(void) {} +static void stDefaultEndMaterial(void) {} + +//###################################################################################################################### +A3DStatus DrawInitCallbacks(A3DDrawCallbacksData* psCallbacks) +{ + if(!stbCallbacksInitialized) + { +#define A3D_DRAW_DEFINE_CALLBACK(name) { \ + stsCallbacks.m_pfunc##name = stDefault##name; \ + if(psCallbacks->m_pfunc##name != NULL) \ + stsCallbacks.m_pfunc##name = psCallbacks->m_pfunc##name; \ + else \ + stsCallbacks.m_pfunc##name = stDefault##name; \ + } + + A3D_DRAW_DEFINE_CALLBACK(MultMatrix); + A3D_DRAW_DEFINE_CALLBACK(PopMatrix); + A3D_DRAW_DEFINE_CALLBACK(PushMatrix); + A3D_DRAW_DEFINE_CALLBACK(Begin); + A3D_DRAW_DEFINE_CALLBACK(End); + A3D_DRAW_DEFINE_CALLBACK(SetTessellationPoints); +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_DEFINE_CALLBACK(SetTessellationNormals); +#endif + A3D_DRAW_DEFINE_CALLBACK(Triangle); + A3D_DRAW_DEFINE_CALLBACK(TriangleFan); + A3D_DRAW_DEFINE_CALLBACK(TriangleStripe); + A3D_DRAW_DEFINE_CALLBACK(TriangleOneNormal); + A3D_DRAW_DEFINE_CALLBACK(TriangleFanOneNormal); + A3D_DRAW_DEFINE_CALLBACK(TriangleStripeOneNormal); + A3D_DRAW_DEFINE_CALLBACK(TriangleTextured); + A3D_DRAW_DEFINE_CALLBACK(TriangleFanTextured); + A3D_DRAW_DEFINE_CALLBACK(TriangleStripeTextured); + A3D_DRAW_DEFINE_CALLBACK(TriangleOneNormalTextured); + A3D_DRAW_DEFINE_CALLBACK(TriangleFanOneNormalTextured); + A3D_DRAW_DEFINE_CALLBACK(TriangleStripeOneNormalTextured); +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_DEFINE_CALLBACK(TriangleWithIndices); + A3D_DRAW_DEFINE_CALLBACK(TriangleFanWithIndices); + A3D_DRAW_DEFINE_CALLBACK(TriangleStripeWithIndices); + A3D_DRAW_DEFINE_CALLBACK(TriangleOneNormalWithIndices); + A3D_DRAW_DEFINE_CALLBACK(TriangleFanOneNormalWithIndices); + A3D_DRAW_DEFINE_CALLBACK(TriangleStripeOneNormalWithIndices); + A3D_DRAW_DEFINE_CALLBACK(TriangleTexturedWithIndices); + A3D_DRAW_DEFINE_CALLBACK(TriangleFanTexturedWithIndices); + A3D_DRAW_DEFINE_CALLBACK(TriangleStripeTexturedWithIndices); + A3D_DRAW_DEFINE_CALLBACK(TriangleOneNormalTexturedWithIndices); + A3D_DRAW_DEFINE_CALLBACK(TriangleFanOneNormalTexturedWithIndices); + A3D_DRAW_DEFINE_CALLBACK(TriangleStripeOneNormalTexturedWithIndices); +#endif + A3D_DRAW_DEFINE_CALLBACK(Material); + A3D_DRAW_DEFINE_CALLBACK(Color); + A3D_DRAW_DEFINE_CALLBACK(BeginMaterial); + A3D_DRAW_DEFINE_CALLBACK(EndMaterial); + A3D_DRAW_DEFINE_CALLBACK(GetDrawContext); + A3D_DRAW_DEFINE_CALLBACK(MarkupTriangle); + A3D_DRAW_DEFINE_CALLBACK(UnProject); + A3D_DRAW_DEFINE_CALLBACK(BeginFrameDraw); + A3D_DRAW_DEFINE_CALLBACK(EndFrameDraw); + A3D_DRAW_DEFINE_CALLBACK(BeginFixedSize); + A3D_DRAW_DEFINE_CALLBACK(EndFixedSize); + A3D_DRAW_DEFINE_CALLBACK(Cylinder); + A3D_DRAW_DEFINE_CALLBACK(Polygon); + A3D_DRAW_DEFINE_CALLBACK(BeginLineWidth); + A3D_DRAW_DEFINE_CALLBACK(EndLineWidth); + A3D_DRAW_DEFINE_CALLBACK(Point); + A3D_DRAW_DEFINE_CALLBACK(Font); + A3D_DRAW_DEFINE_CALLBACK(BeginLineStipple); + A3D_DRAW_DEFINE_CALLBACK(EndLineStipple); + A3D_DRAW_DEFINE_CALLBACK(Symbol); + A3D_DRAW_DEFINE_CALLBACK(PolyLine); + A3D_DRAW_DEFINE_CALLBACK(Text); + A3D_DRAW_DEFINE_CALLBACK(Pattern); + A3D_DRAW_DEFINE_CALLBACK(Picture); +#undef A3D_DRAW_DEFINE_CALLBACK + + stbCallbacksInitialized = true; + } + + return A3D_SUCCESS; +} + +//###################################################################################################################### +#define A3D_DRAW_CALL0(name) { if(stbUseCallbacks) stsCallbacks.m_pfunc##name(); } +#define A3D_DRAW_CALL1(name, p1) { if(stbUseCallbacks) stsCallbacks.m_pfunc##name(p1); } +#define A3D_DRAW_CALL2(name, p1, p2) { if(stbUseCallbacks) stsCallbacks.m_pfunc##name(p1, p2); } +#define A3D_DRAW_CALL3(name, p1, p2, p3) { if(stbUseCallbacks) stsCallbacks.m_pfunc##name(p1, p2, p3); } +#define A3D_DRAW_CALL6(name, p1, p2, p3, p4, p5, p6) { if(stbUseCallbacks) stsCallbacks.m_pfunc##name(p1, p2, p3, p4, p5, p6); } + +//###################################################################################################################### +#define CHECK_RET(func_call) { iRet = func_call; } + +//###################################################################################################################### +class A3DInternalMarkup +{ + A3DTessMarkupData* m_psData; + A3DTessBaseData* m_psBaseData; + +public: + A3DInternalMarkup(); + ~A3DInternalMarkup(); + + void SetTessMarkupData(A3DTessMarkupData* psData); + void SetTessBaseData(A3DTessBaseData* psBaseData); + + A3DTessMarkupData* Data() { return m_psData; } + const A3DTessMarkupData* Data() const { return m_psData; } + A3DTessBaseData* BaseData() { return m_psBaseData; } + const A3DTessBaseData* BaseData() const { return m_psBaseData; } +}; + +//###################################################################################################################### +A3DInternalMarkup::A3DInternalMarkup() +{ + m_psData = (A3DTessMarkupData*)malloc(sizeof(A3DTessMarkupData)); + A3D_INITIALIZE_DATA(A3DTessMarkupData, (*m_psData)); + m_psBaseData = (A3DTessBaseData*)malloc(sizeof(A3DTessBaseData)); + A3D_INITIALIZE_DATA(A3DTessBaseData, (*m_psBaseData)); +} + +//###################################################################################################################### +A3DInternalMarkup::~A3DInternalMarkup() +{ + if(m_psData != NULL) + { + A3DTessMarkupGet(NULL, m_psData); + free(m_psData); + } + if(m_psBaseData != NULL) + { + A3DTessBaseGet(NULL, m_psBaseData); + free(m_psBaseData); + } +} + +//###################################################################################################################### +void A3DInternalMarkup::SetTessMarkupData(A3DTessMarkupData* psData) +{ + m_psData = psData; +} + +//###################################################################################################################### +void A3DInternalMarkup::SetTessBaseData(A3DTessBaseData* psBaseData) +{ + m_psBaseData = psBaseData; +} + +//###################################################################################################################### +static void stAllocVector3dArray(A3DVector3dData** ppasArray, A3DUns32 uiSize) +{ + A3DUns32 ui; + *ppasArray = (A3DVector3dData*)malloc(uiSize * sizeof(A3DVector3dData)); + for(ui = 0; ui < uiSize; ui++) + A3D_INITIALIZE_DATA(A3DVector3dData, ((*ppasArray)[ui])); +} + +//###################################################################################################################### +static void stAllocNormalsAndPoints(A3DVector3dData** ppasNormals, A3DUns32 uiNormalSize, A3DVector3dData** ppasPoints, + A3DUns32 uiPointSize) +{ + stAllocVector3dArray(ppasNormals, uiNormalSize); + stAllocVector3dArray(ppasPoints, uiPointSize); +} + +//###################################################################################################################### +static void stFreeNormalsAndPoints(A3DVector3dData** ppasNormals, A3DVector3dData** ppasPoints) +{ + free(*ppasNormals); + free(*ppasPoints); +} + +//###################################################################################################################### +typedef struct +{ + unsigned int m_uiAllocated; + unsigned int m_uiSize; + void** m_ppPointers; +} A3DPointerArray; + +//###################################################################################################################### +static void stPointerArrayInitialize(A3DPointerArray* psArray) +{ + if(psArray == NULL) + return; + + psArray->m_uiAllocated = 0; + psArray->m_uiSize = 0; + psArray->m_ppPointers = NULL; +} + +//###################################################################################################################### +static void stPointerArrayFree(A3DPointerArray* psArray) +{ + psArray->m_uiAllocated = 0; + psArray->m_uiSize = 0; + free(psArray->m_ppPointers); +} + +//###################################################################################################################### +static void stPointerArrayTerminate(A3DPointerArray* psArray) +{ + stPointerArrayFree(psArray); +} + +//###################################################################################################################### +void* MiscRealloc(void* p, A3DUns32 uiOldSize, A3DUns32 uiNewSize) +{ + void* newp=malloc(uiNewSize); + memcpy(newp,p,uiOldSize); + free(p); + + return newp; +} + +//###################################################################################################################### +static unsigned int stPointerArrayAdd(A3DPointerArray* psArray, void* pPointer) +{ + if(psArray == NULL) + return 0; + + if(psArray->m_uiAllocated == 0) + { + psArray->m_uiAllocated = 2; + psArray->m_ppPointers = (void**)malloc(psArray->m_uiAllocated * sizeof(void*)); + } + + if(psArray->m_uiSize == psArray->m_uiAllocated) + { + psArray->m_uiAllocated *= 2; + psArray->m_ppPointers = (void**)MiscRealloc(psArray->m_ppPointers, psArray->m_uiSize * sizeof(void*), + psArray->m_uiAllocated * sizeof(void*)); + } + + psArray->m_ppPointers[psArray->m_uiSize] = pPointer; + psArray->m_uiSize++; + + return psArray->m_uiSize; +} + +//###################################################################################################################### +static int stPointerArrayFind(A3DPointerArray* psArray, void* pPointer) +{ + for(unsigned int ui = 0; ui < psArray->m_uiSize; ui++) + { + if(psArray->m_ppPointers[ui] == pPointer) + return ui; + } + + return -1; +} + +//###################################################################################################################### +static unsigned int stPointerArrayAddUnique(A3DPointerArray* psArray, void* pPointer) +{ + if(psArray == NULL) + return 0; + + if(stPointerArrayFind(psArray, pPointer) != -1) + return psArray->m_uiSize; + + return stPointerArrayAdd(psArray, pPointer); +} + +//###################################################################################################################### +static unsigned int stPointerArrayAddArray(A3DPointerArray* psArray, void** const ppPointers, unsigned int uiSize) +{ + for(unsigned int ui = 0; ui < uiSize; ui++) + stPointerArrayAdd(psArray, ppPointers[ui]); + return psArray->m_uiSize; +} + +//###################################################################################################################### +#define A3D_MIN(a,b) (((a)<(b)) ? (a) : (b)) +#define A3D_MAX(a,b) (((a)>(b)) ? (a) : (b)) + +//###################################################################################################################### +extern void stVectoriel(const A3DVector3dData* X, const A3DVector3dData* Y, A3DVector3dData* Z) +{ + Z->m_dX=X->m_dY*Y->m_dZ - X->m_dZ*Y->m_dY; + Z->m_dY=X->m_dZ*Y->m_dX - X->m_dX*Y->m_dZ; + Z->m_dZ=X->m_dX*Y->m_dY - X->m_dY*Y->m_dX; +} + +//###################################################################################################################### +static void stVectorMatrixMult(A3DDouble dX, A3DDouble dY, A3DDouble dZ, double adMatrix[16], + A3DDouble* pdResX, A3DDouble* pdResY, A3DDouble* pdResZ) +{ + *pdResX = adMatrix[0]*dX + adMatrix[4]*dY + adMatrix[8]*dZ + adMatrix[12]; + *pdResY = adMatrix[1]*dX + adMatrix[5]*dY + adMatrix[9]*dZ + adMatrix[13]; + *pdResZ = adMatrix[2]*dX + adMatrix[6]*dY + adMatrix[10]*dZ + adMatrix[14]; +} + +//###################################################################################################################### +static double staadStack[32][16]; +static unsigned int uiPos = 0; +static double stadMatrix[16]; + +//###################################################################################################################### +extern void stMatrixMatrixMult(double m[16], const double o[16]) +{ + memcpy(stadMatrix, m, 16*sizeof(double)); + m[0] = stadMatrix[0] * o[0] + stadMatrix[4] * o[1] + stadMatrix[8] * o[2] + stadMatrix[12] * o[3]; + m[1] = stadMatrix[1] * o[0] + stadMatrix[5] * o[1] + stadMatrix[9] * o[2] + stadMatrix[13] * o[3]; + m[2] = stadMatrix[2] * o[0] + stadMatrix[6] * o[1] + stadMatrix[10] * o[2] + stadMatrix[14] * o[3]; + m[3] = stadMatrix[3] * o[0] + stadMatrix[7] * o[1] + stadMatrix[11] * o[2] + stadMatrix[15] * o[3]; + m[4] = stadMatrix[0] * o[4] + stadMatrix[4] * o[5] + stadMatrix[8] * o[6] + stadMatrix[12] * o[7]; + m[5] = stadMatrix[1] * o[4] + stadMatrix[5] * o[5] + stadMatrix[9] * o[6] + stadMatrix[13] * o[7]; + m[6] = stadMatrix[2] * o[4] + stadMatrix[6] * o[5] + stadMatrix[10] * o[6] + stadMatrix[14] * o[7]; + m[7] = stadMatrix[3] * o[4] + stadMatrix[7] * o[5] + stadMatrix[11] * o[6] + stadMatrix[15] * o[7]; + m[8] = stadMatrix[0] * o[8] + stadMatrix[4] * o[9] + stadMatrix[8] * o[10] + stadMatrix[12] * o[11]; + m[9] = stadMatrix[1] * o[8] + stadMatrix[5] * o[9] + stadMatrix[9] * o[10] + stadMatrix[13] * o[11]; + m[10]= stadMatrix[2] * o[8] + stadMatrix[6] * o[9] + stadMatrix[10] * o[10] + stadMatrix[14] * o[11]; + m[11]= stadMatrix[3] * o[8] + stadMatrix[7] * o[9] + stadMatrix[11] * o[10] + stadMatrix[15] * o[11]; + m[12]= stadMatrix[0] * o[12] + stadMatrix[4] * o[13] + stadMatrix[8] * o[14] + stadMatrix[12] * o[15]; + m[13]= stadMatrix[1] * o[12] + stadMatrix[5] * o[13] + stadMatrix[9] * o[14] + stadMatrix[13] * o[15]; + m[14]= stadMatrix[2] * o[12] + stadMatrix[6] * o[13] + stadMatrix[10] * o[14] + stadMatrix[14] * o[15]; + m[15]= stadMatrix[3] * o[12] + stadMatrix[7] * o[13] + stadMatrix[11] * o[14] + stadMatrix[15] * o[15]; +} + +//###################################################################################################################### +extern void stLoadIdentity() +{ + memset(staadStack[uiPos], 0, 16*sizeof(double)); + staadStack[uiPos][0] = 1.0; + staadStack[uiPos][5] = 1.0; + staadStack[uiPos][10] = 1.0; + staadStack[uiPos][15] = 1.0; +} + +//###################################################################################################################### +extern void stMultMatrix(const double m[16]) +{ + stMatrixMatrixMult(staadStack[uiPos], m); +} + +//###################################################################################################################### +extern void stPushMatrix() +{ + if(uiPos < 7) + { + uiPos++; + memcpy(staadStack[uiPos], staadStack[uiPos-1], 16*sizeof(double)); + } +} + +//###################################################################################################################### +extern void stPopMatrix() +{ + if(uiPos > 0) + { + uiPos--; + } +} + +//###################################################################################################################### +static void stGetMatrix(double m[16]) +{ + memcpy(m, staadStack[uiPos], 16*sizeof(double)); +} + +//###################################################################################################################### +extern void stExtentInit(A3DBoundingBoxData* e) +{ + e->m_sMin.m_dX = 1e10; + e->m_sMin.m_dY = 1e10; + e->m_sMin.m_dZ = 1e10; + e->m_sMax.m_dX = -1e10; + e->m_sMax.m_dY = -1e10; + e->m_sMax.m_dZ = -1e10; +} + +//###################################################################################################################### +extern void stBoundingBoxAddPoint(A3DBoundingBoxData* e, double x, double y, double z) +{ + if (e == NULL) + return; + + if(x < e->m_sMin.m_dX) e->m_sMin.m_dX = x; + if(y < e->m_sMin.m_dY) e->m_sMin.m_dY = y; + if(z < e->m_sMin.m_dZ) e->m_sMin.m_dZ = z; + if(x > e->m_sMax.m_dX) e->m_sMax.m_dX = x; + if(y > e->m_sMax.m_dY) e->m_sMax.m_dY = y; + if(z > e->m_sMax.m_dZ) e->m_sMax.m_dZ = z; +} + +//###################################################################################################################### +static bool stExtentIsValid(A3DBoundingBoxData* e) +{ + return (e->m_sMin.m_dX <= e->m_sMax.m_dX && e->m_sMin.m_dY <= e->m_sMax.m_dY && e->m_sMin.m_dZ <= e->m_sMax.m_dZ); +} + +//###################################################################################################################### +static void stExtentUnion(const A3DBoundingBoxData* e1, const A3DBoundingBoxData* e2, A3DBoundingBoxData* r) +{ + r->m_sMin.m_dX = A3D_MIN(e1->m_sMin.m_dX, e2->m_sMin.m_dX); + r->m_sMax.m_dX = A3D_MAX(e1->m_sMax.m_dX, e2->m_sMax.m_dX); + r->m_sMin.m_dY = A3D_MIN(e1->m_sMin.m_dY, e2->m_sMin.m_dY); + r->m_sMax.m_dY = A3D_MAX(e1->m_sMax.m_dY, e2->m_sMax.m_dY); + r->m_sMin.m_dZ = A3D_MIN(e1->m_sMin.m_dZ, e2->m_sMin.m_dZ); + r->m_sMax.m_dZ = A3D_MAX(e1->m_sMax.m_dZ, e2->m_sMax.m_dZ); +} + +//###################################################################################################################### +static void stUnitVector(A3DVector3dData* psVect) +{ + if(psVect == NULL) + return; + + double x = psVect->m_dX, y = psVect->m_dY, z = psVect->m_dZ; + double norm = sqrt(x*x+y*y+z*z); + if(norm != 0) + { + psVect->m_dX = (x/norm); + psVect->m_dY = (y/norm); + psVect->m_dZ = (z/norm); + } +} + +//###################################################################################################################### +static void stMatrixCalculate(const A3DVector3dData* psX, const A3DVector3dData* psY, const A3DVector3dData* psZ, + double m[16]) +{ + m[0] = psX->m_dX; + m[1] = psX->m_dY; + m[2] = psX->m_dZ; + m[3] = 0.0; + m[4] = psY->m_dX; + m[5] = psY->m_dY; + m[6] = psY->m_dZ; + m[7] = 0.0; + m[8] = psZ->m_dX; + m[9] = psZ->m_dY; + m[10] = psZ->m_dZ; + m[11] = 0.0; + m[12] = 0.0; + m[13] = 0.0; + m[14] = 0.0; + m[15] = 1.0; +} + +//###################################################################################################################### +void stGetFaceViewMatrix(const A3DVector3dData* psP0, const A3DVector3dData* psP1, const A3DVector3dData* psP2, + double m[16]) +{ + A3DVector3dData sVectX; + sVectX.m_dX = psP1->m_dX - psP0->m_dX; + sVectX.m_dY = psP1->m_dY - psP0->m_dY; + sVectX.m_dZ = psP1->m_dZ - psP0->m_dZ; + + A3DVector3dData sVectY; + sVectY.m_dX = psP2->m_dX - psP0->m_dX; + sVectY.m_dY = psP2->m_dY - psP0->m_dY; + sVectY.m_dZ = psP2->m_dZ - psP0->m_dZ; + + A3DVector3dData sNormalPlane; + sNormalPlane.m_dX = sVectX.m_dY * sVectY.m_dZ - sVectX.m_dZ * sVectY.m_dY; + sNormalPlane.m_dY = -(sVectX.m_dX * sVectY.m_dZ - sVectX.m_dZ * sVectY.m_dX); + sNormalPlane.m_dZ = sVectX.m_dX * sVectY.m_dY - sVectX.m_dY * sVectY.m_dX; + + stUnitVector(&sVectX); + stUnitVector(&sVectY); + stUnitVector(&sNormalPlane); + + stMatrixCalculate(&sVectX, &sVectY, &sNormalPlane, m); +} + +//###################################################################################################################### +static A3DStatus stCreateAndPushCascadedAttributes(const A3DRootBaseWithGraphics* pBase, + const A3DMiscCascadedAttributes* pFatherAttr, + A3DMiscCascadedAttributes** ppAttr, + A3DMiscCascadedAttributesData* psAttrData) +{ + A3DStatus iRet = A3D_SUCCESS; + + CHECK_RET(A3DMiscCascadedAttributesCreate(ppAttr)); + CHECK_RET(A3DMiscCascadedAttributesPush(*ppAttr,pBase, pFatherAttr)); + + A3D_INITIALIZE_DATA(A3DMiscCascadedAttributesData, (*psAttrData)); + CHECK_RET(A3DMiscCascadedAttributesGet(*ppAttr, psAttrData)); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stCreateAndPushCascadedAttributesFace(const A3DRiRepresentationItem* pRepItem, + const A3DTessBase* pTessBase, + const A3DTessFaceData* psTessFaceData, + A3DUns32 uiFaceIndex, + const A3DMiscCascadedAttributes* pFatherAttr, + A3DMiscCascadedAttributes** ppAttr, + A3DMiscCascadedAttributesData* psAttrData) +{ + A3DStatus iRet = A3D_SUCCESS; + + CHECK_RET(A3DMiscCascadedAttributesCreate(ppAttr)); + CHECK_RET(A3DMiscCascadedAttributesPushTessFace(*ppAttr, pRepItem, pTessBase, psTessFaceData, uiFaceIndex, + pFatherAttr)); + + A3D_INITIALIZE_DATA(A3DMiscCascadedAttributesData, (*psAttrData)); + CHECK_RET(A3DMiscCascadedAttributesGet(*ppAttr, psAttrData)); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stCreateAndPushCascadedAttributesDrwEntity(const A3DDrawingBlock* pBlock, + A3DUns32 uiEntityIndex, + const A3DMiscCascadedAttributes* pFatherAttr, + A3DMiscCascadedAttributes** ppAttr, + A3DMiscCascadedAttributesData* psAttrData) +{ + A3DStatus iRet = A3D_SUCCESS; + + CHECK_RET(A3DMiscCascadedAttributesCreate(ppAttr)); + CHECK_RET(A3DDrawingBlockPushMiscCascadedAttributes(*ppAttr, pBlock, uiEntityIndex, pFatherAttr) ); + + A3D_INITIALIZE_DATA(A3DMiscCascadedAttributesData, (*psAttrData)); + CHECK_RET(A3DMiscCascadedAttributesGet(*ppAttr, psAttrData)); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stDrawTransformation(const A3DMiscTransformation* pTransfo3d) +{ + if(pTransfo3d == NULL) + return A3D_SUCCESS; + + A3DStatus iRet = A3D_SUCCESS; + + A3DEEntityType eType = kA3DTypeUnknown; + A3DEntityGetType(pTransfo3d, &eType); + + switch(eType) + { + case kA3DTypeMiscCartesianTransformation : + { + A3DMiscCartesianTransformationData sData; + A3D_INITIALIZE_DATA(A3DMiscCartesianTransformationData, sData); + + CHECK_RET(A3DMiscCartesianTransformationGet(pTransfo3d, &sData)); + + double adMatrix[16]; + double dMirror=(sData.m_ucBehaviour & kA3DTransformationMirror) ? -1.: 1.; + + A3DVector3dData sZVector; + memset(adMatrix,0,16*sizeof(double)); + stVectoriel(&sData.m_sXVector, &sData.m_sYVector, &sZVector); + + adMatrix[12]=sData.m_sOrigin.m_dX; + adMatrix[13]=sData.m_sOrigin.m_dY; + adMatrix[14]=sData.m_sOrigin.m_dZ; + + adMatrix[0]=sData.m_sXVector.m_dX*sData.m_sScale.m_dX; + adMatrix[1]=sData.m_sXVector.m_dY*sData.m_sScale.m_dX; + adMatrix[2]=sData.m_sXVector.m_dZ*sData.m_sScale.m_dX; + + adMatrix[4]=sData.m_sYVector.m_dX*sData.m_sScale.m_dY; + adMatrix[5]=sData.m_sYVector.m_dY*sData.m_sScale.m_dY; + adMatrix[6]=sData.m_sYVector.m_dZ*sData.m_sScale.m_dY; + + adMatrix[8]=dMirror*sZVector.m_dX*sData.m_sScale.m_dZ; + adMatrix[9]=dMirror*sZVector.m_dY*sData.m_sScale.m_dZ; + adMatrix[10]=dMirror*sZVector.m_dZ*sData.m_sScale.m_dZ; + + adMatrix[15]=1.; + + A3D_DRAW_CALL1(MultMatrix, adMatrix); + stMultMatrix(adMatrix); + + CHECK_RET(A3DMiscCartesianTransformationGet(NULL, &sData)); + } + break; + + case kA3DTypeMiscGeneralTransformation : + { + A3DMiscGeneralTransformationData sData; + A3D_INITIALIZE_DATA(A3DMiscGeneralTransformationData, sData); + + CHECK_RET(A3DMiscGeneralTransformationGet(pTransfo3d, &sData)); + + A3D_DRAW_CALL1(MultMatrix, sData.m_adCoeff); + stMultMatrix(sData.m_adCoeff); + + CHECK_RET(A3DMiscGeneralTransformationGet(NULL, &sData)); + } + break; + default: + break; + } + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stDrawBoundingBox(const A3DBoundingBoxData* /*pData*/) +{ + return A3D_SUCCESS; +} + +//###################################################################################################################### +static A3DUns32 stTessFaceDataGetNumberOfFacets(const A3DTessFaceData* psTessFaceData) +{ + A3DUns32 iNbFacet=0; + A3DUns32 iNumberIndex=0; + A3DUns32 iNbEntities=0; + A3DUns32 iStartId; + A3DUns32 iId; + +#define SIZE_TRIANGLE_ENTITY(index) ((index < psTessFaceData->m_uiSizesTriangulatedSize ? \ + psTessFaceData->m_puiSizesTriangulated[index] & kA3DTessFaceDataNormalMask : 0)) + + if(psTessFaceData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangle) + { + iNbFacet+=SIZE_TRIANGLE_ENTITY(iNumberIndex); + iNumberIndex++; + } + + if(psTessFaceData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFan) + { + iNbEntities = SIZE_TRIANGLE_ENTITY(iNumberIndex); + iStartId = iNumberIndex+1; + + for(iId=0;iIdm_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripe) + { + iNbEntities = SIZE_TRIANGLE_ENTITY(iNumberIndex); + iStartId = iNumberIndex+1; + + for(iId=0;iIdm_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormal) + { + iNbFacet+=SIZE_TRIANGLE_ENTITY(iNumberIndex); + iNumberIndex++; + } + + if(psTessFaceData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormal) + { + iNbEntities = SIZE_TRIANGLE_ENTITY(iNumberIndex); + iStartId = iNumberIndex+1; + + for(iId=0;iIdm_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormal) + { + iNbEntities = SIZE_TRIANGLE_ENTITY(iNumberIndex); + iStartId = iNumberIndex+1; + + for(iId=0;iIdm_usUsedEntitiesFlags & kA3DTessFaceDataTriangleTextured) + { + iNbFacet+=SIZE_TRIANGLE_ENTITY(iNumberIndex); + iNumberIndex++; + } + + if(psTessFaceData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanTextured) + { + iNbEntities = SIZE_TRIANGLE_ENTITY(iNumberIndex); + iStartId = iNumberIndex+1; + + for(iId=0;iIdm_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeTextured) + { + iNbEntities = SIZE_TRIANGLE_ENTITY(iNumberIndex); + iStartId = iNumberIndex+1; + + for(iId=0;iIdm_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormalTextured) + { + iNbFacet+=SIZE_TRIANGLE_ENTITY(iNumberIndex); + iNumberIndex++; + } + + if(psTessFaceData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormalTextured) + { + iNbEntities = SIZE_TRIANGLE_ENTITY(iNumberIndex); + iStartId = iNumberIndex+1; + + for(iId=0;iIdm_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormalTextured) + { + iNbEntities = SIZE_TRIANGLE_ENTITY(iNumberIndex); + iStartId = iNumberIndex+1; + + for(iId=0;iIdm_uiFaceTessSize; ui++) + { + uiNbFacets += stTessFaceDataGetNumberOfFacets(&psTess3DData->m_psFaceTessData[ui]); + } + + return uiNbFacets; +} + +//###################################################################################################################### +static A3DStatus stIsShow(const A3DRootBaseWithGraphics* pGraphics) +{ + if(pGraphics == NULL) + return A3D_ERROR; + + A3DStatus iRet = A3D_SUCCESS; + + A3DRootBaseWithGraphicsData sRootData; + A3D_INITIALIZE_DATA(A3DRootBaseWithGraphicsData, sRootData); + CHECK_RET(A3DRootBaseWithGraphicsGet(pGraphics, &sRootData)); + + A3DGraphicsData sGraphicsData; + A3D_INITIALIZE_DATA(A3DGraphicsData, sGraphicsData); + CHECK_RET(A3DGraphicsGet(sRootData.m_pGraphics, &sGraphicsData)); + + A3DBool bShow; + if(sRootData.m_pGraphics) + bShow = (sGraphicsData.m_usBehaviour & kA3DGraphicsShow) != 0; + else + bShow = true; + CHECK_RET(A3DGraphicsGet(NULL, &sGraphicsData)); + CHECK_RET(A3DRootBaseWithGraphicsGet(NULL, &sRootData)); + + if(bShow) + return A3D_SUCCESS; + else + return A3D_ERROR; +} + +//###################################################################################################################### +static A3DStatus stDrawStyle(const A3DGraphStyleData* psStyleData, A3DInt32* piUVCoordinatesIndex, + A3DUns8* pucTextureDimension, + bool* pbPush = NULL, + bool *pbPushLineStipple = NULL, + bool *pbPushLineWidth = NULL) +{ + if(psStyleData == NULL) + return A3D_ERROR; + + A3DStatus iRet = A3D_SUCCESS; + + if(pbPush != NULL) + { + *pbPush = false; + } + + if(psStyleData->m_bMaterial) + { + A3DBool bMaterialIsTexture = false; + + A3DDouble adColor[4] = { 0.0, 0.0, 0.0, 1.0 }; + + /* check if this material is a texture */ + CHECK_RET(A3DGlobalIsMaterialTexture(psStyleData->m_uiRgbColorIndex,&bMaterialIsTexture)); + if(bMaterialIsTexture) + { + A3DGraphTextureApplicationData sTextureAppplicationData; + A3D_INITIALIZE_DATA(A3DGraphTextureApplicationData, sTextureAppplicationData); + CHECK_RET(A3DGlobalGetGraphTextureApplicationData(psStyleData->m_uiRgbColorIndex, + &sTextureAppplicationData)); + + *piUVCoordinatesIndex = sTextureAppplicationData.m_iUVCoordinatesIndex; + + A3DGraphTextureDefinitionData sTextureDefinitionData; + A3D_INITIALIZE_DATA(A3DGraphTextureDefinitionData, sTextureDefinitionData); + CHECK_RET(A3DGlobalGetGraphTextureDefinitionData(sTextureAppplicationData.m_uiTextureDefinitionIndex, + &sTextureDefinitionData)); + + *pucTextureDimension = sTextureDefinitionData.m_ucTextureDimension; + + adColor[0] = sTextureDefinitionData.m_dRed; + adColor[1] = sTextureDefinitionData.m_dGreen; + adColor[2] = sTextureDefinitionData.m_dBlue; + adColor[3] = sTextureDefinitionData.m_dAlpha; + if(pbPush != NULL) + { + A3D_DRAW_CALL0(BeginMaterial); + *pbPush = true; + } + + A3D_DRAW_CALL3(Material, kA3DDrawMaterialDiffuse, adColor, 4); + + CHECK_RET(A3DGlobalGetGraphTextureDefinitionData(A3D_DEFAULT_TEXTURE_DEFINITION_INDEX, + &sTextureDefinitionData)); + + CHECK_RET(A3DGlobalGetGraphTextureApplicationData(A3D_DEFAULT_MATERIAL_INDEX, &sTextureAppplicationData)); + } + else + { + if(pbPush != NULL) + { + A3D_DRAW_CALL0(BeginMaterial); + *pbPush = true; + } + + A3DGraphMaterialData sMaterialData; + A3D_INITIALIZE_DATA(A3DGraphMaterialData, sMaterialData); + CHECK_RET(A3DGlobalGetGraphMaterialData(psStyleData->m_uiRgbColorIndex,&sMaterialData)); + + A3DGraphRgbColorData sRgbColorData; + A3D_INITIALIZE_DATA(A3DGraphRgbColorData, sRgbColorData); + + CHECK_RET(A3DGlobalGetGraphRgbColorData(sMaterialData.m_uiDiffuse, &sRgbColorData)); + adColor[0] = sRgbColorData.m_dRed; + adColor[1] = sRgbColorData.m_dGreen; + adColor[2] = sRgbColorData.m_dBlue; + adColor[3] = sMaterialData.m_dDiffuseAlpha; + A3D_DRAW_CALL3(Material, kA3DDrawMaterialDiffuse, adColor, 4); + + CHECK_RET(A3DGlobalGetGraphRgbColorData(A3D_DEFAULT_COLOR_INDEX, &sRgbColorData)); + + CHECK_RET(A3DGlobalGetGraphRgbColorData(sMaterialData.m_uiAmbient, &sRgbColorData)); + adColor[0] = sRgbColorData.m_dRed; + adColor[1] = sRgbColorData.m_dGreen; + adColor[2] = sRgbColorData.m_dBlue; + adColor[3] = sMaterialData.m_dAmbientAlpha; + A3D_DRAW_CALL3(Material, kA3DDrawMaterialAmbient, adColor, 4); + + CHECK_RET(A3DGlobalGetGraphRgbColorData(A3D_DEFAULT_COLOR_INDEX, &sRgbColorData)); + + CHECK_RET(A3DGlobalGetGraphRgbColorData(sMaterialData.m_uiEmissive, &sRgbColorData)); + adColor[0] = sRgbColorData.m_dRed; + adColor[1] = sRgbColorData.m_dGreen; + adColor[2] = sRgbColorData.m_dBlue; + adColor[3] = sMaterialData.m_dEmissiveAlpha; + A3D_DRAW_CALL3(Material, kA3DDrawMaterialEmission, adColor, 4); + + CHECK_RET(A3DGlobalGetGraphRgbColorData(A3D_DEFAULT_COLOR_INDEX, &sRgbColorData)); + + CHECK_RET(A3DGlobalGetGraphRgbColorData(sMaterialData.m_uiSpecular, &sRgbColorData)); + adColor[0] = sRgbColorData.m_dRed; + adColor[1] = sRgbColorData.m_dGreen; + adColor[2] = sRgbColorData.m_dBlue; + adColor[3] = sMaterialData.m_dSpecularAlpha; + A3D_DRAW_CALL3(Material, kA3DDrawMaterialSpecular, adColor, 4); + + CHECK_RET(A3DGlobalGetGraphRgbColorData(A3D_DEFAULT_COLOR_INDEX, &sRgbColorData)); + + A3DDouble adShininess[1] = { sMaterialData.m_dShininess }; + A3D_DRAW_CALL3(Material, kA3DDrawMaterialShininess, adShininess, 1); + + CHECK_RET(A3DGlobalGetGraphMaterialData(A3D_DEFAULT_MATERIAL_INDEX, &sMaterialData)); + } + } + else + { + if(psStyleData->m_uiRgbColorIndex != A3D_DEFAULT_COLOR_INDEX) + { + if(pbPush != NULL) + { + A3D_DRAW_CALL0(BeginMaterial); + *pbPush = true; + } + + A3DGraphRgbColorData sRgbColorData; + A3D_INITIALIZE_DATA(A3DGraphRgbColorData, sRgbColorData); + CHECK_RET(A3DGlobalGetGraphRgbColorData(psStyleData->m_uiRgbColorIndex,&sRgbColorData)); + + A3DDouble adColor[3] = { sRgbColorData.m_dRed, sRgbColorData.m_dGreen, sRgbColorData.m_dBlue }; + A3D_DRAW_CALL3(Material, kA3DDrawMaterialDiffuse, adColor, 3); + A3D_DRAW_CALL1(Color, adColor); + + CHECK_RET(A3DGlobalGetGraphRgbColorData(A3D_DEFAULT_COLOR_INDEX, &sRgbColorData)); + } + } + + if (pbPushLineWidth != NULL) + { + if (psStyleData->m_dWidth!=0.) + { + *pbPushLineWidth = true; + A3D_DRAW_CALL1(BeginLineWidth, psStyleData->m_dWidth); + } + else + *pbPushLineWidth = false; + } + + if (pbPushLineStipple!=NULL) + { + if (psStyleData->m_uiLinePatternIndex != A3D_DEFAULT_LINEPATTERN_INDEX) + { + *pbPushLineStipple = true; + A3D_DRAW_CALL1(BeginLineStipple, psStyleData); + } + else + *pbPushLineStipple = false; + } + + return iRet; +} + +//###################################################################################################################### +static A3DUTF8Char* stpcRepresentationItemName = NULL; + +//###################################################################################################################### +static A3DStatus stDrawTess3DWire(const A3DTess3DWire* pTess3DWire, const A3DRiRepresentationItem* /*pRepItem*/, + const A3DMiscCascadedAttributes* pFatherAttr) +{ + A3DStatus iRet = A3D_SUCCESS; + A3DTessBaseData sTessBaseData; + A3D_INITIALIZE_DATA(A3DTessBaseData, sTessBaseData); + CHECK_RET(A3DTessBaseGet(pTess3DWire,&sTessBaseData)); + + A3DMiscCascadedAttributesData sAttrData; + A3D_INITIALIZE_DATA(A3DMiscCascadedAttributesData, sAttrData); + CHECK_RET(A3DMiscCascadedAttributesGet(pFatherAttr, &sAttrData)); + + // computing the box if we're not using the callbacks (A3DDrawModelFileGetBoundingBox) + + double adMatrix[16]; + stGetMatrix(adMatrix); + + A3DDouble dX, dY, dZ; + A3DDouble dAbsX, dAbsY, dAbsZ; + + const A3DDouble* pdCoord = &sTessBaseData.m_pdCoords[0]; + const A3DDouble* pdEnd = &sTessBaseData.m_pdCoords[sTessBaseData.m_uiCoordSize-1]; + + A3DInt32 iUVCoordinatesIndex = -1; + A3DUns8 ucTextureDimension = 2; + CHECK_RET(stDrawStyle(&sAttrData.m_sStyle, &iUVCoordinatesIndex, &ucTextureDimension)); + + A3DUns32 uiPointSize=sTessBaseData.m_uiCoordSize/3; + A3D_DRAW_CALL2(PolyLine, pdCoord, uiPointSize); + + for(; pdCoord < pdEnd; pdCoord += 3) + { + dX = *pdCoord; + dY = *(pdCoord+1); + dZ = *(pdCoord+2); + + stVectorMatrixMult(dX, dY, dZ, adMatrix, &dAbsX, &dAbsY, &dAbsZ); + stBoundingBoxAddPoint(stpsBoundingBox, dAbsX, dAbsY, dAbsZ); + } + + CHECK_RET(A3DTessBaseGet(NULL, &sTessBaseData)); + CHECK_RET(A3DMiscCascadedAttributesGet(NULL, &sAttrData)); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stDrawTess3D(const A3DTess3D* pTess3D, const A3DRiRepresentationItem* pRepItem, + const A3DMiscCascadedAttributes* pFatherAttr) +{ + A3DEEntityType eType=kA3DTypeUnknown; + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(A3DEntityGetType(pRepItem, &eType)); + bool bIsPlane = eType == kA3DTypeRiPlane; + + + A3DTess3DData sTess3DData; + A3D_INITIALIZE_DATA(A3DTess3DData, sTess3DData); + + CHECK_RET(A3DTess3DGet(pTess3D, &sTess3DData)); + + A3DTessBaseData sTessBaseData; + A3D_INITIALIZE_DATA(A3DTessBaseData, sTessBaseData); + CHECK_RET(A3DTessBaseGet(pTess3D,&sTessBaseData)); + + A3DDouble adMinimumNormals[3]; + if (sTess3DData.m_bMustRecalculateNormals) + { + sTess3DData.m_uiNormalSize = 3; + sTess3DData.m_pdNormals = adMinimumNormals; + sTess3DData.m_pdNormals[0] = 0; + sTess3DData.m_pdNormals[1] = 0; + sTess3DData.m_pdNormals[2] = 0; + } + + A3DMiscCascadedAttributesData sAttrData; + A3D_INITIALIZE_DATA(A3DMiscCascadedAttributesData, sAttrData); + CHECK_RET(A3DMiscCascadedAttributesGet(pFatherAttr, &sAttrData)); + + //if(stpcRepresentationItemName != NULL) + { + A3DUns32 uiNbTriangles = stTess3DDataGetNumberOfFacets(&sTess3DData); + A3D_DRAW_CALL3(Begin, kA3DDrawBeginEndRepresentationItem, stpcRepresentationItemName, uiNbTriangles); + } + + // stbUseCallbacks is set to false when we're asking for the box computing (A3DDrawModelFileGetBoundingBox). + // In the case where we're using Draw, it's set to true. + + A3DVector3dData* pasPoints = NULL; + if(stbUseCallbacks) + stAllocVector3dArray(&pasPoints, sTessBaseData.m_uiCoordSize/3); + + // computing the box if we're not using the callbacks (A3DDrawModelFileGetBoundingBox) + + double adMatrix[16]; + stGetMatrix(adMatrix); + + A3DDouble dX, dY, dZ; + A3DDouble dAbsX, dAbsY, dAbsZ; + + const A3DDouble* pdCoord = &sTessBaseData.m_pdCoords[0]; + const A3DDouble* pdEnd = &sTessBaseData.m_pdCoords[sTessBaseData.m_uiCoordSize-1]; + + A3DVector3dData* psCurPoint = NULL; + + if(stbUseCallbacks) + psCurPoint = &pasPoints[0]; + + if(pdCoord != NULL) + { + for(; pdCoord < pdEnd; pdCoord += 3) + { + dX = *pdCoord; + dY = *(pdCoord+1); + dZ = *(pdCoord+2); + + if(stbUseCallbacks) + { + psCurPoint->m_dX = dX; + psCurPoint->m_dY = dY; + psCurPoint->m_dZ = dZ; + psCurPoint++; + } + else + { + if(!bIsPlane) + { + stVectorMatrixMult(dX, dY, dZ, adMatrix, &dAbsX, &dAbsY, &dAbsZ); + stBoundingBoxAddPoint(stpsBoundingBox, dAbsX, dAbsY, dAbsZ); + } + } + } + } + + if(!stbUseCallbacks) + { + if (sTess3DData.m_bMustRecalculateNormals) + sTess3DData.m_pdNormals=NULL; + CHECK_RET(A3DTess3DGet(NULL, &sTess3DData)); + CHECK_RET(A3DTessBaseGet(NULL, &sTessBaseData)); + + // it's OK because we have allocating pasPoints in the case where stbUseCallbacks == true + return iRet; + } + + A3D_DRAW_CALL2(SetTessellationPoints, pasPoints, sTessBaseData.m_uiCoordSize/3); + + if(stbUseCallbacks) + free(pasPoints); + +#ifdef A3D_DRAW_WITH_INDICES + // getting the normals for the callbacks + if(stbUseCallbacks) + { + A3DVector3dData* pasNormals = NULL; + stAllocVector3dArray(&pasNormals, sTess3DData.m_uiNormalSize/3); + + const A3DDouble* pdNormal = &sTess3DData.m_pdNormals[0]; + const A3DDouble* pdEnd = &sTess3DData.m_pdNormals[sTess3DData.m_uiNormalSize-1]; + A3DVector3dData* psCurNormal = &pasNormals[0]; + + for(; pdNormal < pdEnd; pdNormal += 3) + { + psCurNormal->m_dX = *pdNormal; + psCurNormal->m_dY = *(pdNormal+1); + psCurNormal->m_dZ = *(pdNormal+2); + psCurNormal++; + } + + A3D_DRAW_CALL2(SetTessellationNormals, pasNormals, sTess3DData.m_uiNormalSize/3); + + A3DMiscFree(pasNormals); + } +#endif + + A3DUns32 uiNumberOfFaces = sTess3DData.m_uiFaceTessSize; + + A3DUns32 ui; + for(ui = 0; ui < uiNumberOfFaces; ui++) + { + A3DTessFaceData& sTessFaceData = sTess3DData.m_psFaceTessData[ui]; + + A3DMiscCascadedAttributes* pAttr; + + A3D_INITIALIZE_DATA(A3DMiscCascadedAttributesData, sAttrData); + CHECK_RET(stCreateAndPushCascadedAttributesFace(pRepItem, pTess3D, &sTessFaceData, ui, pFatherAttr, &pAttr, + &sAttrData)); + + /* is there only one color/material for the face or for each triangle? */ + /* is there a texture ? */ + + //A3DBool bOneColorForFace = sTessFaceData.m_uiStyleIndexesSize == 1; + + A3DInt32 iUVCoordinatesIndex = -1; + A3DUns8 ucTextureDimension = 2; + + CHECK_RET(stDrawStyle(&sAttrData.m_sStyle, &iUVCoordinatesIndex, &ucTextureDimension)); + + //if(bOneColorForFace) + //{ + //A3DGraphStyleData sLineStyleData; + //A3D_INITIALIZE_DATA(sLineStyleData); + //CHECK_RET(A3DGlobalLineStyleGet(sTessFaceData.m_puiStyleIndexes[0],&sLineStyleData)) + + //CHECK_RET(stDrawStyle(&sLineStyleData, &iUVCoordinatesIndex, &ucTextureDimension)); + + //CHECK_RET(A3DGlobalLineStyleGet(NULL, &sLineStyleData)); + + //A3DGlobalLineStyleGet(A3D_DEFAULT_LINESTYLE_INDEX,&sLineStyleData); + //} + + if(sTessFaceData.m_uiSizesTriangulatedSize) + { + A3DUns32 uiCurrentSize = 0; + A3DUns32* puiTriangulatedIndexes = sTess3DData.m_puiTriangulatedIndexes + + sTessFaceData.m_uiStartTriangulated; + + if(sTessFaceData.m_usUsedEntitiesFlags & kA3DTessFaceDataTriangle) + { + /* number of triangles for this face */ + A3DUns32 uiNbTriangles = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiTri, uiId; + + //uiTotalTriangles += uiNbTriangles; + + A3DVector3dData* pasGNormals; + A3DVector3dData* pasGPoints; + stAllocNormalsAndPoints(&pasGNormals, uiNbTriangles*3, &pasGPoints, uiNbTriangles*3); + +#ifdef A3D_DRAW_WITH_INDICES + A3DUns32* pauiNormals = (A3DUns32*)A3DMiscAlloc(uiNbTriangles*3 * sizeof(A3DUns32)); + A3DUns32* pauiPoints = (A3DUns32*)A3DMiscAlloc(uiNbTriangles*3 * sizeof(A3DUns32)); +#endif + + for(uiTri = 0; uiTri < uiNbTriangles; uiTri++) + { + /* Point and normal #1 */ + uiId = *puiTriangulatedIndexes++; /* normal index */ + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[uiTri*3].m_dX = sTess3DData.m_pdNormals[uiId]; /* x */ + pasGNormals[uiTri*3].m_dY = sTess3DData.m_pdNormals[uiId+1]; /* y */ + pasGNormals[uiTri*3].m_dZ = sTess3DData.m_pdNormals[uiId+2]; /* z */ + } + +#ifdef A3D_DRAW_WITH_INDICES + pauiNormals[uiTri*3] = uiId/3; +#endif + + uiId = *puiTriangulatedIndexes++; /* point index */ + pasGPoints[uiTri*3].m_dX = sTessBaseData.m_pdCoords[uiId]; /* x */ + pasGPoints[uiTri*3].m_dY = sTessBaseData.m_pdCoords[uiId+1]; /* y */ + pasGPoints[uiTri*3].m_dZ = sTessBaseData.m_pdCoords[uiId+2]; /* z */ +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiTri*3] = uiId/3; +#endif + + /* Point and normal #2 */ + uiId = *puiTriangulatedIndexes++; /* normal index */ + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[uiTri*3+1].m_dX = sTess3DData.m_pdNormals[uiId]; /* x */ + pasGNormals[uiTri*3+1].m_dY = sTess3DData.m_pdNormals[uiId+1]; /* y */ + pasGNormals[uiTri*3+1].m_dZ = sTess3DData.m_pdNormals[uiId+2]; /* z */ + } + +#ifdef A3D_DRAW_WITH_INDICES + pauiNormals[uiTri*3+1] = uiId/3; +#endif + + uiId = *puiTriangulatedIndexes++; /* point index */ + pasGPoints[uiTri*3+1].m_dX = sTessBaseData.m_pdCoords[uiId]; /* x */ + pasGPoints[uiTri*3+1].m_dY = sTessBaseData.m_pdCoords[uiId+1]; /* y */ + pasGPoints[uiTri*3+1].m_dZ = sTessBaseData.m_pdCoords[uiId+2]; /* z */ +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiTri*3+1] = uiId/3; +#endif + + /* Point and normal #3 */ + uiId = *puiTriangulatedIndexes++; /* normal index */ + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[uiTri*3+2].m_dX = sTess3DData.m_pdNormals[uiId]; /* x */ + pasGNormals[uiTri*3+2].m_dY = sTess3DData.m_pdNormals[uiId+1]; /* y */ + pasGNormals[uiTri*3+2].m_dZ = sTess3DData.m_pdNormals[uiId+2]; /* z */ + } + +#ifdef A3D_DRAW_WITH_INDICES + pauiNormals[uiTri*3+2] = uiId/3; +#endif + + uiId = *puiTriangulatedIndexes++; /* point index */ + pasGPoints[uiTri*3+2].m_dX = sTessBaseData.m_pdCoords[uiId]; /* x */ + pasGPoints[uiTri*3+2].m_dY = sTessBaseData.m_pdCoords[uiId+1]; /* y */ + pasGPoints[uiTri*3+2].m_dZ = sTessBaseData.m_pdCoords[uiId+2]; /* z */ +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiTri*3+2] = uiId/3; +#endif + } + + A3D_DRAW_CALL3(Triangle, pasGNormals, pasGPoints, uiNbTriangles*3); + stFreeNormalsAndPoints(&pasGNormals, &pasGPoints); + +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_CALL3(TriangleWithIndices, pauiNormals, pauiPoints, uiNbTriangles*3); + A3DMiscFree(pauiNormals); + A3DMiscFree(pauiPoints); +#endif + } + + if(sTessFaceData.m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFan) + { + A3DUns32 uiNbFan = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiFan, uiPoint; + + for(uiFan = 0; uiFan < uiNbFan; uiFan++) + { + A3DUns32 uiNumberOfPointsForThisFan = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + + //if(uiNumberOfPointsForThisFan > 2) + // uiTotalTriangles += (uiNumberOfPointsForThisFan - 2); + + A3DVector3dData* pasGNormals; + A3DVector3dData* pasGPoints; + stAllocNormalsAndPoints(&pasGNormals, uiNumberOfPointsForThisFan, &pasGPoints, + uiNumberOfPointsForThisFan); + +#ifdef A3D_DRAW_WITH_INDICES + A3DUns32* pauiNormals = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisFan * sizeof(A3DUns32)); + A3DUns32* pauiPoints = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisFan * sizeof(A3DUns32)); +#endif + + A3DDouble* pdNormal = NULL; + A3DDouble* pdPoint = NULL; + for(uiPoint = 0; uiPoint < uiNumberOfPointsForThisFan; uiPoint++) + { +#ifdef A3D_DRAW_WITH_INDICES + pauiNormals[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdNormal = &sTess3DData.m_pdNormals[*puiTriangulatedIndexes++]; + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[uiPoint].m_dX = pdNormal[0]; + pasGNormals[uiPoint].m_dY = pdNormal[1]; + pasGNormals[uiPoint].m_dZ = pdNormal[2]; + } + +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiPoint].m_dX = pdPoint[0]; + pasGPoints[uiPoint].m_dY = pdPoint[1]; + pasGPoints[uiPoint].m_dZ = pdPoint[2]; + } + + A3D_DRAW_CALL3(TriangleFan, pasGNormals, pasGPoints, uiNumberOfPointsForThisFan); + stFreeNormalsAndPoints(&pasGNormals, &pasGPoints); + +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_CALL3(TriangleFanWithIndices, pauiNormals, pauiPoints, uiNumberOfPointsForThisFan); + A3DMiscFree(pauiNormals); + A3DMiscFree(pauiPoints); +#endif + } + } + + if(sTessFaceData.m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripe) + { + A3DUns32 uiNbStripe = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe, uiPoint; + for(uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + A3DUns32 uiNumberOfPointsForThisStripe = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + + //if(uiNumberOfPointsForThisStripe > 2) + // uiTotalTriangles += (uiNumberOfPointsForThisStripe - 2); + + A3DVector3dData* pasGNormals; + A3DVector3dData* pasGPoints; + stAllocNormalsAndPoints(&pasGNormals, uiNumberOfPointsForThisStripe, &pasGPoints, + uiNumberOfPointsForThisStripe); + +#ifdef A3D_DRAW_WITH_INDICES + A3DUns32* pauiNormals = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisStripe * sizeof(A3DUns32)); + A3DUns32* pauiPoints = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisStripe * sizeof(A3DUns32)); +#endif + + A3DDouble* pdNormal = NULL; + A3DDouble* pdPoint = NULL; + for(uiPoint = 0; uiPoint < uiNumberOfPointsForThisStripe; uiPoint++) + { +#ifdef A3D_DRAW_WITH_INDICES + pauiNormals[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdNormal = &sTess3DData.m_pdNormals[*puiTriangulatedIndexes++]; + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[uiPoint].m_dX = pdNormal[0]; + pasGNormals[uiPoint].m_dY = pdNormal[1]; + pasGNormals[uiPoint].m_dZ = pdNormal[2]; + } + +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiPoint].m_dX = pdPoint[0]; + pasGPoints[uiPoint].m_dY = pdPoint[1]; + pasGPoints[uiPoint].m_dZ = pdPoint[2]; + } + + A3D_DRAW_CALL3(TriangleStripe, pasGNormals, pasGPoints, uiNumberOfPointsForThisStripe); + stFreeNormalsAndPoints(&pasGNormals, &pasGPoints); + +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_CALL3(TriangleStripeWithIndices, pauiNormals, pauiPoints, uiNumberOfPointsForThisStripe); + A3DMiscFree(pauiNormals); + A3DMiscFree(pauiPoints); +#endif + } + } + + if(sTessFaceData.m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormal) + { + A3DUns32 uiTri, uiNbTriangles = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + + //uiTotalTriangles += uiNbTriangles; + + A3DVector3dData* pasGNormals; + A3DVector3dData* pasGPoints; + stAllocNormalsAndPoints(&pasGNormals, uiNbTriangles, &pasGPoints, uiNbTriangles*3); + +#ifdef A3D_DRAW_WITH_INDICES + A3DUns32* pauiNormals = (A3DUns32*)A3DMiscAlloc(uiNbTriangles * sizeof(A3DUns32)); + A3DUns32* pauiPoints = (A3DUns32*)A3DMiscAlloc(uiNbTriangles*3 * sizeof(A3DUns32)); +#endif + + A3DDouble* pdNormal = NULL; + A3DDouble* pdPoint = NULL; + for(uiTri = 0; uiTri < uiNbTriangles; uiTri++) + { +#ifdef A3D_DRAW_WITH_INDICES + pauiNormals[uiTri] = (*puiTriangulatedIndexes)/3; +#endif + pdNormal = &sTess3DData.m_pdNormals[*puiTriangulatedIndexes++]; + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[uiTri].m_dX = pdNormal[0]; + pasGNormals[uiTri].m_dY = pdNormal[1]; + pasGNormals[uiTri].m_dZ = pdNormal[2]; + } + +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiTri*3] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiTri*3].m_dX = pdPoint[0]; + pasGPoints[uiTri*3].m_dY = pdPoint[1]; + pasGPoints[uiTri*3].m_dZ = pdPoint[2]; +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiTri*3+1] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiTri*3+1].m_dX = pdPoint[0]; + pasGPoints[uiTri*3+1].m_dY = pdPoint[1]; + pasGPoints[uiTri*3+1].m_dZ = pdPoint[2]; +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiTri*3+2] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiTri*3+2].m_dX = pdPoint[0]; + pasGPoints[uiTri*3+2].m_dY = pdPoint[1]; + pasGPoints[uiTri*3+2].m_dZ = pdPoint[2]; + } + + A3D_DRAW_CALL3(TriangleOneNormal, pasGNormals, pasGPoints, uiNbTriangles*3); + stFreeNormalsAndPoints(&pasGNormals, &pasGPoints); + +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_CALL3(TriangleOneNormalWithIndices, pauiNormals, pauiPoints, uiNbTriangles*3); + A3DMiscFree(pauiNormals); + A3DMiscFree(pauiPoints); +#endif + } + + if(sTessFaceData.m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormal) + { + A3DUns32 uiNbFan = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiFan, uiSize, uiPoint; + for(uiFan = 0; uiFan < uiNbFan; uiFan++) + { + uiSize = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + + A3DUns32 uiNumberOfPointsForThisFan = (uiSize & kA3DTessFaceDataNormalMask); + + //if(uiNumberOfPointsForThisFan > 2) + // uiTotalTriangles += (uiNumberOfPointsForThisFan - 2); + + if(uiSize & kA3DTessFaceDataNormalSingle) /* only one normal for the entire fan */ + { + A3DVector3dData* pasGNormals; + A3DVector3dData* pasGPoints; + stAllocNormalsAndPoints(&pasGNormals, 1, &pasGPoints, uiNumberOfPointsForThisFan); + +#ifdef A3D_DRAW_WITH_INDICES + A3DUns32* pauiPoints = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisFan * sizeof(A3DUns32)); + A3DUns32 uiNormal = (*puiTriangulatedIndexes)/3; +#endif + + A3DDouble* pdNormal = NULL; + A3DDouble* pdPoint = NULL; + + pdNormal = &sTess3DData.m_pdNormals[*puiTriangulatedIndexes++]; + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[0].m_dX = pdNormal[0]; + pasGNormals[0].m_dY = pdNormal[1]; + pasGNormals[0].m_dZ = pdNormal[2]; + } + + for(uiPoint = 0; uiPoint < uiNumberOfPointsForThisFan; uiPoint++) + { +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiPoint].m_dX = pdPoint[0]; + pasGPoints[uiPoint].m_dY = pdPoint[1]; + pasGPoints[uiPoint].m_dZ = pdPoint[2]; + } + + A3D_DRAW_CALL3(TriangleFanOneNormal, &pasGNormals[0], pasGPoints, uiNumberOfPointsForThisFan); + stFreeNormalsAndPoints(&pasGNormals, &pasGPoints); + +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_CALL3(TriangleFanOneNormalWithIndices, uiNormal, pauiPoints, + uiNumberOfPointsForThisFan); + A3DMiscFree(pauiPoints); +#endif + } + else + { + A3DVector3dData* pasGNormals; + A3DVector3dData* pasGPoints; + stAllocNormalsAndPoints(&pasGNormals, uiNumberOfPointsForThisFan, &pasGPoints, + uiNumberOfPointsForThisFan); + +#ifdef A3D_DRAW_WITH_INDICES + A3DUns32* pauiNormals = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisFan * sizeof(A3DUns32)); + A3DUns32* pauiPoints = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisFan * sizeof(A3DUns32)); +#endif + + A3DDouble* pdNormal = NULL; + A3DDouble* pdPoint = NULL; + for(uiPoint = 0; uiPoint < uiNumberOfPointsForThisFan; uiPoint++) + { +#ifdef A3D_DRAW_WITH_INDICES + pauiNormals[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdNormal = &sTess3DData.m_pdNormals[*puiTriangulatedIndexes++]; + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[uiPoint].m_dX = pdNormal[0]; + pasGNormals[uiPoint].m_dY = pdNormal[1]; + pasGNormals[uiPoint].m_dZ = pdNormal[2]; + } + +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiPoint].m_dX = pdPoint[0]; + pasGPoints[uiPoint].m_dY = pdPoint[1]; + pasGPoints[uiPoint].m_dZ = pdPoint[2]; + } + + A3D_DRAW_CALL3(TriangleFan, pasGNormals, pasGPoints, uiNumberOfPointsForThisFan); + stFreeNormalsAndPoints(&pasGNormals, &pasGPoints); + +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_CALL3(TriangleFanWithIndices, pauiNormals, pauiPoints, uiNumberOfPointsForThisFan); + A3DMiscFree(pauiNormals); + A3DMiscFree(pauiPoints); +#endif + } + } + } + + if(sTessFaceData.m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormal) + { + A3DUns32 uiNbStripe = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe, uiPoint; + for(uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + A3DUns32 uiSize = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiNumberOfPointsForThisStripe = (uiSize & kA3DTessFaceDataNormalMask); + + //if(uiNumberOfPointsForThisStripe > 2) + // uiTotalTriangles += (uiNumberOfPointsForThisStripe - 2); + + if(uiSize & kA3DTessFaceDataNormalSingle) /* only one normal for the entire stripe */ + { + A3DVector3dData* pasGNormals; + A3DVector3dData* pasGPoints; + stAllocNormalsAndPoints(&pasGNormals, 1, &pasGPoints, uiNumberOfPointsForThisStripe); + +#ifdef A3D_DRAW_WITH_INDICES + A3DUns32* pauiPoints = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisStripe * + sizeof(A3DUns32)); + A3DUns32 uiNormal = (*puiTriangulatedIndexes)/3; +#endif + + A3DDouble* pdNormal = NULL; + A3DDouble* pdPoint = NULL; + + pdNormal = &sTess3DData.m_pdNormals[*puiTriangulatedIndexes++]; + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[0].m_dX = pdNormal[0]; + pasGNormals[0].m_dY = pdNormal[1]; + pasGNormals[0].m_dZ = pdNormal[2]; + } + + for(uiPoint = 0; uiPoint < uiNumberOfPointsForThisStripe; uiPoint++) + { +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiPoint].m_dX = pdPoint[0]; + pasGPoints[uiPoint].m_dY = pdPoint[1]; + pasGPoints[uiPoint].m_dZ = pdPoint[2]; + } + + A3D_DRAW_CALL3(TriangleStripeOneNormal, &pasGNormals[0], pasGPoints, + uiNumberOfPointsForThisStripe); + stFreeNormalsAndPoints(&pasGNormals, &pasGPoints); + +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_CALL3(TriangleStripeOneNormalWithIndices, uiNormal, pauiPoints, + uiNumberOfPointsForThisStripe); + A3DMiscFree(pauiPoints); +#endif + } + else + { + A3DVector3dData* pasGNormals; + A3DVector3dData* pasGPoints; + stAllocNormalsAndPoints(&pasGNormals, uiNumberOfPointsForThisStripe, &pasGPoints, + uiNumberOfPointsForThisStripe); + +#ifdef A3D_DRAW_WITH_INDICES + A3DUns32* pauiNormals = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisStripe * + sizeof(A3DUns32)); + A3DUns32* pauiPoints = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisStripe * + sizeof(A3DUns32)); +#endif + + A3DDouble* pdNormal = NULL; + A3DDouble* pdPoint = NULL; + for(uiPoint = 0; uiPoint < uiNumberOfPointsForThisStripe; uiPoint++) + { +#ifdef A3D_DRAW_WITH_INDICES + pauiNormals[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdNormal = &sTess3DData.m_pdNormals[*puiTriangulatedIndexes++]; + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[uiPoint].m_dX = pdNormal[0]; + pasGNormals[uiPoint].m_dY = pdNormal[1]; + pasGNormals[uiPoint].m_dZ = pdNormal[2]; + } + +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiPoint].m_dX = pdPoint[0]; + pasGPoints[uiPoint].m_dY = pdPoint[1]; + pasGPoints[uiPoint].m_dZ = pdPoint[2]; + } + + A3D_DRAW_CALL3(TriangleStripe, pasGNormals, pasGPoints, uiNumberOfPointsForThisStripe); + stFreeNormalsAndPoints(&pasGNormals, &pasGPoints); + +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_CALL3(TriangleStripeWithIndices, pauiNormals, pauiPoints, + uiNumberOfPointsForThisStripe); + A3DMiscFree(pauiNormals); + A3DMiscFree(pauiPoints); +#endif + } + } + } + + if(sTessFaceData.m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleTextured) + { + // number of triangles for this face + A3DUns32 uiNbTriangles = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiTri, uiId; + + // read the 3 points, and the 3 normals of each triangle and read the texture uv coordinates + + // For each point of the face we can have several uv coordinates indexes. + // This number of uv coordinates indexes is given by the parameter + // sTessFaceData.m_uiTextureCoordIndexesSize. To know which is the index to use read + // the parameter m_iUVCoordinatesIndex of the A3DTextureDefinition linked to this face -- see above. + + A3DDouble sUV1[2],sUV2[2],sUV3[2]; + A3DVector3dData* pasGNormals; + A3DVector3dData* pasGPoints; + stAllocNormalsAndPoints(&pasGNormals, uiNbTriangles*3, &pasGPoints, uiNbTriangles*3); + +#ifdef A3D_DRAW_WITH_INDICES + A3DUns32* pauiNormals = (A3DUns32*)A3DMiscAlloc(uiNbTriangles*3 * sizeof(A3DUns32)); + A3DUns32* pauiPoints = (A3DUns32*)A3DMiscAlloc(uiNbTriangles*3 * sizeof(A3DUns32)); +#endif + + for(uiTri = 0; uiTri < uiNbTriangles; uiTri++) + { + /* Point uv and normal #1 */ + uiId = *puiTriangulatedIndexes++; /* normal index */ + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[uiTri*3].m_dX = sTess3DData.m_pdNormals[uiId]; /* x */ + pasGNormals[uiTri*3].m_dY = sTess3DData.m_pdNormals[uiId+1]; /* y */ + pasGNormals[uiTri*3].m_dZ = sTess3DData.m_pdNormals[uiId+2]; /* z */ + } + +#ifdef A3D_DRAW_WITH_INDICES + pauiNormals[uiTri*3] = uiId/3; +#endif + + if(iUVCoordinatesIndex!=-1 && ucTextureDimension == 2 ) + { + uiId = *(puiTriangulatedIndexes+iUVCoordinatesIndex); /* UV index */ + sUV1[0] = sTess3DData.m_pdTextureCoords[uiId]; /* U */ + sUV1[1] = sTess3DData.m_pdTextureCoords[uiId+1]; /* V */ + } + puiTriangulatedIndexes+=sTessFaceData.m_uiTextureCoordIndexesSize; + + uiId = *puiTriangulatedIndexes++; /* point index */ + pasGPoints[uiTri*3].m_dX = sTessBaseData.m_pdCoords[uiId]; /* x */ + pasGPoints[uiTri*3].m_dY = sTessBaseData.m_pdCoords[uiId+1]; /* y */ + pasGPoints[uiTri*3].m_dZ = sTessBaseData.m_pdCoords[uiId+2]; /* z */ +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiTri*3] = uiId/3; +#endif + + /* Point uv and normal #2 */ + uiId = *puiTriangulatedIndexes++; /* normal index */ + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[uiTri*3+1].m_dX = sTess3DData.m_pdNormals[uiId]; /* x */ + pasGNormals[uiTri*3+1].m_dY = sTess3DData.m_pdNormals[uiId+1]; /* y */ + pasGNormals[uiTri*3+1].m_dZ = sTess3DData.m_pdNormals[uiId+2]; /* z */ + } + +#ifdef A3D_DRAW_WITH_INDICES + pauiNormals[uiTri*3+1] = uiId/3; +#endif + + if(iUVCoordinatesIndex!=-1 && ucTextureDimension == 2 ) + { + uiId = *(puiTriangulatedIndexes+iUVCoordinatesIndex); /* UV index */ + sUV2[0] = sTess3DData.m_pdTextureCoords[uiId]; /* U */ + sUV2[1] = sTess3DData.m_pdTextureCoords[uiId+1]; /* V */ + } + puiTriangulatedIndexes+=sTessFaceData.m_uiTextureCoordIndexesSize; + + uiId = *puiTriangulatedIndexes++; /* point index */ + pasGPoints[uiTri*3+1].m_dX = sTessBaseData.m_pdCoords[uiId]; /* x */ + pasGPoints[uiTri*3+1].m_dY = sTessBaseData.m_pdCoords[uiId+1]; /* y */ + pasGPoints[uiTri*3+1].m_dZ = sTessBaseData.m_pdCoords[uiId+2]; /* z */ +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiTri*3+1] = uiId/3; +#endif + + /* Point uv and normal #3 */ + uiId = *puiTriangulatedIndexes++; /* normal index */ + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[uiTri*3+2].m_dX = sTess3DData.m_pdNormals[uiId]; /* x */ + pasGNormals[uiTri*3+2].m_dY = sTess3DData.m_pdNormals[uiId+1]; /* y */ + pasGNormals[uiTri*3+2].m_dZ = sTess3DData.m_pdNormals[uiId+2]; /* z */ + } + +#ifdef A3D_DRAW_WITH_INDICES + pauiNormals[uiTri*3+2] = uiId/3; +#endif + + if(iUVCoordinatesIndex!=-1 && ucTextureDimension == 2 ) + { + uiId = *(puiTriangulatedIndexes+iUVCoordinatesIndex); /* UV index */ + sUV3[0] = sTess3DData.m_pdTextureCoords[uiId]; /* U */ + sUV3[1] = sTess3DData.m_pdTextureCoords[uiId+1]; /* V */ + } + puiTriangulatedIndexes+=sTessFaceData.m_uiTextureCoordIndexesSize; + + uiId = *puiTriangulatedIndexes++; /* point index */ + pasGPoints[uiTri*3+2].m_dX = sTessBaseData.m_pdCoords[uiId]; /* x */ + pasGPoints[uiTri*3+2].m_dY = sTessBaseData.m_pdCoords[uiId+1]; /* y */ + pasGPoints[uiTri*3+2].m_dZ = sTessBaseData.m_pdCoords[uiId+2]; /* z */ +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiTri*3+2] = uiId/3; +#endif + } + + A3D_DRAW_CALL3(Triangle, pasGNormals, pasGPoints, uiNbTriangles*3); + stFreeNormalsAndPoints(&pasGNormals, &pasGPoints); + +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_CALL3(TriangleWithIndices, pauiNormals, pauiPoints, uiNbTriangles*3); + A3DMiscFree(pauiNormals); + A3DMiscFree(pauiPoints); +#endif + } + + if(sTessFaceData.m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanTextured) + { + A3DUns32 uiNbFan = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiFan, uiPoint; + for(uiFan = 0; uiFan < uiNbFan; uiFan++) + { + A3DUns32 uiNumberOfPointsForThisFan = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + + //if(uiNumberOfPointsForThisFan > 2) + // uiTotalTriangles += (uiNumberOfPointsForThisFan - 2); + + A3DVector3dData* pasGNormals; + A3DVector3dData* pasGPoints; + stAllocNormalsAndPoints(&pasGNormals, uiNumberOfPointsForThisFan, &pasGPoints, + uiNumberOfPointsForThisFan); + +#ifdef A3D_DRAW_WITH_INDICES + A3DUns32* pauiNormals = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisFan * + sizeof(A3DUns32)); + A3DUns32* pauiPoints = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisFan * + sizeof(A3DUns32)); +#endif + + A3DDouble* pdNormal = NULL; + A3DDouble* pdPoint = NULL; + for(uiPoint = 0; uiPoint < uiNumberOfPointsForThisFan; uiPoint++) + { +#ifdef A3D_DRAW_WITH_INDICES + pauiNormals[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdNormal = &sTess3DData.m_pdNormals[*puiTriangulatedIndexes++]; + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[uiPoint].m_dX = pdNormal[0]; + pasGNormals[uiPoint].m_dY = pdNormal[1]; + pasGNormals[uiPoint].m_dZ = pdNormal[2]; + } + + // we're not reading the UV for now + puiTriangulatedIndexes += sTessFaceData.m_uiTextureCoordIndexesSize; + +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiPoint].m_dX = pdPoint[0]; + pasGPoints[uiPoint].m_dY = pdPoint[1]; + pasGPoints[uiPoint].m_dZ = pdPoint[2]; + } + + A3D_DRAW_CALL3(TriangleFan, pasGNormals, pasGPoints, uiNumberOfPointsForThisFan); + stFreeNormalsAndPoints(&pasGNormals, &pasGPoints); + +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_CALL3(TriangleFanWithIndices, pauiNormals, pauiPoints, + uiNumberOfPointsForThisFan); + A3DMiscFree(pauiNormals); + A3DMiscFree(pauiPoints); +#endif + } + } + else if(sTessFaceData.m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeTextured) + { + A3DUns32 uiNbStripe = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe, uiPoint; + for(uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + A3DUns32 uiNumberOfPointsForThisStripe = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + + //if(uiNumberOfPointsForThisStripe > 2) + // uiTotalTriangles += (uiNumberOfPointsForThisStripe - 2); + + A3DVector3dData* pasGNormals; + A3DVector3dData* pasGPoints; + stAllocNormalsAndPoints(&pasGNormals, uiNumberOfPointsForThisStripe, &pasGPoints, + uiNumberOfPointsForThisStripe); + +#ifdef A3D_DRAW_WITH_INDICES + A3DUns32* pauiNormals = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisStripe * sizeof(A3DUns32)); + A3DUns32* pauiPoints = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisStripe * sizeof(A3DUns32)); +#endif + + A3DDouble* pdNormal = NULL; + A3DDouble* pdPoint = NULL; + for(uiPoint = 0; uiPoint < uiNumberOfPointsForThisStripe; uiPoint++) + { +#ifdef A3D_DRAW_WITH_INDICES + pauiNormals[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdNormal = &sTess3DData.m_pdNormals[*puiTriangulatedIndexes++]; + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[uiPoint].m_dX = pdNormal[0]; + pasGNormals[uiPoint].m_dY = pdNormal[1]; + pasGNormals[uiPoint].m_dZ = pdNormal[2]; + } + + // we're not reading the UV for now + puiTriangulatedIndexes += sTessFaceData.m_uiTextureCoordIndexesSize; + +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiPoint].m_dX = pdPoint[0]; + pasGPoints[uiPoint].m_dY = pdPoint[1]; + pasGPoints[uiPoint].m_dZ = pdPoint[2]; + } + + A3D_DRAW_CALL3(TriangleStripe, pasGNormals, pasGPoints, uiNumberOfPointsForThisStripe); + stFreeNormalsAndPoints(&pasGNormals, &pasGPoints); + +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_CALL3(TriangleStripeWithIndices, pauiNormals, pauiPoints, uiNumberOfPointsForThisStripe); + A3DMiscFree(pauiNormals); + A3DMiscFree(pauiPoints); +#endif + } + } + else if(sTessFaceData.m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormalTextured) + { + A3DUns32 uiTri, uiNbTriangles = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + + // uiTotalTriangles += uiNbTriangles; + + A3DVector3dData* pasGNormals; + A3DVector3dData* pasGPoints; + stAllocNormalsAndPoints(&pasGNormals, uiNbTriangles, &pasGPoints, uiNbTriangles*3); + +#ifdef A3D_DRAW_WITH_INDICES + A3DUns32* pauiNormals = (A3DUns32*)A3DMiscAlloc(uiNbTriangles * sizeof(A3DUns32)); + A3DUns32* pauiPoints = (A3DUns32*)A3DMiscAlloc(uiNbTriangles*3 * sizeof(A3DUns32)); +#endif + + A3DDouble* pdNormal = NULL; + A3DDouble* pdPoint = NULL; + for(uiTri = 0; uiTri < uiNbTriangles; uiTri++) + { +#ifdef A3D_DRAW_WITH_INDICES + pauiNormals[uiTri] = (*puiTriangulatedIndexes)/3; +#endif + pdNormal = &sTess3DData.m_pdNormals[*puiTriangulatedIndexes++]; + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[uiTri].m_dX = pdNormal[0]; + pasGNormals[uiTri].m_dY = pdNormal[1]; + pasGNormals[uiTri].m_dZ = pdNormal[2]; + } + + // we're not reading the UV for now + puiTriangulatedIndexes += sTessFaceData.m_uiTextureCoordIndexesSize; + +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiTri*3] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiTri*3].m_dX = pdPoint[0]; + pasGPoints[uiTri*3].m_dY = pdPoint[1]; + pasGPoints[uiTri*3].m_dZ = pdPoint[2]; + + // we're not reading the UV for now + puiTriangulatedIndexes += sTessFaceData.m_uiTextureCoordIndexesSize; + +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiTri*3+1] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiTri*3+1].m_dX = pdPoint[0]; + pasGPoints[uiTri*3+1].m_dY = pdPoint[1]; + pasGPoints[uiTri*3+1].m_dZ = pdPoint[2]; + + // we're not reading the UV for now + puiTriangulatedIndexes += sTessFaceData.m_uiTextureCoordIndexesSize; + +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiTri*3+2] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiTri*3+2].m_dX = pdPoint[0]; + pasGPoints[uiTri*3+2].m_dY = pdPoint[1]; + pasGPoints[uiTri*3+2].m_dZ = pdPoint[2]; + } + + A3D_DRAW_CALL3(TriangleOneNormal, pasGNormals, pasGPoints, uiNbTriangles*3); + stFreeNormalsAndPoints(&pasGNormals, &pasGPoints); + +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_CALL3(TriangleOneNormalWithIndices, pauiNormals, pauiPoints, uiNbTriangles*3); + A3DMiscFree(pauiNormals); + A3DMiscFree(pauiPoints); +#endif + } + else if(sTessFaceData.m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormalTextured) + { + A3DUns32 uiNbFan = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiFan,uiSize, uiPoint; + for(uiFan=0;uiFan 2) + // uiTotalTriangles += (uiNumberOfPointsForThisFan - 2); + + if(uiSize & kA3DTessFaceDataNormalSingle) /* only one normal for the entire fan */ + { + A3DVector3dData* pasGNormals; + A3DVector3dData* pasGPoints; + stAllocNormalsAndPoints(&pasGNormals, 1, &pasGPoints, uiNumberOfPointsForThisFan); + +#ifdef A3D_DRAW_WITH_INDICES + A3DUns32* pauiPoints = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisFan * sizeof(A3DUns32)); + A3DUns32 uiNormal = (*puiTriangulatedIndexes)/3; +#endif + + A3DDouble* pdNormal = NULL; + A3DDouble* pdPoint = NULL; + + pdNormal = &sTess3DData.m_pdNormals[*puiTriangulatedIndexes++]; + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[0].m_dX = pdNormal[0]; + pasGNormals[0].m_dY = pdNormal[1]; + pasGNormals[0].m_dZ = pdNormal[2]; + } + + for(uiPoint = 0; uiPoint < uiNumberOfPointsForThisFan; uiPoint++) + { + // we're not reading the UV for now + puiTriangulatedIndexes += sTessFaceData.m_uiTextureCoordIndexesSize; + +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiPoint].m_dX = pdPoint[0]; + pasGPoints[uiPoint].m_dY = pdPoint[1]; + pasGPoints[uiPoint].m_dZ = pdPoint[2]; + } + + A3D_DRAW_CALL3(TriangleFanOneNormal, &pasGNormals[0], pasGPoints, uiNumberOfPointsForThisFan); + stFreeNormalsAndPoints(&pasGNormals, &pasGPoints); + +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_CALL3(TriangleFanOneNormalWithIndices, uiNormal, pauiPoints, + uiNumberOfPointsForThisFan); + A3DMiscFree(pauiPoints); +#endif + } + else + { + A3DVector3dData* pasGNormals; + A3DVector3dData* pasGPoints; + stAllocNormalsAndPoints(&pasGNormals, uiNumberOfPointsForThisFan, &pasGPoints, + uiNumberOfPointsForThisFan); + +#ifdef A3D_DRAW_WITH_INDICES + A3DUns32* pauiNormals = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisFan * sizeof(A3DUns32)); + A3DUns32* pauiPoints = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisFan * sizeof(A3DUns32)); +#endif + + A3DDouble* pdNormal = NULL; + A3DDouble* pdPoint = NULL; + for(uiPoint = 0; uiPoint < uiNumberOfPointsForThisFan; uiPoint++) + { +#ifdef A3D_DRAW_WITH_INDICES + pauiNormals[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdNormal = &sTess3DData.m_pdNormals[*puiTriangulatedIndexes++]; + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[uiPoint].m_dX = pdNormal[0]; + pasGNormals[uiPoint].m_dY = pdNormal[1]; + pasGNormals[uiPoint].m_dZ = pdNormal[2]; + } + + // we're not reading the UV for now + puiTriangulatedIndexes += sTessFaceData.m_uiTextureCoordIndexesSize; + +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiPoint].m_dX = pdPoint[0]; + pasGPoints[uiPoint].m_dY = pdPoint[1]; + pasGPoints[uiPoint].m_dZ = pdPoint[2]; + } + + A3D_DRAW_CALL3(TriangleFan, pasGNormals, pasGPoints, uiNumberOfPointsForThisFan); + stFreeNormalsAndPoints(&pasGNormals, &pasGPoints); + +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_CALL3(TriangleFanWithIndices, pauiNormals, pauiPoints, uiNumberOfPointsForThisFan); + A3DMiscFree(pauiNormals); + A3DMiscFree(pauiPoints); +#endif + } + } + } + else if(sTessFaceData.m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormalTextured) + { + A3DUns32 uiNbStripe = sTessFaceData.m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe, uiPoint; + for(uiStripe=0;uiStripe 2) + // uiTotalTriangless += (uiNumberOfPointsForThisStripe - 2); + + if(uiSize & kA3DTessFaceDataNormalSingle) /* only one normal for the entire stripe */ + { + A3DVector3dData* pasGNormals; + A3DVector3dData* pasGPoints; + stAllocNormalsAndPoints(&pasGNormals, 1, &pasGPoints, uiNumberOfPointsForThisStripe); + +#ifdef A3D_DRAW_WITH_INDICES + A3DUns32* pauiPoints = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisStripe * + sizeof(A3DUns32)); + A3DUns32 uiNormal = (*puiTriangulatedIndexes)/3; +#endif + + A3DDouble* pdNormal = NULL; + A3DDouble* pdPoint = NULL; + + pdNormal = &sTess3DData.m_pdNormals[*puiTriangulatedIndexes++]; + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[0].m_dX = pdNormal[0]; + pasGNormals[0].m_dY = pdNormal[1]; + pasGNormals[0].m_dZ = pdNormal[2]; + } + + for(uiPoint = 0; uiPoint < uiNumberOfPointsForThisStripe; uiPoint++) + { + // we're not reading the UV for now + puiTriangulatedIndexes += sTessFaceData.m_uiTextureCoordIndexesSize; + +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiPoint].m_dX = pdPoint[0]; + pasGPoints[uiPoint].m_dY = pdPoint[1]; + pasGPoints[uiPoint].m_dZ = pdPoint[2]; + } + + A3D_DRAW_CALL3(TriangleStripeOneNormal, &pasGNormals[0], pasGPoints, + uiNumberOfPointsForThisStripe); + stFreeNormalsAndPoints(&pasGNormals, &pasGPoints); + +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_CALL3(TriangleStripeOneNormalWithIndices, uiNormal, pauiPoints, + uiNumberOfPointsForThisStripe); + A3DMiscFree(pauiPoints); +#endif + } + else + { + A3DVector3dData* pasGNormals; + A3DVector3dData* pasGPoints; + stAllocNormalsAndPoints(&pasGNormals, uiNumberOfPointsForThisStripe, &pasGPoints, + uiNumberOfPointsForThisStripe); + +#ifdef A3D_DRAW_WITH_INDICES + A3DUns32* pauiNormals = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisStripe * + sizeof(A3DUns32)); + A3DUns32* pauiPoints = (A3DUns32*)A3DMiscAlloc(uiNumberOfPointsForThisStripe * + sizeof(A3DUns32)); +#endif + + A3DDouble* pdNormal = NULL; + A3DDouble* pdPoint = NULL; + for(uiPoint = 0; uiPoint < uiNumberOfPointsForThisStripe; uiPoint++) + { +#ifdef A3D_DRAW_WITH_INDICES + pauiNormals[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdNormal = &sTess3DData.m_pdNormals[*puiTriangulatedIndexes++]; + if (!sTess3DData.m_bMustRecalculateNormals) + { + pasGNormals[uiPoint].m_dX = pdNormal[0]; + pasGNormals[uiPoint].m_dY = pdNormal[1]; + pasGNormals[uiPoint].m_dZ = pdNormal[2]; + } + + // we're not reading the UV for now + puiTriangulatedIndexes += sTessFaceData.m_uiTextureCoordIndexesSize; + +#ifdef A3D_DRAW_WITH_INDICES + pauiPoints[uiPoint] = (*puiTriangulatedIndexes)/3; +#endif + pdPoint = &sTessBaseData.m_pdCoords[*puiTriangulatedIndexes++]; + pasGPoints[uiPoint].m_dX = pdPoint[0]; + pasGPoints[uiPoint].m_dY = pdPoint[1]; + pasGPoints[uiPoint].m_dZ = pdPoint[2]; + } + + A3D_DRAW_CALL3(TriangleStripe, pasGNormals, pasGPoints, uiNumberOfPointsForThisStripe); + stFreeNormalsAndPoints(&pasGNormals, &pasGPoints); + +#ifdef A3D_DRAW_WITH_INDICES + A3D_DRAW_CALL3(TriangleStripeWithIndices, pauiNormals, pauiPoints, + uiNumberOfPointsForThisStripe); + A3DMiscFree(pauiNormals); + A3DMiscFree(pauiPoints); +#endif + } + } + } + } + + CHECK_RET(A3DMiscCascadedAttributesDelete(pAttr)); + } + + //if(stpcRepresentationItemName != NULL) + A3D_DRAW_CALL1(End, kA3DDrawBeginEndRepresentationItem); + + if (sTess3DData.m_bMustRecalculateNormals) + sTess3DData.m_pdNormals=NULL; + CHECK_RET(A3DTessBaseGet(NULL, &sTessBaseData)); + CHECK_RET(A3DTess3DGet(NULL, &sTess3DData)); + + return iRet; +} + +//###################################################################################################################### +static bool stCheckExtent(const A3DBoundingBoxData* psExtent) +{ + if(psExtent->m_sMin.m_dX == -1.0e+020 || psExtent->m_sMin.m_dY == -1.0e+020 || psExtent->m_sMin.m_dZ == -1.0e+020) + return false; + if(psExtent->m_sMax.m_dX == -1.0e+020 || psExtent->m_sMax.m_dY == -1.0e+020 || psExtent->m_sMax.m_dZ == -1.0e+020) + return false; + return true; +} + +//###################################################################################################################### +static A3DStatus stEvaluateMarkupTessellationBox(const A3DTessBaseData* psTessBaseData, + const A3DTessMarkupData* psTessMarkupData, A3DBoundingBoxData* psBox) +{ + A3DStatus iRet = A3D_SUCCESS; + + if(psTessBaseData == NULL || psTessMarkupData == NULL) + return A3D_ERROR; + + if(psTessMarkupData->m_uiCodesSize == 0) + return A3D_ERROR; + + stExtentInit(psBox); + + const A3DDouble* pData = psTessBaseData->m_pdCoords; + + unsigned int k, kSize; + //TfFontKey sFontKey; + A3DBoundingBoxData sTextBox; + // to know if in "matrix" mode we've had some text + // and if we have to transform the text box with the current matrix + bool bGotText = false; + double adMatrix[16]; + + stExtentInit(&sTextBox); + + const A3DDouble* pTD = pData; + unsigned int uiCount; + const A3DUns32* puiStart = &psTessMarkupData->m_puiCodes[0]; + const A3DUns32* puiEnd = &psTessMarkupData->m_puiCodes[psTessMarkupData->m_uiCodesSize-1]; + + float fWidthMetrics, fHeightMetrics; + +#define DEFAULT_OFFSET \ + pData += *(puiStart+1); \ + puiStart += (uiCount + 1); // knowing we're gonna do puiStart++ right afterwards +#define MAKE_OFFSET(CountInt, CountFloats) \ + pData += CountFloats; \ + puiStart += (CountInt + 1); + + for(; puiStart < puiEnd; puiStart++) + { + uiCount = *puiStart & kA3DMarkupIntegerMask; + + if(*puiStart & kA3DMarkupIsExtraData) + { + switch(A3D_DECODE_EXTRA_DATA(*puiStart)) + { + case 6 : + case 7 : + case 8 : + MAKE_OFFSET(0, (*(puiStart+1) > 0) ? 3 : 0) + break; + case 2 : + kSize = *(puiStart+1) / 9; // triangle number + pTD = pData; + for(k = 0; k < kSize; k++) + { + stBoundingBoxAddPoint(psBox, *pTD, *(pTD+1), *(pTD+2)); + pTD += 3; + stBoundingBoxAddPoint(psBox, *pTD, *(pTD+1), *(pTD+2)); + pTD += 3; + stBoundingBoxAddPoint(psBox, *pTD, *(pTD+1), *(pTD+2)); + pTD += 3; + } + DEFAULT_OFFSET + break; + case 16 : + kSize = *(puiStart+1) / 3; // vertex number + pTD = pData; + for(k = 0; k < kSize; k++) + { + stBoundingBoxAddPoint(psBox, *pTD, *(pTD+1), *(pTD+2)); + pTD += 3; + } + DEFAULT_OFFSET + break; + case 15 : + kSize = *(puiStart+1) / 3; // vertex number + pTD = pData; + for(k = 0; k < kSize; k++) + { + stBoundingBoxAddPoint(psBox, *pTD, *(pTD+1), *(pTD+2)); + pTD += 3; + } + DEFAULT_OFFSET + break; + case 13 : + { + DEFAULT_OFFSET + } + break; + case 14 : + { + fWidthMetrics = (float)*pData; + fHeightMetrics = (float)*(pData+1); + bGotText = true; + stBoundingBoxAddPoint(&sTextBox, 0.0, 0.0, 0.0); + stBoundingBoxAddPoint(&sTextBox, fWidthMetrics, fHeightMetrics, 0.0); + DEFAULT_OFFSET + } + break; + default : + DEFAULT_OFFSET + } + } + else if(*puiStart & kA3DMarkupIsMatrix) + { + if(*(puiStart+1) > 0) // if there are floats, beginning the "matrix" mode + { + // getting the matrix stored in sMatrix + for(k = 0; k < 16; k++) + adMatrix[k] = (double)(*(pData + k)); + MAKE_OFFSET(0, 16) + } + else // if there aren't any floats, ending the "matrix" mode + { + if(bGotText) // if we've had some text in this "matrix" mode + { + // transforming the text box with the current matrix + A3DVector3dData& sMin = sTextBox.m_sMin; + A3DVector3dData& sMax = sTextBox.m_sMax; + stVectorMatrixMult(sMin.m_dX, sMin.m_dY, sMin.m_dZ, adMatrix, &sMin.m_dX, &sMin.m_dY, &sMin.m_dZ); + stVectorMatrixMult(sMax.m_dX, sMax.m_dY, sMax.m_dZ, adMatrix, &sMax.m_dX, &sMax.m_dY, &sMax.m_dZ); + stBoundingBoxAddPoint(psBox, sMin.m_dX, sMin.m_dY, sMin.m_dZ); + stBoundingBoxAddPoint(psBox, sMax.m_dX, sMax.m_dY, sMax.m_dZ); + stExtentInit(&sTextBox); + bGotText = false; + } + MAKE_OFFSET(0, 0) + } + } + else + { + kSize = *(puiStart+1) / 3; // vertex number + pTD = pData; + for(k = 0; k < kSize; k++) + { + stBoundingBoxAddPoint(psBox, *pTD, *(pTD+1), *(pTD+2)); + pTD += 3; + } + DEFAULT_OFFSET + } + } + +#undef DEFAULT_OFFSET +#undef MAKE_OFFSET + + if(stExtentIsValid(psBox)) + { + // we can have a box with NAN and infinite values + if(!stCheckExtent(psBox)) + iRet = A3D_ERROR; + } + + return iRet; +} + +//###################################################################################################################### +#define START_TREAT_DRWENTITY_ATTRIBUT \ + if(bUseAttribut) \ + { \ + stCreateAndPushCascadedAttributesDrwEntity((A3DDrawingBlock*)pRepItem, uiDrwEntityCount, pFatherAttr, &pAttr, &sAttrData); \ + CHECK_RET(stDrawStyle(&sAttrData.m_sStyle, NULL, NULL, &bPushMaterial, &bPushLineStipple, &bPushLineWidth)); \ + bShow = (sAttrData.m_bShow==TRUE); \ + } + + +//###################################################################################################################### +#define END_TREAT_DRWENTITY_ATTRIBUT \ + if(bUseAttribut) \ + { \ + CHECK_RET(A3DMiscCascadedAttributesDelete(pAttr)); \ + if (bPushLineStipple) \ + { \ + A3D_DRAW_CALL0(EndLineStipple); \ + bPushLineStipple = false; \ + } \ + if (bPushLineWidth) \ + { \ + A3D_DRAW_CALL0(EndLineWidth); \ + bPushLineWidth = false; \ + } \ + if (bPushMaterial) \ + { \ + A3D_DRAW_CALL0(EndMaterial); \ + } \ + uiDrwEntityCount++; \ + } + +//###################################################################################################################### +//static A3DStatus stTreatDrawingEntityAttribute(A3DRiRepresentationItem const * pRepItem, +// A3DMiscCascadedAttributes const * pFatherAttr, +// A3DUns32 uiDrwEntityCount) +//{ +// A3DMiscCascadedAttributes *pAttr; +// A3DMiscCascadedAttributesData sAttrData; +// stCreateAndPushCascadedAttributesDrwEntity((A3DDrawingBlock*)pRepItem, uiDrwEntityCount, pFatherAttr, pAttr, +// &sAttrData); +// +// return A3D_SUCCESS; +//} +static A3DStatus stDrawSet(const A3DRiSet* pSet, const A3DMiscCascadedAttributes* pFatherAttr); + +//###################################################################################################################### +static A3DStatus stDrawMarkupTessellation(const A3DTessBaseData* psTessBaseData, + const A3DTessMarkupData* psTessMarkupData, + const A3DRiRepresentationItem* pRepItem, + const A3DMiscCascadedAttributes* pFatherAttr) +{ + A3DStatus iRet = A3D_SUCCESS; + + if(psTessBaseData == NULL || psTessMarkupData == NULL) + return A3D_ERROR; + +#define DEFAULT_OFFSET {\ + pData += *(puiStart+1); \ + puiStart += (uiCount + 1); /* knowing we'll increment puiStart right afterwards */ \ + } +#define MAKE_OFFSET(CountInt, CountFloats) {\ + pData += CountFloats; \ + puiStart += (CountInt + 1); \ + } + + double dFixedSize = 1.0;//_GetFixedSize(); + //double dFixedSizeArrow = dFixedSize * SIZE_ARROW; + //double dScaleText=1.0; + //float fFontScale; + //A3DVector3dData sPntFrame; + //TfwOldMatrix sMatGroup; + bool bIsScreenMarkupZoomable = true; + unsigned int kSize; + unsigned int uiCount = 0; + A3DDouble adMatrix[16]; + + A3DDouble adMv[16], adPr[16]; + A3DInt32 aiVp[4]; + A3D_DRAW_CALL3(GetDrawContext, adPr, adMv, aiVp); + + bool bUseAttribut = false; + if(pRepItem != NULL) + { + A3DEEntityType eType=kA3DTypeUnknown; + CHECK_RET(A3DEntityGetType(pRepItem, &eType)); + if(eType==kA3DTypeDrawingBlockBasic || eType==kA3DTypeDrawingBlockOperator) + bUseAttribut = true; + } + + A3DMiscCascadedAttributesData sAttrData; + A3DMiscCascadedAttributes* pAttr = NULL; + + A3DGraphRgbColorData sRgbColorData; + A3D_INITIALIZE_DATA(A3DGraphRgbColorData, sRgbColorData); + A3DGraphStyleData sGraphStyleData; + A3D_INITIALIZE_DATA(A3DGraphStyleData, sGraphStyleData); + A3DFontKeyData sFontKeyData; + A3D_INITIALIZE_DATA(A3DFontKeyData, sFontKeyData); + A3DGraphPictureData sPictureData; + A3D_INITIALIZE_DATA(A3DGraphPictureData, sPictureData); + + bIsScreenMarkupZoomable = (psTessMarkupData->m_cBehaviour & kA3DMarkupIsZoomable) != 0; + const A3DDouble* pData = psTessBaseData->m_pdCoords; + const A3DUns32* puiStart = &psTessMarkupData->m_puiCodes[0]; + const A3DUns32* puiEnd = &psTessMarkupData->m_puiCodes[psTessMarkupData->m_uiCodesSize-1]; + + A3DUns32 uiDrwEntityCount = 0; + bool bShow, bPushMaterial = false; + bool bPushLineStipple = false; + bool bPushLineWidth = false; + + for(; puiStart < puiEnd; puiStart++) + { + uiCount = *puiStart & kA3DMarkupIntegerMask; + bShow = true; + + if(*puiStart & kA3DMarkupIsExtraData) + { + A3DUns32 uiExtraDataValue = A3D_DECODE_EXTRA_DATA(*puiStart); + switch(uiExtraDataValue) + { + case 2 : // triangles + { + kSize = *(puiStart+1) / 9; // triangle number + A3D_DRAW_CALL2(MarkupTriangle, pData, kSize*3); + DEFAULT_OFFSET; + } + break; + case 6 : // faceview + { + if(*(puiStart+1) > 0) + { + A3DVector3dData sP1, sP2, sP3, sP1Proj, sP2Proj, sP3Proj; + A3D_INITIALIZE_DATA(A3DVector3dData, sP1); + A3D_INITIALIZE_DATA(A3DVector3dData, sP2); + A3D_INITIALIZE_DATA(A3DVector3dData, sP3); + A3D_INITIALIZE_DATA(A3DVector3dData, sP1Proj); + A3D_INITIALIZE_DATA(A3DVector3dData, sP2Proj); + A3D_INITIALIZE_DATA(A3DVector3dData, sP3Proj); + sP1.m_dX = 0.0; sP1.m_dY = 0.0; sP1.m_dZ = 0.0; + sP2.m_dX = 1.0; sP2.m_dY = 0.0; sP2.m_dZ = 0.0; + sP3.m_dX = 0.0; sP3.m_dY = 1.0; sP3.m_dZ = 0.0; + A3D_DRAW_CALL2(UnProject, &sP1, &sP1Proj); + A3D_DRAW_CALL2(UnProject, &sP2, &sP2Proj); + A3D_DRAW_CALL2(UnProject, &sP3, &sP3Proj); + stGetFaceViewMatrix(&sP1Proj, &sP2Proj, &sP3Proj, adMatrix); + adMatrix[12] = *pData; + adMatrix[13] = *(pData+1); + adMatrix[14] = *(pData+2); + A3D_DRAW_CALL0(PushMatrix); + A3D_DRAW_CALL1(MultMatrix, adMatrix); + + MAKE_OFFSET(0, 3); + } + else + { + A3D_DRAW_CALL0(PopMatrix); + MAKE_OFFSET(0, 0); + } + } + break; + case 7 : // framedraw + { + if(*(puiStart+1) > 0) + { + A3DVector3dData sP; + A3D_INITIALIZE_DATA(A3DVector3dData, sP); + sP.m_dX = *pData; + sP.m_dY = *(pData+1); + sP.m_dZ = *(pData+2); + A3D_DRAW_CALL3(BeginFrameDraw, &sP, bIsScreenMarkupZoomable, dFixedSize); + + MAKE_OFFSET(0, 3); + } + else + { + A3D_DRAW_CALL0(EndFrameDraw); + + MAKE_OFFSET(0, 0); + } + } + break; + case 8 : // fixedsize + { + if(*(puiStart+1) > 0) + { + A3DVector3dData sP; + A3D_INITIALIZE_DATA(A3DVector3dData, sP); + sP.m_dX = *pData; + sP.m_dY = *(pData+1); + sP.m_dZ = *(pData+2); + A3D_DRAW_CALL1(BeginFixedSize, &sP); + + MAKE_OFFSET(0, 3); + } + else + { + A3D_DRAW_CALL0(EndFixedSize); + + MAKE_OFFSET(0, 0); + } + } + break; + case 10 : // cylinder + { + A3D_DRAW_CALL3(Cylinder, *pData, *(pData+1), *(pData+2)); + DEFAULT_OFFSET; + } + break; + case 9 : // symbol + { + A3DVector3dData sPosition; + A3D_INITIALIZE_DATA(A3DVector3dData, sPosition); + sPosition.m_dX = *pData; + sPosition.m_dY = *(pData+1); + sPosition.m_dZ = *(pData+2); + A3DGraphVPicturePatternData sPatternData; + A3D_INITIALIZE_DATA(A3DGraphVPicturePatternData, sPatternData); + CHECK_RET(A3DGlobalGetGraphVPicturePatternData(*(puiStart+2), &sPatternData)); + A3D_DRAW_CALL2(Symbol, &sPatternData, &sPosition); + DEFAULT_OFFSET; + } + break; + case 16 : // polygon + { + kSize = *(puiStart+1) / 3; // vertex number + A3D_DRAW_CALL2(Polygon, pData, kSize); + DEFAULT_OFFSET; + } + break; + case 11 : // color + { + CHECK_RET(A3DGlobalGetGraphRgbColorData(*(puiStart+2), &sRgbColorData)); + A3DDouble adColor[3] = { sRgbColorData.m_dRed, sRgbColorData.m_dGreen, sRgbColorData.m_dBlue }; + A3D_DRAW_CALL1(Color,adColor); + CHECK_RET(A3DGlobalGetGraphRgbColorData(A3D_DEFAULT_COLOR_INDEX, &sRgbColorData)); + DEFAULT_OFFSET; + } + break; + case 12 : // line stipple + { + if(uiCount > 0) + { + CHECK_RET(A3DGlobalGetGraphStyleData(*(puiStart+2), &sGraphStyleData)); + A3D_DRAW_CALL1(BeginLineStipple, &sGraphStyleData); + CHECK_RET(A3DGlobalGetGraphStyleData(A3D_DEFAULT_STYLE_INDEX, &sGraphStyleData)); + } + else + A3D_DRAW_CALL0(EndLineStipple); + DEFAULT_OFFSET; + } + break; + case 17 : // line width + { + if(*(puiStart+1) > 0) + { + A3D_DRAW_CALL1(BeginLineWidth, *pData); + } + else + A3D_DRAW_CALL0(EndLineWidth); + DEFAULT_OFFSET; + } + break; + case 15 : // points + { + START_TREAT_DRWENTITY_ATTRIBUT; + kSize = *(puiStart+1) / 3; // vertex number + if(bShow) + A3D_DRAW_CALL2(Point, pData, kSize); + DEFAULT_OFFSET; + END_TREAT_DRWENTITY_ATTRIBUT; + } + break; + case 13 : // font + { + sFontKeyData.m_iFontFamilyIndex = *(puiStart+2); + sFontKeyData.m_iFontStyleIndex = (*(puiStart+3) & kA3DFontKeyStyle) >> 24; + sFontKeyData.m_iFontSizeIndex = (*(puiStart+3) & kA3DFontKeySize) >> 12; + sFontKeyData.m_cAttributes = (A3DInt8)(*(puiStart+3) & kA3DFontKeyAttrib); + A3D_DRAW_CALL1(Font, &sFontKeyData); + DEFAULT_OFFSET; + } + break; + case 14 : // text + { + A3DUns32 uiTextIndex = *(puiStart+2); + A3DUTF8Char* pcBuffer = NULL; + if(uiTextIndex < psTessMarkupData->m_uiTextsSize) + pcBuffer = psTessMarkupData->m_ppcTexts[uiTextIndex]; + //A3D_DRAW_CALL3(Text, pcBuffer, *pData, *(pData+1)); + + // Draw Text + A3DRiSet *pSet = NULL; + A3DDouble dLength = 0.; + + if(A3DGlobalFontTextTessellationGet(&sFontKeyData, pcBuffer, &pSet, &dLength) == A3D_SUCCESS) + { + A3DRiSetData sDataSet; + A3D_INITIALIZE_DATA(A3DRiSetData, sDataSet); + + if(A3DRiSetGet(pSet, &sDataSet) == A3D_SUCCESS) + { + A3DMiscCascadedAttributes* psCascadeAttribute; + A3DMiscCascadedAttributesCreate(&psCascadeAttribute); + stDrawSet(pSet, psCascadeAttribute); + A3DMiscCascadedAttributesDelete(psCascadeAttribute); + A3DRiSetGet(nullptr, &sDataSet); + } + } + + A3DGlobalFontTextTessellationGet(NULL, pcBuffer, &pSet, &dLength); + + DEFAULT_OFFSET; + } + break; + case 0 : // pattern + { + START_TREAT_DRWENTITY_ATTRIBUT; + if(bShow) + { + A3DUns32 uiLoopCount = uiCount-3; + A3DUns32* puiLoopsPointSize = (A3DUns32*)malloc(uiLoopCount * sizeof(A3DUns32)); + for(A3DUns32 ui = 0; ui < uiLoopCount; ui++) + puiLoopsPointSize[ui] = *(puiStart+5+ui); + A3D_DRAW_CALL6(Pattern, uiLoopCount, *(puiStart+2), *(puiStart+3), *(puiStart+4), pData, + puiLoopsPointSize); + free(puiLoopsPointSize); + } + DEFAULT_OFFSET; + END_TREAT_DRWENTITY_ATTRIBUT; + } + break; + case 1 : // picture + { + START_TREAT_DRWENTITY_ATTRIBUT; + if(bShow) + { + CHECK_RET(A3DGlobalGetGraphPictureData(*(puiStart+2), &sPictureData)); + A3D_DRAW_CALL1(Picture, &sPictureData); + } + DEFAULT_OFFSET; + END_TREAT_DRWENTITY_ATTRIBUT; + } + break; + default : + DEFAULT_OFFSET; + } + } + else if(*puiStart & kA3DMarkupIsMatrix) + { + if(*(puiStart+1) > 0) // if there are floats, beginning the "matrix" mode + { + A3D_DRAW_CALL0(PushMatrix); + A3D_DRAW_CALL1(MultMatrix, pData); + //dScaleText=stGetScaleText(pData); + MAKE_OFFSET(0, 16); + } + else // if there aren't any floats, ending the "matrix" mode + { + A3D_DRAW_CALL0(PopMatrix); + MAKE_OFFSET(0, 0); + } + } + else + { + START_TREAT_DRWENTITY_ATTRIBUT; + if(bShow) + { + kSize = *(puiStart+1) / 3; // vertex number + A3D_DRAW_CALL2(PolyLine, pData, kSize); + } + DEFAULT_OFFSET; + END_TREAT_DRWENTITY_ATTRIBUT; + } + } + +#undef DEFAULT_OFFSET +#undef MAKE_OFFSET +#undef SIZE_ARROW + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stDrawTessMarkup(const A3DTessMarkup* pTessMarkup, const A3DRiRepresentationItem* pRepItem, + const A3DMiscCascadedAttributes* pFatherAttr) +{ + A3DStatus iRet = A3D_SUCCESS; + + //A3DInternalMarkup* psTessMarkup = TFG_BASE_NEW A3DInternalMarkup(); + + A3DTessMarkupData sMarkupData; + A3D_INITIALIZE_DATA(A3DTessMarkupData, sMarkupData); + CHECK_RET(A3DTessMarkupGet(pTessMarkup, &sMarkupData)); + + if((sMarkupData.m_cBehaviour & kA3DMarkupIsHidden) || sMarkupData.m_uiCodesSize == 0) + { + CHECK_RET(A3DTessMarkupGet(NULL, &sMarkupData)); + return iRet; + } + + A3DTessBaseData sBaseData; + A3D_INITIALIZE_DATA(A3DTessBaseData, sBaseData); + CHECK_RET(A3DTessBaseGet(pTessMarkup, &sBaseData)); + + if(stbUseCallbacks) + stDrawMarkupTessellation(&sBaseData, &sMarkupData, pRepItem, pFatherAttr); + else + { + A3DBoundingBoxData sMarkupBox; + stEvaluateMarkupTessellationBox(&sBaseData, &sMarkupData, &sMarkupBox); + stExtentUnion(&sMarkupBox, stpsBoundingBox, stpsBoundingBox); + } + + CHECK_RET(A3DTessBaseGet(NULL, &sBaseData)); + CHECK_RET(A3DTessMarkupGet(NULL, &sMarkupData)); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stDrawTessBase(A3DTessBase* pTessBase, const A3DRiRepresentationItem* pRepItem, + const A3DMiscCascadedAttributes* pFatherAttr) +{ + if(pTessBase == NULL) + return A3D_ERROR; + + A3DStatus iRet = A3D_SUCCESS; + + A3DEEntityType eEntityType; + CHECK_RET(A3DEntityGetType(pTessBase, &eEntityType)); + + switch(eEntityType) + { + case kA3DTypeTess3D : + { + CHECK_RET(stDrawTess3D((A3DTess3D*)pTessBase, pRepItem, pFatherAttr)); + break; + } + case kA3DTypeTess3DWire : + { + CHECK_RET(stDrawTess3DWire((A3DTess3DWire*)pTessBase, pRepItem, pFatherAttr)); + break; + } + case kA3DTypeTessMarkup : + { + CHECK_RET(stDrawTessMarkup((A3DTessMarkup*)pTessBase, pRepItem, pFatherAttr)); + break; + } + default: + break; + } + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stDrawRepresentationItem(const A3DRiRepresentationItem* pRepItem, + const A3DMiscCascadedAttributes* pFatherAttr); + +//###################################################################################################################### +static A3DStatus stDrawSet(const A3DRiSet* pSet, const A3DMiscCascadedAttributes* pFatherAttr) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DMiscCascadedAttributes* pAttr; + A3DMiscCascadedAttributesData sAttrData; + CHECK_RET(stCreateAndPushCascadedAttributes(pSet, pFatherAttr, &pAttr, &sAttrData)); + + if(sAttrData.m_bShow && !sAttrData.m_bRemoved && stIsShow(pSet) == A3D_SUCCESS) + { + A3DRiSetData sData; + A3D_INITIALIZE_DATA(A3DRiSetData, sData); + CHECK_RET(A3DRiSetGet(pSet, &sData)); + + A3DUns32 ui; + for(ui = 0; ui < sData.m_uiRepItemsSize; ui++) + { + CHECK_RET(stDrawRepresentationItem(sData.m_ppRepItems[ui], pAttr)); + } + + CHECK_RET(A3DRiSetGet(NULL, &sData)); + } + + CHECK_RET(A3DMiscCascadedAttributesDelete(pAttr)); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stDrawRepresentationItem(const A3DRiRepresentationItem* pRepItem, + const A3DMiscCascadedAttributes* pFatherAttr) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DMiscCascadedAttributes* pAttr; + A3DMiscCascadedAttributesData sAttrData; + CHECK_RET(stCreateAndPushCascadedAttributes(pRepItem, pFatherAttr, &pAttr, &sAttrData)); + + if(sAttrData.m_bShow && !sAttrData.m_bRemoved && stIsShow(pRepItem) == A3D_SUCCESS) + { + A3DEEntityType eType=kA3DTypeUnknown; + CHECK_RET(A3DEntityGetType(pRepItem, &eType)); + + if(eType == kA3DTypeRiSet) + { + CHECK_RET(stDrawSet((A3DRiSet*)pRepItem, pAttr)); + } + else + { + //uiTotalRepItems++; + + A3DRootBaseData sRootBaseData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sRootBaseData); + CHECK_RET(A3DRootBaseGet(pRepItem, &sRootBaseData)); + stpcRepresentationItemName = sRootBaseData.m_pcName; + + if(sRootBaseData.m_uiSize>0) + { + for(A3DUns32 ui=0;uim_uiAnnotationsSize; + for(ui = 0; ui < uiSize; ui++) + { + CHECK_RET(stAnnotationGetMarkups(psPartData->m_ppAnnotations[ui], psArray)); + } + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stDrawPartDefinition(const A3DAsmPartDefinition* pPart, const A3DMiscCascadedAttributes* pFatherAttr) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DMiscCascadedAttributes* pAttr; + A3DMiscCascadedAttributesData sAttrData; + CHECK_RET(stCreateAndPushCascadedAttributes(pPart, pFatherAttr, &pAttr, &sAttrData)); + + if(sAttrData.m_bShow && !sAttrData.m_bRemoved && stIsShow(pPart) == A3D_SUCCESS) + { + A3DAsmPartDefinitionData sData; + A3D_INITIALIZE_DATA(A3DAsmPartDefinitionData, sData); + CHECK_RET(A3DAsmPartDefinitionGet(pPart, &sData)); + + CHECK_RET(stDrawBoundingBox(&sData.m_sBoundingBox)); + + if(stbDraw3D) + { + A3DUns32 ui; + for(ui = 0; ui < sData.m_uiRepItemsSize; ui++) + { + CHECK_RET(stDrawRepresentationItem(sData.m_ppRepItems[ui], pAttr)); + } + } + + if(stbDrawMarkups) + { + A3DPointerArray sMarkups; + stPointerArrayInitialize(&sMarkups); + stPartDefinitionGetMarkups(&sData, &sMarkups); + A3DUns32 ui; +#ifdef VIEWS + for(ui = 0; ui < sData.m_uiViewsSize; ui++) + CHECK_RET(stDrawView(sData.m_ppViews[ui], pAttr)); +#endif + A3DUns32 uiSize = sMarkups.m_uiSize; + for(ui = 0; ui < uiSize; ui++) + CHECK_RET(DrawMarkup(sMarkups.m_ppPointers[ui], pAttr)); + + stPointerArrayTerminate(&sMarkups); + } + + CHECK_RET(A3DAsmPartDefinitionGet(NULL, &sData)); + } + + CHECK_RET(A3DMiscCascadedAttributesDelete(pAttr)); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stProductOccurrenceGetExternalData(const A3DAsmProductOccurrenceData* psPOccData, + A3DAsmProductOccurrence** ppExternalData) +{ + if(psPOccData == NULL) + return A3D_ERROR; + + A3DStatus iRet = A3D_SUCCESS; + + if(psPOccData->m_pExternalData == NULL && psPOccData->m_pPrototype != NULL) + { + A3DAsmProductOccurrenceData sProductPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductPrototypeData); + CHECK_RET(A3DAsmProductOccurrenceGet(psPOccData->m_pPrototype, &sProductPrototypeData)); + + CHECK_RET(stProductOccurrenceGetExternalData(&sProductPrototypeData, ppExternalData)); + + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sProductPrototypeData)); + } + else + *ppExternalData = psPOccData->m_pExternalData; + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stProductOccurrenceGetPart(const A3DAsmProductOccurrenceData* psPOccData, + A3DAsmPartDefinition** ppPart) +{ + if(psPOccData == NULL) + return A3D_ERROR; + + A3DStatus iRet = A3D_SUCCESS; + + *ppPart = NULL; + + if(psPOccData->m_pPart != NULL) + { + *ppPart = psPOccData->m_pPart; + return iRet; + } + + A3DAsmProductOccurrence* pProductPrototype = psPOccData->m_pPrototype; + while(pProductPrototype != NULL) + { + A3DAsmProductOccurrenceData sProductPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductPrototypeData); + CHECK_RET(A3DAsmProductOccurrenceGet(pProductPrototype, &sProductPrototypeData)); + + if(sProductPrototypeData.m_pPart != NULL) + { + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sProductPrototypeData)); + *ppPart = sProductPrototypeData.m_pPart; + return iRet; + } + else + pProductPrototype = sProductPrototypeData.m_pPrototype; + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sProductPrototypeData)); + } + + if(psPOccData->m_uiPOccurrencesSize == 0) + { + A3DAsmProductOccurrence* pExternal = NULL; + CHECK_RET(stProductOccurrenceGetExternalData(psPOccData, &pExternal)); + if(pExternal != NULL) + { + A3DAsmProductOccurrenceData sExternalDataData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sExternalDataData); + CHECK_RET(A3DAsmProductOccurrenceGet(pExternal, &sExternalDataData)); + A3DAsmPartDefinition* pPartDefinition; + CHECK_RET(stProductOccurrenceGetPart(&sExternalDataData, &pPartDefinition)); + *ppPart = pPartDefinition; + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sExternalDataData)); + + return iRet; + } + } + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stProductOccurrenceGetLocation(const A3DAsmProductOccurrenceData* psPOccData, + A3DMiscCartesianTransformation** ppLocation) +{ + if(psPOccData == NULL) + return A3D_ERROR; + + A3DStatus iRet = A3D_SUCCESS; + + *ppLocation = NULL; + + if(psPOccData->m_pLocation != NULL) + { + *ppLocation = psPOccData->m_pLocation; + return iRet; + } + + A3DAsmProductOccurrence* pProductPrototype = psPOccData->m_pPrototype; + while(pProductPrototype != NULL) + { + A3DAsmProductOccurrenceData sProductPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductPrototypeData); + CHECK_RET(A3DAsmProductOccurrenceGet(pProductPrototype, &sProductPrototypeData)); + + if(sProductPrototypeData.m_pLocation != NULL) + { + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sProductPrototypeData)); + *ppLocation = sProductPrototypeData.m_pLocation; + return iRet; + } + else + pProductPrototype = sProductPrototypeData.m_pPrototype; + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sProductPrototypeData)); + } + + if(psPOccData->m_uiPOccurrencesSize == 0) + { + A3DAsmProductOccurrence* pExternal = NULL; + CHECK_RET(stProductOccurrenceGetExternalData(psPOccData, &pExternal)); + if(pExternal != NULL) + { + A3DAsmProductOccurrenceData sExternalDataData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sExternalDataData); + CHECK_RET(A3DAsmProductOccurrenceGet(pExternal, &sExternalDataData)); + A3DAsmPartDefinition* pLoc; + CHECK_RET(stProductOccurrenceGetLocation(&sExternalDataData, &pLoc)); + *ppLocation = pLoc; + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sExternalDataData)); + + return iRet; + } + } + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stProductOccurrenceGetOccurrences(const A3DAsmProductOccurrenceData* psPOccData, + A3DPointerArray* psArray) +{ + if(psPOccData == NULL || psArray == NULL) + return A3D_ERROR; + + A3DStatus iRet = A3D_SUCCESS; + + if(psPOccData->m_uiPOccurrencesSize == 0 && psPOccData->m_pPrototype != NULL) + { + A3DAsmProductOccurrenceData sPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sPrototypeData); + CHECK_RET(A3DAsmProductOccurrenceGet(psPOccData->m_pPrototype, &sPrototypeData)); + + CHECK_RET(stProductOccurrenceGetOccurrences(&sPrototypeData, psArray)); + + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sPrototypeData)); + } + else + { + stPointerArrayAddArray(psArray, psPOccData->m_ppPOccurrences, psPOccData->m_uiPOccurrencesSize); + } + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stProductOccurrenceGetSons(const A3DAsmProductOccurrenceData* psPOccData, A3DPointerArray* psArray) +{ + if(psPOccData == NULL || psArray == NULL) + return A3D_ERROR; + + A3DStatus iRet = A3D_SUCCESS; + + CHECK_RET(stProductOccurrenceGetOccurrences(psPOccData, psArray)); + + A3DAsmProductOccurrence* pExternal = NULL; + CHECK_RET(stProductOccurrenceGetExternalData(psPOccData, &pExternal)); + if(pExternal != NULL) + { + A3DAsmProductOccurrenceData sExternalDataData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sExternalDataData); + CHECK_RET(A3DAsmProductOccurrenceGet(pExternal, &sExternalDataData)); + + if(psArray->m_uiSize == 0) + { + CHECK_RET(stProductOccurrenceGetSons(&sExternalDataData, psArray)); + } + else + stPointerArrayAdd(psArray, pExternal); + + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sExternalDataData)); + } + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stProductOccurrenceGetViews(const A3DAsmProductOccurrenceData* psPOccData, A3DPointerArray* psArray) +{ + if(psPOccData == NULL || psArray == NULL) + return A3D_ERROR; + + A3DStatus iRet = A3D_SUCCESS; + + if(psPOccData->m_uiViewsSize == 0 && psPOccData->m_pPrototype != NULL) + { + A3DAsmProductOccurrenceData sPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sPrototypeData); + CHECK_RET(A3DAsmProductOccurrenceGet(psPOccData->m_pPrototype, &sPrototypeData)); + + CHECK_RET(stProductOccurrenceGetViews(&sPrototypeData, psArray)); + + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sPrototypeData)); + } + else + stPointerArrayAddArray(psArray, psPOccData->m_ppViews, psPOccData->m_uiViewsSize); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stAnnotationSetGetMarkups(const A3DMkpAnnotationSet* pAnnotationSet, A3DPointerArray* psArray) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DMkpAnnotationSetData sAnnotationSetData; + A3D_INITIALIZE_DATA(A3DMkpAnnotationSetData, sAnnotationSetData); + CHECK_RET(A3DMkpAnnotationSetGet(pAnnotationSet,&sAnnotationSetData)); + + for(A3DUns32 ui = 0; ui < sAnnotationSetData.m_uiAnnotationsSize; ui++) + { + CHECK_RET(stAnnotationGetMarkups(sAnnotationSetData.m_ppAnnotations[ui], psArray)); + } + + CHECK_RET(A3DMkpAnnotationSetGet(NULL, &sAnnotationSetData)); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stAnnotationReferenceGetMarkups(const A3DMkpAnnotationItem* /*pAnnotationItem*/, A3DPointerArray* /*psArray*/) +{ + A3DStatus iRet = A3D_SUCCESS; + return iRet; +} + +//###################################################################################################################### +static A3DStatus stAnnotationItemGetMarkups(const A3DMkpAnnotationItem* pAnnotationItem, A3DPointerArray* psArray) +{ + if(pAnnotationItem == NULL || psArray == NULL) + return A3D_ERROR; + + A3DStatus iRet = A3D_SUCCESS; + + A3DMkpAnnotationItemData sAnnotationItemData; + A3D_INITIALIZE_DATA(A3DMkpAnnotationItemData, sAnnotationItemData); + CHECK_RET(A3DMkpAnnotationItemGet(pAnnotationItem,&sAnnotationItemData)); + + stPointerArrayAddUnique(psArray, sAnnotationItemData.m_pMarkup); + + CHECK_RET(A3DMkpAnnotationItemGet(NULL, &sAnnotationItemData)); + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stAnnotationGetMarkups(const A3DMkpAnnotationEntity* pAnnotation, A3DPointerArray* psArray) +{ + A3DStatus iRet = A3D_SUCCESS; + A3DEEntityType eType=kA3DTypeUnknown; + + CHECK_RET(A3DEntityGetType(pAnnotation,&eType)); + + switch(eType) + { + case kA3DTypeMkpAnnotationSet: + CHECK_RET(stAnnotationSetGetMarkups(pAnnotation, psArray)); + break; + case kA3DTypeMkpAnnotationReference: + CHECK_RET(stAnnotationReferenceGetMarkups(pAnnotation, psArray)); + break; + case kA3DTypeMkpAnnotationItem: + CHECK_RET(stAnnotationItemGetMarkups(pAnnotation, psArray)); + break; + default: + break; + } + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stProductOccurrenceGetMarkups(const A3DAsmProductOccurrenceData* psPOccData, A3DPointerArray* psArray) +{ + if(psPOccData == NULL || psArray == NULL) + return A3D_ERROR; + + A3DStatus iRet = A3D_SUCCESS; + + if(psPOccData->m_uiAnnotationsSize == 0 && psPOccData->m_pPrototype != NULL) + { + A3DAsmProductOccurrenceData sPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sPrototypeData); + CHECK_RET(A3DAsmProductOccurrenceGet(psPOccData->m_pPrototype, &sPrototypeData)); + + CHECK_RET(stProductOccurrenceGetMarkups(&sPrototypeData, psArray)); + + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sPrototypeData)); + } + else + { + unsigned int ui, uiSize = psPOccData->m_uiAnnotationsSize; + for(ui = 0; ui < uiSize; ui++) + { + CHECK_RET(stAnnotationGetMarkups(psPOccData->m_ppAnnotations[ui], psArray)); + } + } + + return iRet; +} + +//###################################################################################################################### +static A3DStatus stDrawProductOccurrence(const A3DAsmProductOccurrence* pOccurrence, + const A3DMiscCascadedAttributes* pFatherAttr) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DMiscCascadedAttributes* pAttr; + A3DMiscCascadedAttributesData sAttrData; + CHECK_RET(stCreateAndPushCascadedAttributes(pOccurrence, pFatherAttr, &pAttr, &sAttrData)); + + if(sAttrData.m_bShow && !sAttrData.m_bRemoved && stIsShow(pOccurrence) == A3D_SUCCESS) + { + A3DAsmProductOccurrenceData sData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sData); + CHECK_RET(A3DAsmProductOccurrenceGet(pOccurrence, &sData)); + + if(sData.m_ucBehaviour != 1) + { + A3DRootBaseData sRootBaseData; + A3D_INITIALIZE_DATA(A3DRootBaseData, sRootBaseData); + CHECK_RET(A3DRootBaseGet(pOccurrence, &sRootBaseData)); + if(sRootBaseData.m_uiSize>0) + { + for(A3DUns32 ui=0;ui +#include "Connector.h" +#include + +class A3DVisitorContainer; + +/********************************************************************************************* + A3DMarkupTessDataConnectorCreator is in charge of creating new A3DMarkupTessConnector + each time a graphical state change when traversing markup tessellation structure + + At the end, A3DMarkupTessDataConnectorCreator ensure that + Tesselated data (point, polyline, triangles, Cone, text) that have the same Graphical data + (color, linestyle , pattern) and same local Matrix are group in the same MarkupTessConnector + +**********************************************************************************************/ +class A3DMarkupTessConnector; +class A3DMarkupTessDataConnectorCreator +{ +public: + A3DMarkupTessDataConnectorCreator(std::vector& a_rvMkpTessConnector); + ~A3DMarkupTessDataConnectorCreator(); + + A3DStatus pushMatrix(const double* a_pdLocalMatrix); + A3DStatus popMatrix(); + const double* GetCurrentWorldMatrix() { return &m_adCurrentWorldMatrix[0]; } + + A3DMarkupTessConnector& GetMarkupTessConnector(const double* pdMatrix); + A3DMarkupTessConnector& GetMarkupTessConnector(unsigned uiExtraDataValue, bool& bCameraDependant); + + bool HasStartToDrawSet() const { return m_bStartToDrawSet; } + +private: + // assignement operator can't work because of the ref member (std::vector&) + A3DMarkupTessDataConnectorCreator& operator= (const A3DMarkupTessDataConnectorCreator&) { assert(false); return *this; } + +private: + bool m_bStartToDrawSet; + + //Camera dependant Parameter: + bool m_bFaceViewActivated; + bool m_bFramedrawActivated; + bool m_bFixedSizeActivated; + + std::vector& m_rvMarkupTessData; + double m_adCurrentWorldMatrix[16]; + std::vector m_adPushedWorldMatrices; +}; + +/********************************************************************************************* + PMI Text entry +*********************************************************************************************/ +class A3DPMITextEntry +{ +public: + + A3DPMITextEntry() : m_dTextWidth(0.0), m_dTextHeight(0.0f), m_apcText(NULL) {} + + A3DPMITextEntry(A3DDouble a_dTextWidth, A3DDouble a_dTextHeight, + A3DFontKeyData const& a_rFontKeyData, A3DUTF8Char* a_apcText) : + m_dTextWidth(a_dTextWidth), m_dTextHeight(a_dTextHeight), m_oFontKeyData(a_rFontKeyData) + { + SetText(a_apcText); + } + + ~A3DPMITextEntry() + { + free(m_apcText); + } + + void SetTextWidth(A3DDouble a_dValue) { m_dTextWidth = a_dValue; } + void SetTextHeight(A3DDouble a_dValue) { m_dTextHeight = a_dValue; } + A3DDouble GetTextWidth() const { return m_dTextWidth; } + A3DDouble GetTextHeight() const { return m_dTextHeight; } + void SetText(A3DUTF8Char const * a_apcText) + { + auto iSize = strlen(a_apcText); + m_apcText = (A3DUTF8Char*)malloc(iSize + 1); + strcpy_s(m_apcText, iSize + 1, a_apcText); + } + A3DUTF8Char* GetText() const { return m_apcText; } + A3DFontKeyData const& GetFontKeyData() { return m_oFontKeyData; } + +private: + A3DDouble m_dTextWidth; + A3DDouble m_dTextHeight; + A3DFontKeyData m_oFontKeyData; + A3DUTF8Char* m_apcText; +}; + + /********************************************************************************************* + Markup Tessellation +**********************************************************************************************/ +class A3DMarkupTessConnector : public A3DConnector +{ + friend class A3DMarkupConnector; + friend class A3DMarkupTessDataConnectorCreator; + +public: + A3DMarkupTessConnector(); + A3DMarkupTessConnector(A3DMarkupTessConnector& a_PreviousTessConnector); + ~A3DMarkupTessConnector(); + + A3DStatus TraverseMarkupTessWithSameGraphicsAttributes(A3DVisitorContainer* pVisitor); + + + bool HasAlreadySomethingToDisplay() const { return (m_adPoints.size() != 0) || (m_adPolylineCoords.size() != 0) + || (m_aiPolylineIndices.size() != 0) + || (m_adTriangleList.size() != 0) || (m_adCylinder.size() != 0) + || (m_apTexts.size() != 0); } + + // Geometrical Data + std::vector const& GetPolyLineCoords() const { return m_adPolylineCoords; } + std::vector const& GetPolyLineIndices() const { return m_aiPolylineIndices; } + std::vector const& GetTextEntries() const { return m_apTexts; } + std::vector const& GetTriangles() const { return m_adTriangleList; } + std::vector const& GetCylinder() const { return m_adCylinder;} + std::vector const& GetPoints() const { return m_adPoints;} + + // Transfo + double const * GetWorldMatrix() const { return &m_adWorldMatrix[0]; } + + void GetFrameDrawWorldOffset(double a_adOfs[3]) const + { memcpy(a_adOfs, m_adViewDependantParameter, sizeof(m_adViewDependantParameter)); } + + A3DStatus ComputeCameraDependantMatrix( double const * pdProjMatrix, + int const * aiViewport, + long const * Rect, // TOP_LEFT(X,Y) BOTTOM_RIGHT(X,Y) + double* m_adPerViewMatrix); + + bool IsHidden() const { return (m_ucBehaviour&0x01) == 0 ? false : true; } + bool HasFrame() const { return (m_ucBehaviour&0x02) == 0 ? false : true; } + bool IsNotModifiable() const { return (m_ucBehaviour&0x04) == 0 ? false : true; } + bool IsZoomable() const { return (m_ucBehaviour&0x08) == 0 ? false : true; } + bool IsOnTop() const { return (m_ucBehaviour&0x10) == 0 ? false : true; } + bool IsFacingView() const { return m_bFaceView ; } + bool IsFrameDraw() const { return m_bFrameDraw ; } + bool HasColorSetup() const { return m_adRGB[0] >= 0.0; } + + // Graphic + void GetColor(double a_adRGB[3]) const + { + //memcpy(a_adRGB, m_adRGB, sizeof(m_adRGB)); + a_adRGB[0] = m_adRGB[0]; + a_adRGB[1] = m_adRGB[1]; + a_adRGB[2] = m_adRGB[2]; + + } + double GetLineWidth() const { return m_dLineWidth;} + int GetStyleIndexLineStyle() const { return m_iGraphStyleIndexLinsStyle;} + int GetPicturePattennIndex() const { return m_iGraphVPicturePatternIndex;} + +private: + static A3DStatus GetMarkupTessellation( const A3DTessBaseData& sTessBaseData, + const A3DTessMarkupData* pTessMarkupData, + const bool bIsText, + std::vector& asMarkupTessDataConnector, + double a_dParallelToScreenPMIScale); + +private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) // Suppress the warning C4251 because it leads to have that kind of warning : "warning + // C4251: 'A3DVisitorColorMaterials::m_apsCascadedAttribute' : class 'std::vector<_Ty>' needs to have dll-interface to + // be used by clients of class 'A3DVisitorColorMaterials" + // This is because of the "dllexport" on the visitor classes, as they use stl members and it seems that stl causes + // warning with dllexport with microsoft compiler +#endif // _MSC_VER + + // Parameter useful to compute camera dependant Matrix + bool m_bFaceView; + bool m_bFrameDraw; + bool m_bSymbol; + bool m_bFixedSize; + + bool m_bIsText; + double m_adViewDependantParameter[3]; + unsigned m_uiFixedSizePatternIndex; + + char m_ucBehaviour; + + double m_adModelMatrix[16]; + double m_adProjMatrix[16]; + + //Transfo + double m_adWorldMatrix[16]; + + //Graphic + double m_adRGB[3]; + double m_dLineWidth; + int m_iGraphStyleIndexLinsStyle; + int m_iGraphVPicturePatternIndex; + + //Geometrical data + std::vector m_adPoints; + std::vector m_aiPolylineIndices; + std::vector m_adPolylineCoords; + std::vector m_adTriangleList; + std::vector m_adCylinder; // n x (m_dRadiusBase, m_dRadiusTop, m_dHeight) + + //Text + std::vector m_apTexts; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif // _MSC_VER +}; + +#endif + + \ No newline at end of file diff --git a/exchange/exchangesource/Viewer/MarkupTraverse.h b/exchange/exchangesource/Viewer/MarkupTraverse.h new file mode 100644 index 0000000..7a93000 --- /dev/null +++ b/exchange/exchangesource/Viewer/MarkupTraverse.h @@ -0,0 +1,202 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_MARKUP_TRAVERSE +#define A3D_MARKUP_TRAVERSE + +#include +#include "Connector.h" + +/*######################################################################## + Markup Hierarchy +##########################################################################*/ + +class A3DVisitorContainer; +class A3DMkpAnnotationEntityConnector : public A3DConnector +{ +public: + + A3DMkpAnnotationEntityConnector(const A3DMkpAnnotationEntity *pAnnotEntity) + : A3DConnector(pAnnotEntity) {} + + ~A3DMkpAnnotationEntityConnector(){} + + A3DStatus TraverseAnnotationEntity(A3DVisitorContainer* psVisitor); + +}; + +class A3DMkpAnnotationSetConnector : public A3DConnector +{ +public: + + A3DMkpAnnotationSetConnector(const A3DMkpAnnotationSet *pAnnotSet) : A3DConnector(pAnnotSet) + { + A3D_INITIALIZE_DATA( A3DMkpAnnotationSetData, m_sAnnotSetData); + A3DMkpAnnotationSetGet(pAnnotSet,&m_sAnnotSetData); + } + + ~A3DMkpAnnotationSetConnector() + { + A3DMkpAnnotationSetGet(NULL, &m_sAnnotSetData); + } + + A3DStatus TraverseAnnotationSet(A3DVisitorContainer* pVisitor); + +public : + + A3DMkpAnnotationSetData m_sAnnotSetData; +}; + +class A3DMkpAnnotationReferenceConnector : public A3DConnector +{ +public: + A3DMkpAnnotationReferenceConnector(const A3DMkpAnnotationReference *pAnnotReference) : A3DConnector(pAnnotReference) + { + A3D_INITIALIZE_DATA( A3DMkpAnnotationReferenceData, m_sAnnotReferenceData); + A3DMkpAnnotationReferenceGet(pAnnotReference,&m_sAnnotReferenceData); + } + + ~A3DMkpAnnotationReferenceConnector() + { + A3DMkpAnnotationReferenceGet(NULL, &m_sAnnotReferenceData); + } + + A3DStatus TraverseAnnotationReference(A3DVisitorContainer* pVisitor); +public : + + A3DMkpAnnotationReferenceData m_sAnnotReferenceData; +}; + +class A3DMkpAnnotationItemConnector : public A3DConnector +{ + +public: + + A3DMkpAnnotationItemConnector(const A3DMkpAnnotationItem *pAnnotItem) : A3DConnector(pAnnotItem) + { + A3D_INITIALIZE_DATA( A3DMkpAnnotationItemData, m_sAnnotItemData); + A3DMkpAnnotationItemGet(pAnnotItem,&m_sAnnotItemData); + } + + ~A3DMkpAnnotationItemConnector() + { + A3DMkpAnnotationItemGet(NULL, &m_sAnnotItemData); + } + + A3DStatus TraverseAnnotationItem(A3DVisitorContainer* pVisitor); + +public: + + A3DMkpAnnotationItemData m_sAnnotItemData; +}; + +class A3DMarkupTessConnector; +class A3DMarkupConnector : public A3DConnector +{ + +public: + A3DStatus SplitMarkupTesselationByEntityWithSameGraphics(std::vector& asMarkupTessConnector, + double a_dParallelToScreenPMIScale); + +public: + + A3DMarkupConnector(const A3DMkpMarkup *pMarkup) : A3DConnector(pMarkup) + { + A3D_INITIALIZE_DATA( A3DMkpMarkupData, m_sMarkupData); + A3DMkpMarkupGet(pMarkup,&m_sMarkupData); + } + + ~A3DMarkupConnector() + { + A3DMkpMarkupGet(NULL, &m_sMarkupData); + } + + A3DStatus TraverseMarkupSemantic(A3DVisitorContainer* pVisitor); + + A3DStatus TraverseMarkupTess(A3DVisitorContainer* pVisitor,std::vector& asMarkupTessConnector); + +public: + + A3DMkpMarkupData m_sMarkupData; + +}; + + +class A3DMarkupDimensionConnector : public A3DConnector +{ + +public: + + A3DMarkupDimensionConnector(const A3DMarkupDimension *pMarkup) : A3DConnector(pMarkup) + { + A3D_INITIALIZE_DATA( A3DMarkupDimensionData, m_sDimensionData); + A3DMarkupDimensionGet(pMarkup,&m_sDimensionData); + } + + ~A3DMarkupDimensionConnector() + { + A3DMarkupDimensionGet(NULL, &m_sDimensionData); + } + + A3DStatus TraverseDimension(A3DVisitorContainer* pVisitor); + +public: + + A3DMarkupDimensionData m_sDimensionData; +}; + +class A3DMarkupDatumConnector : public A3DConnector +{ + +public: + + A3DMarkupDatumConnector(const A3DMarkupDatum *pMarkup) : A3DConnector(pMarkup) + { + A3D_INITIALIZE_DATA( A3DMarkupDatumData, m_sDatumData); + A3DMarkupDatumGet(pMarkup,&m_sDatumData); + } + + ~A3DMarkupDatumConnector() + { + A3DMarkupDatumGet(NULL, &m_sDatumData); + } + + A3DStatus TraverseDatum(A3DVisitorContainer* pVisitor); + +public: + + A3DMarkupDatumData m_sDatumData; +}; + +class A3DMarkupGDTConnector : public A3DConnector +{ + +public: + + A3DMarkupGDTConnector(const A3DMarkupGDT *pMarkup) : A3DConnector(pMarkup) + { + A3D_INITIALIZE_DATA( A3DMarkupGDTData, m_sGDTData); + A3DMarkupGDTGet(pMarkup,&m_sGDTData); + } + + ~A3DMarkupGDTConnector() + { + A3DMarkupGDTGet(NULL, &m_sGDTData); + } + + A3DStatus TraverseGDT(A3DVisitorContainer* pVisitor); + +public: + + A3DMarkupGDTData m_sGDTData; +}; + +#endif //A3D_MARKUP_TRAVERSE \ No newline at end of file diff --git a/exchange/exchangesource/Viewer/Matrix.h b/exchange/exchangesource/Viewer/Matrix.h new file mode 100644 index 0000000..cf5e002 --- /dev/null +++ b/exchange/exchangesource/Viewer/Matrix.h @@ -0,0 +1,738 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3DMATRIX_H +#define A3DMATRIX_H + +#include +#include +#include +#include +#include +#include + +#define A3D_PI 3.1415926535897932384626433832795028841971693993751 +#define A3D_HALF_PI 1.5707963267948966192313216916397514420985846996875 + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +static void MultMatrixVecd(const double matrix[16], + const double in[4], + double out[4]) +{ + int i; + + for (i = 0; i < 4; i++) { + out[i] = + in[0] * matrix[0 * 4 + i] + + in[1] * matrix[1 * 4 + i] + + in[2] * matrix[2 * 4 + i] + + in[3] * matrix[3 * 4 + i]; + } +} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +/* +** Invert 4x4 matrix. +** Contributed by David Moore (See Mesa bug #6748) +*/ +static bool InvertMatrixd(const double m[16], double invOut[16]) +{ + double inv[16], det; + int i; + + inv[0] = m[5] * m[10] * m[15] - m[5] * m[11] * m[14] - m[9] * m[6] * m[15] + + m[9] * m[7] * m[14] + m[13] * m[6] * m[11] - m[13] * m[7] * m[10]; + inv[4] = -m[4] * m[10] * m[15] + m[4] * m[11] * m[14] + m[8] * m[6] * m[15] + - m[8] * m[7] * m[14] - m[12] * m[6] * m[11] + m[12] * m[7] * m[10]; + inv[8] = m[4] * m[9] * m[15] - m[4] * m[11] * m[13] - m[8] * m[5] * m[15] + + m[8] * m[7] * m[13] + m[12] * m[5] * m[11] - m[12] * m[7] * m[9]; + inv[12] = -m[4] * m[9] * m[14] + m[4] * m[10] * m[13] + m[8] * m[5] * m[14] + - m[8] * m[6] * m[13] - m[12] * m[5] * m[10] + m[12] * m[6] * m[9]; + inv[1] = -m[1] * m[10] * m[15] + m[1] * m[11] * m[14] + m[9] * m[2] * m[15] + - m[9] * m[3] * m[14] - m[13] * m[2] * m[11] + m[13] * m[3] * m[10]; + inv[5] = m[0] * m[10] * m[15] - m[0] * m[11] * m[14] - m[8] * m[2] * m[15] + + m[8] * m[3] * m[14] + m[12] * m[2] * m[11] - m[12] * m[3] * m[10]; + inv[9] = -m[0] * m[9] * m[15] + m[0] * m[11] * m[13] + m[8] * m[1] * m[15] + - m[8] * m[3] * m[13] - m[12] * m[1] * m[11] + m[12] * m[3] * m[9]; + inv[13] = m[0] * m[9] * m[14] - m[0] * m[10] * m[13] - m[8] * m[1] * m[14] + + m[8] * m[2] * m[13] + m[12] * m[1] * m[10] - m[12] * m[2] * m[9]; + inv[2] = m[1] * m[6] * m[15] - m[1] * m[7] * m[14] - m[5] * m[2] * m[15] + + m[5] * m[3] * m[14] + m[13] * m[2] * m[7] - m[13] * m[3] * m[6]; + inv[6] = -m[0] * m[6] * m[15] + m[0] * m[7] * m[14] + m[4] * m[2] * m[15] + - m[4] * m[3] * m[14] - m[12] * m[2] * m[7] + m[12] * m[3] * m[6]; + inv[10] = m[0] * m[5] * m[15] - m[0] * m[7] * m[13] - m[4] * m[1] * m[15] + + m[4] * m[3] * m[13] + m[12] * m[1] * m[7] - m[12] * m[3] * m[5]; + inv[14] = -m[0] * m[5] * m[14] + m[0] * m[6] * m[13] + m[4] * m[1] * m[14] + - m[4] * m[2] * m[13] - m[12] * m[1] * m[6] + m[12] * m[2] * m[5]; + inv[3] = -m[1] * m[6] * m[11] + m[1] * m[7] * m[10] + m[5] * m[2] * m[11] + - m[5] * m[3] * m[10] - m[9] * m[2] * m[7] + m[9] * m[3] * m[6]; + inv[7] = m[0] * m[6] * m[11] - m[0] * m[7] * m[10] - m[4] * m[2] * m[11] + + m[4] * m[3] * m[10] + m[8] * m[2] * m[7] - m[8] * m[3] * m[6]; + inv[11] = -m[0] * m[5] * m[11] + m[0] * m[7] * m[9] + m[4] * m[1] * m[11] + - m[4] * m[3] * m[9] - m[8] * m[1] * m[7] + m[8] * m[3] * m[5]; + inv[15] = m[0] * m[5] * m[10] - m[0] * m[6] * m[9] - m[4] * m[1] * m[10] + + m[4] * m[2] * m[9] + m[8] * m[1] * m[6] - m[8] * m[2] * m[5]; + + det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12]; + if (det == 0) + return false; + + det = 1.0 / det; + + for (i = 0; i < 16; i++) + invOut[i] = inv[i] * det; + + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +static void MultMatricesd(const double a[16], const double b[16], + double r[16]) +{ + int i, j; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + r[i * 4 + j] = + a[i * 4 + 0] * b[0 * 4 + j] + + a[i * 4 + 1] * b[1 * 4 + j] + + a[i * 4 + 2] * b[2 * 4 + j] + + a[i * 4 + 3] * b[3 * 4 + j]; + } + } +} + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +static A3DStatus UnProject(double winx, + double winy, + double winz, + const double modelMatrix[16], + const double projMatrix[16], + const int viewport[4], + double *objx, double *objy, double *objz) +{ + double finalMatrix[16]; + double in[4]; + double out[4]; + + MultMatricesd(modelMatrix, projMatrix, finalMatrix); + if (!InvertMatrixd(finalMatrix, finalMatrix)) + return A3D_ERROR; + + in[0] = winx; + in[1] = winy; + in[2] = winz; + in[3] = 1.0; + + /* Map x and y from window coordinates */ + in[0] = (in[0] - viewport[0]) / viewport[2]; + in[1] = (in[1] - viewport[1]) / viewport[3]; + + /* Map to range -1 to 1 */ + in[0] = in[0] * 2 - 1; + in[1] = in[1] * 2 - 1; + in[2] = in[2] * 2 - 1; + + MultMatrixVecd(finalMatrix, in, out); + if (out[3] == 0.0) + return A3D_ERROR; + out[0] /= out[3]; + out[1] /= out[3]; + out[2] /= out[3]; + *objx = out[0]; + *objy = out[1]; + *objz = out[2]; + return A3D_SUCCESS; +} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +static A3DStatus Project(double objx, + double objy, + double objz, + const double modelMatrix[16], + const double projMatrix[16], + const int viewport[4], + double *winx, + double *winy, + double *winz) +{ + double in[4]; + double out[4]; + + in[0] = objx; + in[1] = objy; + in[2] = objz; + in[3] = 1.0; + MultMatrixVecd(modelMatrix, in, out); + MultMatrixVecd(projMatrix, out, in); + if (in[3] == 0.0) return A3D_ERROR; + in[0] /= in[3]; + in[1] /= in[3]; + in[2] /= in[3]; + /* Map x, y and z to range 0-1 */ + in[0] = in[0] * 0.5 + 0.5; + in[1] = in[1] * 0.5 + 0.5; + in[2] = in[2] * 0.5 + 0.5; + + /* Map x,y to viewport */ + in[0] = in[0] * viewport[2] + viewport[0]; + in[1] = in[1] * viewport[3] + viewport[1]; + + *winx = in[0]; + *winy = in[1]; + *winz = in[2]; + + return A3D_SUCCESS; +} + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +static A3DStatus MultiplyMatrix(const double* padFather, const double* pdThisMatrix, double* pdResult) +{ + A3DStatus iRet = A3D_SUCCESS; + pdResult[0] = padFather[0] * pdThisMatrix[0] + padFather[4] * pdThisMatrix[1] + padFather[8] * pdThisMatrix[2] + padFather[12] * pdThisMatrix[3]; + pdResult[1] = padFather[1] * pdThisMatrix[0] + padFather[5] * pdThisMatrix[1] + padFather[9] * pdThisMatrix[2] + padFather[13] * pdThisMatrix[3]; + pdResult[2] = padFather[2] * pdThisMatrix[0] + padFather[6] * pdThisMatrix[1] + padFather[10] * pdThisMatrix[2] + padFather[14] * pdThisMatrix[3]; + pdResult[3] = padFather[3] * pdThisMatrix[0] + padFather[7] * pdThisMatrix[1] + padFather[11] * pdThisMatrix[2] + padFather[15] * pdThisMatrix[3]; + pdResult[4] = padFather[0] * pdThisMatrix[4] + padFather[4] * pdThisMatrix[5] + padFather[8] * pdThisMatrix[6] + padFather[12] * pdThisMatrix[7]; + pdResult[5] = padFather[1] * pdThisMatrix[4] + padFather[5] * pdThisMatrix[5] + padFather[9] * pdThisMatrix[6] + padFather[13] * pdThisMatrix[7]; + pdResult[6] = padFather[2] * pdThisMatrix[4] + padFather[6] * pdThisMatrix[5] + padFather[10] * pdThisMatrix[6] + padFather[14] * pdThisMatrix[7]; + pdResult[7] = padFather[3] * pdThisMatrix[4] + padFather[7] * pdThisMatrix[5] + padFather[11] * pdThisMatrix[6] + padFather[15] * pdThisMatrix[7]; + pdResult[8] = padFather[0] * pdThisMatrix[8] + padFather[4] * pdThisMatrix[9] + padFather[8] * pdThisMatrix[10] + padFather[12] * pdThisMatrix[11]; + pdResult[9] = padFather[1] * pdThisMatrix[8] + padFather[5] * pdThisMatrix[9] + padFather[9] * pdThisMatrix[10] + padFather[13] * pdThisMatrix[11]; + pdResult[10] = padFather[2] * pdThisMatrix[8] + padFather[6] * pdThisMatrix[9] + padFather[10] * pdThisMatrix[10] + padFather[14] * pdThisMatrix[11]; + pdResult[11] = padFather[3] * pdThisMatrix[8] + padFather[7] * pdThisMatrix[9] + padFather[11] * pdThisMatrix[10] + padFather[15] * pdThisMatrix[11]; + pdResult[12] = padFather[0] * pdThisMatrix[12] + padFather[4] * pdThisMatrix[13] + padFather[8] * pdThisMatrix[14] + padFather[12] * pdThisMatrix[15]; + pdResult[13] = padFather[1] * pdThisMatrix[12] + padFather[5] * pdThisMatrix[13] + padFather[9] * pdThisMatrix[14] + padFather[13] * pdThisMatrix[15]; + pdResult[14] = padFather[2] * pdThisMatrix[12] + padFather[6] * pdThisMatrix[13] + padFather[10] * pdThisMatrix[14] + padFather[14] * pdThisMatrix[15]; + pdResult[15] = padFather[3] * pdThisMatrix[12] + padFather[7] * pdThisMatrix[13] + padFather[11] * pdThisMatrix[14] + padFather[15] * pdThisMatrix[15]; + return iRet; +} + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +static void MatrixVectMultiply(const double* pdMatrix, + const double* pdVect, + double* pdresult) +{ + unsigned int uI; + + for (uI = 0; uI < 4; uI++) + { + pdresult[uI] = + pdVect[0] * pdMatrix[uI] + + pdVect[1] * pdMatrix[4 + uI] + + pdVect[2] * pdMatrix[8 + uI] + + pdVect[3] * pdMatrix[12 + uI]; + } +} + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +static A3DStatus Calculate(double* pdX, double* pdY, double* pdZ, double* pdMat) +{ + double dLenght = sqrt(pdX[0] * pdX[0] + pdX[1] * pdX[1] + pdX[2] * pdX[2]); + if (dLenght < 1e-12) + return A3D_ERROR; + pdX[0] /= dLenght; pdX[1] /= dLenght; pdX[2] /= dLenght; + + dLenght = sqrt(pdY[0] * pdY[0] + pdY[1] * pdY[1] + pdY[2] * pdY[2]); + if (dLenght < 1e-12) + return A3D_ERROR; + pdY[0] /= dLenght; pdY[1] /= dLenght; pdY[2] /= dLenght; + + dLenght = sqrt(pdZ[0] * pdZ[0] + pdZ[1] * pdZ[1] + pdZ[2] * pdZ[2]); + if (dLenght < 1e-12) + return A3D_ERROR; + pdZ[0] /= dLenght; pdZ[1] /= dLenght; pdZ[2] /= dLenght; + + pdMat[0] = pdX[0]; + pdMat[1] = pdX[1]; + pdMat[2] = pdX[2]; + pdMat[4] = pdY[0]; + pdMat[5] = pdY[1]; + pdMat[6] = pdY[2]; + pdMat[8] = pdZ[0]; + pdMat[9] = pdZ[1]; + pdMat[10] = pdZ[2]; + + pdMat[3] = pdMat[7] = pdMat[11] = pdMat[12] = pdMat[13] = pdMat[14] = pdMat[15] = 0; + + return A3D_SUCCESS; +} + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +static double det2x2(double a, double b, double c, double d) +{ + double det; + det = a * d - b * c; + return det; +} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +static double det3x3(double a1, double a2, double a3, + double b1, double b2, double b3, + double c1, double c2, double c3) +{ + double det; + det = a1 * det2x2(b2, b3, c2, c3) + - b1 * det2x2(a2, a3, c2, c3) + + c1 * det2x2(a2, a3, b2, b3); + return det; +} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +static void adjoint(double* pdMatrix) +{ + double a1, a2, a3, a4, b1, b2, b3, b4; + double c1, c2, c3, c4, d1, d2, d3, d4; + + + a1 = pdMatrix[0]; b1 = pdMatrix[1]; + c1 = pdMatrix[2]; d1 = pdMatrix[3]; + a2 = pdMatrix[4]; b2 = pdMatrix[5]; + c2 = pdMatrix[6]; d2 = pdMatrix[7]; + a3 = pdMatrix[8]; b3 = pdMatrix[9]; + c3 = pdMatrix[10]; d3 = pdMatrix[11]; + a4 = pdMatrix[12]; b4 = pdMatrix[13]; + c4 = pdMatrix[14]; d4 = pdMatrix[15]; + + pdMatrix[0] = det3x3(b2, b3, b4, c2, c3, c4, d2, d3, d4); + pdMatrix[4] = -det3x3(a2, a3, a4, c2, c3, c4, d2, d3, d4); + pdMatrix[8] = det3x3(a2, a3, a4, b2, b3, b4, d2, d3, d4); + pdMatrix[12] = -det3x3(a2, a3, a4, b2, b3, b4, c2, c3, c4); + + pdMatrix[1] = -det3x3(b1, b3, b4, c1, c3, c4, d1, d3, d4); + pdMatrix[5] = det3x3(a1, a3, a4, c1, c3, c4, d1, d3, d4); + pdMatrix[9] = -det3x3(a1, a3, a4, b1, b3, b4, d1, d3, d4); + pdMatrix[13] = det3x3(a1, a3, a4, b1, b3, b4, c1, c3, c4); + + pdMatrix[2] = det3x3(b1, b2, b4, c1, c2, c4, d1, d2, d4); + pdMatrix[6] = -det3x3(a1, a2, a4, c1, c2, c4, d1, d2, d4); + pdMatrix[10] = det3x3(a1, a2, a4, b1, b2, b4, d1, d2, d4); + pdMatrix[14] = -det3x3(a1, a2, a4, b1, b2, b4, c1, c2, c4); + + pdMatrix[3] = -det3x3(b1, b2, b3, c1, c2, c3, d1, d2, d3); + pdMatrix[7] = det3x3(a1, a2, a3, c1, c2, c3, d1, d2, d3); + pdMatrix[11] = -det3x3(a1, a2, a3, b1, b2, b3, d1, d2, d3); + pdMatrix[15] = det3x3(a1, a2, a3, b1, b2, b3, c1, c2, c3); +} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +static A3DStatus Invert4x4(const double* pdMat, double* pdMatInv) +{ + double det; + int i, j; + double scale = pdMat[15]; + + if (fabs(scale) < FLT_MIN) + { + /*"Matrice avec Scale == 0.: inversion impossible\n"*/ + return A3D_ERROR; + } + + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + pdMatInv[i * 4 + j] = pdMat[i * 4 + j]; + + adjoint(pdMatInv); + det = det3x3(pdMat[0], pdMat[4], pdMat[8], + pdMat[1], pdMat[5], pdMat[9], + pdMat[2], pdMat[6], pdMat[10]); + + if (fabs(det) < FLT_MIN) + { + /*"Matrice non reguliere: inversion impossible\n"*/ + return A3D_ERROR; + } + + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + pdMatInv[i * 4 + j] /= (scale*det); + + return A3D_SUCCESS; +} + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +static A3DStatus UnProject(const double * pPt, + const double* pdModelMatrix, + const double* pdProjMatrix, + const int* viewport, + double* pPtresult) +{ + double finalMatrix[16]; + double in[4]; + double out[4]; + + MultiplyMatrix(pdModelMatrix, pdProjMatrix, finalMatrix); + if (!Invert4x4(finalMatrix, finalMatrix)) + return A3D_ERROR; + + in[0] = pPt[0]; + in[1] = pPt[1]; + in[2] = pPt[2]; + in[3] = 1.0; + + /* Map x and y from window coordinates */ + in[0] = (in[0] - viewport[0]) / viewport[2]; + in[1] = (in[1] - viewport[1]) / viewport[3]; + + /* Map to range -1 to 1 */ + in[0] = in[0] * 2 - 1; + in[1] = in[1] * 2 - 1; + in[2] = in[2] * 2 - 1; + + MatrixVectMultiply(finalMatrix, in, out); + if (out[3] == 0.0) + return A3D_ERROR; + + out[0] /= out[3]; + out[1] /= out[3]; + out[2] /= out[3]; + + *(pPtresult) = out[0]; + *(pPtresult + 1) = out[1]; + *(pPtresult + 2) = out[2]; + + double objx, objy, objz; + UnProject(pPt[0], pPt[1], pPt[2], + pdModelMatrix, + pdProjMatrix, + viewport, + &objx, &objy, &objz); + + if (fabs(pPtresult[0] - objx) > 1e-12 + || fabs(pPtresult[1] - objx) > 1e-12 + || fabs(pPtresult[2] - objx) > 1e-12) + return A3D_ERROR; + return A3D_SUCCESS; +} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +static A3DStatus Identity(double* pdIdentity) +{ + memset(&pdIdentity[0], 0, 16 * sizeof(double)); + pdIdentity[0] = pdIdentity[5] = pdIdentity[10] = pdIdentity[15] = 1; + return A3D_SUCCESS; +} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +static A3DStatus Ortho(const double* pdCurrentMatrix, + double dLeft, + double dRight, + double dTop, + double dBottom, + double dNear, + double dFar, + double* pdOutput) +{ + double adOrthoMatrix[16]; + double tx = -(dRight + dLeft) / (dRight - dLeft); + double ty = -(dTop + dBottom) / (dTop - dBottom); + double tz = -(dFar + dNear) / (dFar - dNear); + + adOrthoMatrix[0] = 2 / (dRight - dLeft); + adOrthoMatrix[1] = 0; + adOrthoMatrix[2] = 0; + adOrthoMatrix[3] = tx; + + adOrthoMatrix[4] = 0; + adOrthoMatrix[5] = 2 / (dTop - dBottom); + adOrthoMatrix[6] = 0; + adOrthoMatrix[7] = ty; + + adOrthoMatrix[8] = 0; + adOrthoMatrix[9] = 0; + adOrthoMatrix[10] = (-2) / (dFar - dNear); + adOrthoMatrix[11] = tz; + + adOrthoMatrix[12] = 0; + adOrthoMatrix[13] = 0; + adOrthoMatrix[14] = 0; + adOrthoMatrix[15] = 1; + + MatrixVectMultiply(pdCurrentMatrix, adOrthoMatrix, pdOutput); + return A3D_SUCCESS; +} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +static A3DVector3dData CrossProduct(const A3DVector3dData* X, const A3DVector3dData* Y) +{ + A3DVector3dData Z; + Z.m_dX = X->m_dY*Y->m_dZ - X->m_dZ*Y->m_dY; + Z.m_dY = X->m_dZ*Y->m_dX - X->m_dX*Y->m_dZ; + Z.m_dZ = X->m_dX*Y->m_dY - X->m_dY*Y->m_dX; + return Z; +} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +class A3DMatrix4x4 +{ +public: + double m_adM[16]; + //column first + //m_adM[0] = m00 m_adM[4] = m01 m_adM[8] = m02 m_adM[12] = m03 + //m_adM[1] = m10 m_adM[5] = m11 m_adM[9] = m12 m_adM[13] = m13 + //m_adM[2] = m20 m_adM[6] = m21 m_adM[10] = m22 m_adM[14] = m23 + //m_adM[3] = m30 m_adM[7] = m31 m_adM[11] = m32 m_adM[15] = m33 + + + ////////////////////////////////////// + ////////////////////////////////////// + A3DMatrix4x4(double* pdMat) + { + memcpy(&m_adM[0], pdMat, sizeof(double) * 16); + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DMatrix4x4() + { + ResetToIdentity(); + } + + ////////////////////////////////////// + ////////////////////////////////////// + operator const double*() const + { + return m_adM; + } + + ////////////////////////////////////// + ////////////////////////////////////// + static A3DStatus CreateIdentity(A3DMatrix4x4*& psIdentity) + { + // by default A3DMatrix4x4() call a ResetToIdentity + psIdentity = new A3DMatrix4x4(); + return A3D_SUCCESS; + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DMatrix4x4 operator * (const A3DMatrix4x4& matrix) const + { + A3DMatrix4x4 result; + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + result.m_adM[i + 4 * j] = 0.; + for (int k = 0; k < 4; k++) + result.m_adM[i + 4 * j] += m_adM[i + 4 * k] * matrix.m_adM[k + 4 * j]; + } + } + return result; + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DVector3d operator * (const A3DVector3d& v) const + { + A3DVector3d Result; + Result.x = m_adM[0] * v.x + m_adM[4] * v.y + m_adM[8] * v.z + m_adM[12]; + Result.y = m_adM[1] * v.x + m_adM[5] * v.y + m_adM[9] * v.z + m_adM[13]; + Result.z = m_adM[2] * v.x + m_adM[6] * v.y + m_adM[10] * v.z + m_adM[14]; + return Result; + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DStatus Invert(A3DMatrix4x4& sResult) + { + return Invert4x4(m_adM, sResult.m_adM); + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DStatus GetTranslation(A3DVector3d& sTranslation) + { + sTranslation.x = m_adM[12]; + sTranslation.y = m_adM[13]; + sTranslation.z = m_adM[14]; + return A3D_SUCCESS; + } + + ////////////////////////////////////// + ////////////////////////////////////// + void ResetToIdentity() + { + memset(m_adM, 0, sizeof(double) * 16); + m_adM[0] = m_adM[5] = m_adM[10] = m_adM[15] = 1; + } + + ////////////////////////////////////// + ////////////////////////////////////// + bool IsIdentity() const + { + if ((m_adM[0] != 1.0) || (m_adM[1] != 0.0) || (m_adM[2] != 0.0) || (m_adM[3] != 0.0) + || (m_adM[4] != 0.0) || (m_adM[5] != 1.0) || (m_adM[6] != 0.0) || (m_adM[7] != 0.0) + || (m_adM[8] != 0.0) || (m_adM[9] != 0.0) || (m_adM[10] != 1.0) || (m_adM[11] != 0.0) + || (m_adM[12] != 0.0) || (m_adM[13] != 0.0) || (m_adM[14] != 0.0) || (m_adM[15] != 1.0)) + { + return false; + } + return true; + } + + ////////////////////////////////////// + ////////////////////////////////////// + void GetScales(double& rdSX, double& rdSY, double& rdSZ) const + { + rdSX = sqrt(m_adM[0] * m_adM[0] + m_adM[1] * m_adM[1] + m_adM[2] * m_adM[2]); + rdSY = sqrt(m_adM[4] * m_adM[4] + m_adM[5] * m_adM[5] + m_adM[6] * m_adM[6]); + rdSZ = sqrt(m_adM[8] * m_adM[8] + m_adM[9] * m_adM[9] + m_adM[10] * m_adM[10]); + } + + ////////////////////////////////////// + ////////////////////////////////////// + void GetTranslation(double& rdTX, double& rdTY, double& rdTZ) const + { + rdTX = m_adM[12]; + rdTY = m_adM[13]; + rdTZ = m_adM[14]; + } + + ////////////////////////////////////// + ////////////////////////////////////// + void GetXYZRadianAngles(double& rdXAngle, double& rdYAngle, double& rdZAngle) const + { + double dSx, dSy, dSz; + GetScales(dSx, dSy, dSz); + double rot[9]; + rot[0] = m_adM[0] / dSx; rot[3] = m_adM[4] / dSy; rot[6] = m_adM[8] / dSz; + rot[1] = m_adM[1] / dSx; rot[4] = m_adM[5] / dSy; rot[7] = m_adM[9] / dSz; + rot[2] = m_adM[2] / dSx; rot[5] = m_adM[6] / dSy; rot[8] = m_adM[10] / dSz; + + if (rot[1] > 0.998) + { + rdZAngle = atan2(rot[6], rot[8]); + rdYAngle = A3D_HALF_PI; + rdXAngle = 0.0; + } + else if (rot[1] < -.998) + { + rdZAngle = atan2(rot[6], rot[8]); + rdYAngle = -A3D_HALF_PI; + rdXAngle = 0.0; + } + else + { + rdZAngle = atan2(-rot[2], rot[0]); + rdYAngle = asin(rot[1]); + if (rot[7] == 0.0 && rot[4] == 0) + { + int sign = (rot[7] > 0) - (rot[7] < 0); + if (sign >= 0) + rdXAngle = A3D_HALF_PI; + else + rdXAngle = -A3D_HALF_PI; + } + else + rdXAngle = atan2(-rot[7], rot[4]); + } + + } + + ////////////////////////////////////// + ////////////////////////////////////// + void setRotations(double const& dXAngle, double const& dYAngle, double const& dZAngle) + { + double dCos, dSin; + dCos = cos(dXAngle); + dSin = sin(dXAngle); + + A3DMatrix4x4 AX; + AX.m_adM[5] = dCos; + AX.m_adM[6] = -dSin; + AX.m_adM[9] = dSin; + AX.m_adM[10] = dCos; + + dCos = cos(dYAngle); + dSin = sin(dYAngle); + + A3DMatrix4x4 AY; + AY.m_adM[0] = dCos; + AY.m_adM[2] = dSin; + AY.m_adM[8] = -dSin; + AY.m_adM[10] = dCos; + + dCos = cos(dZAngle); + dSin = sin(dZAngle); + + A3DMatrix4x4 AZ; + AZ.m_adM[0] = dCos; + AZ.m_adM[1] = -dSin; + AZ.m_adM[4] = dSin; + AZ.m_adM[5] = dCos; + + + *this = AX * (AY * AZ); + } + + ////////////////////////////////////// + ////////////////////////////////////// + A3DMatrix4x4& operator = (const A3DMatrix4x4& rFrom) + { + memcpy(m_adM, rFrom.m_adM, sizeof(double) * 16); + return *this; + } + + ////////////////////////////////////// + ////////////////////////////////////// + bool Compare(A3DMatrix4x4 const& rOther, double dTol = 0.0) const + { + if (dTol != 0.0) + { + for (int i = 0; i < 16; i++) + { + if (m_adM[i] != rOther.m_adM[i]) + return false; + } + } + else + { + for (int i = 0; i < 16; i++) + { + if (fabs(m_adM[i] - rOther.m_adM[i]) < dTol) + return false; + } + } + return true; + } + +}; + +//////////////////////////////////////// +//////////////////////////////////////// +static const A3DMatrix4x4 stIdentity; + +#endif diff --git a/exchange/exchangesource/Viewer/TessConnector.h b/exchange/exchangesource/Viewer/TessConnector.h new file mode 100644 index 0000000..a6416dd --- /dev/null +++ b/exchange/exchangesource/Viewer/TessConnector.h @@ -0,0 +1,145 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_TESS_CONNECTOR +#define A3D_TESS_CONNECTOR + + +#include +#include "Connector.h" + +class A3DVisitorContainer; +class A3DTessDataConnector : public A3DConnector +{ + A3DTess3DData m_sTessData; + A3DTessBaseData m_sBaseTessData; + +public : + + A3DTessDataConnector(const A3DTess3D* pTess3D); + ~A3DTessDataConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor); + + unsigned FacesSize() const + { + return m_sTessData.m_uiFaceTessSize; + } + + A3DStatus Points(double*& pPoint, unsigned int& uSize) const; + + A3DStatus Normals(double*& pNormal, unsigned int& uSize) const; + + A3DStatus UV(double*& pUV, unsigned int& uSize) const; + + A3DTessBaseData const* GetBaseTessData() const { return &m_sBaseTessData; } + A3DTess3DData const* GetTess3DData() const { return &m_sTessData; } + + A3DStatus IndicesAsTriangle( + std::vector& auTriangleWithPoint_Normals_Indices, //normal, point,normal, point,..., point + std::vector& auTriangleWithPoint_Normals_UV_Indices //normal, UV, point, normal, UV , point,, ..., normal, UV, point + ) const; + + A3DStatus IndicesPerFaceAsTriangle( + const unsigned& uFaceIndice, + std::vector& auTriangleWithPoint_Normals_Indices, + std::vector& auTriangleWithPoint_Normals_UV_Indices) const; + + A3DStatus Indices( + std::vector& auTrianglesOneNormal, //(normal, point, point,..., point) + std::vector& auFanOneNormal, + std::vector& auStripeOneNormal, + std::vector& auTrianglesWithNormals, //normal, point, ... , normal, point + std::vector& auFanWithNormals, + std::vector& auStripeWithNormal, + std::vector& auTrianglesOneNormalTexture, //normal,{texture...},point,{texture...},point,{texture...},point + std::vector& auFanOneNormalTextured, + std::vector& auStripeOneNormalTextured, + std::vector& auTrianglesWithNormalsTextured, //normal,{texture...},point,...,normal,{texture...},point + std::vector& auFanWithNormalsTextured, + std::vector& auStripeWithNormalsTextured) const; + + A3DStatus IndicesPerFace( + const unsigned& uFaceIndice, + std::vector& auTrianglesOneNormal, //(normal, point, point,..., point) + std::vector& auFanOneNormal, + std::vector& auStripeOneNormal, + std::vector& auTrianglesWithNormals, //normal, point, ... , normal, point + std::vector& auFanWithNormals, + std::vector& auStripeWithNormal, + std::vector& auTrianglesOneNormalTexture, //normal,{texture...},point,{texture...},point,{texture...},point + std::vector& auFanOneNormalTextured, + std::vector& auStripeOneNormalTextured, + std::vector& auTrianglesWithNormalsTextured,//normal,{texture...},point,...,normal,{texture...},point + std::vector& auFanWithNormalsTextured, + std::vector& auStripeWithNormalsTextured) const; + + A3DStatus GetTextureCount(const unsigned& uFaceIndice, unsigned& uCount) const; +}; + + +class A3DFaceTessDataConnector : public A3DConnector +{ + const A3DTessDataConnector* m_pTessConnector; + unsigned m_uCurrentFaceIndex; + +public : + + A3DFaceTessDataConnector(const A3DTessFaceData* pFaceTess3D, unsigned uCurrentFaceIndex, const A3DTessDataConnector* pTessConnector); + ~A3DFaceTessDataConnector(); + + const A3DTessDataConnector* GetTessDataConnector() const { return m_pTessConnector; } + unsigned GetFaceIndex() const { return m_uCurrentFaceIndex; } + unsigned GetFaceNumber() const { return m_pTessConnector != NULL ? m_pTessConnector->FacesSize() : 0; } + + + A3DStatus Traverse(A3DVisitorContainer* psVisitor); + + A3DStatus IndicesAsTriangle( + std::vector& auTriangleWithPoint_Normals_Indices, //normal, point,normal, point,..., point + std::vector& auTriangleWithPoint_Normals_UV_Indices //normal, point, UV, normal, point,UV, ..., normal,point, UV + ) const; + + A3DStatus Indices( + std::vector& auTrianglesOneNormal, //(normal, point, point,..., point) + std::vector& auFanOneNormal, + std::vector& auStripeOneNormal, + std::vector& auTrianglesWithNormals, //normal, point, ... , normal, point + std::vector& auFanWithNormals, + std::vector& auStripeWithNormal, + std::vector& auTrianglesOneNormalTexture, //normal,{texture...},point,{texture...},point,{texture...},point + std::vector& auFanOneNormalTextured, + std::vector& auStripeOneNormalTextured, + std::vector& auTrianglesWithNormalsTextured, //normal,{texture...},point,...,normal,{texture...},point + std::vector& auFanWithNormalsTextured, + std::vector& auStripeWithNormalsTextured) const; +}; + + +class A3DWireTessDataConnector : public A3DConnector +{ + + A3DTess3DWireData m_sWire3DTessData; + A3DTessBaseData m_sBaseTessData; + +public: + + A3DWireTessDataConnector(const A3DTess3DWire* psTessWire); + ~A3DWireTessDataConnector(); + + A3DStatus Traverse(A3DVisitorContainer* psVisitor); + + A3DStatus Points(double*& pPoint, unsigned int& uSize) const; + A3DStatus Indices(std::vector& auPolylineIndices) const; +}; + +#endif + diff --git a/exchange/exchangesource/Viewer/TransfoConnector.h b/exchange/exchangesource/Viewer/TransfoConnector.h new file mode 100644 index 0000000..0b2ceea --- /dev/null +++ b/exchange/exchangesource/Viewer/TransfoConnector.h @@ -0,0 +1,44 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_TRANSFO_CONNECTOR +#define A3D_TRANSFO_CONNECTOR + +#include +#include "Connector.h" +#include "Matrix.h" + +class A3DVisitor; + + +class A3DTransfoConnector : public A3DConnector +{ + friend class A3DVisitorTransfo; + A3DMatrix4x4 m_sWorldMatrix; + A3DMatrix4x4 m_sLocalMatrix; + + void SetGlobalMatrix(A3DMiscTransformation const * pMiscTransformation); + void SetGlobalMatrix(A3DMatrix4x4 const& rWorldMatrix); + void ComputeGlobalMatrix(A3DMatrix4x4 const& rFatherWorldMatrix); + + A3DTransfoConnector(const A3DMiscTransformation* pMiscTransformation); + +public : + + ~A3DTransfoConnector() {} + + A3DStatus GetLocalMatrix(A3DMatrix4x4& rsMatrix); + + A3DStatus GetGlobalTransfo(A3DMatrix4x4& rsMatrix); + +}; + +#endif \ No newline at end of file diff --git a/exchange/exchangesource/Viewer/TreeTraverse.h b/exchange/exchangesource/Viewer/TreeTraverse.h new file mode 100644 index 0000000..4c9b56b --- /dev/null +++ b/exchange/exchangesource/Viewer/TreeTraverse.h @@ -0,0 +1,263 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_TREE_CONNECTOR +#define A3D_TREE_CONNECTOR + +#include +#include "Connector.h" +#include "callback_opengl.h" + +//###################################################################################################################### + +class A3DVisitorContainer; +class A3DModelFileConnector : public A3DConnector +{ +public: + + A3DModelFileConnector(const A3DAsmModelFile* pModelFile) : A3DConnector(pModelFile) + { + A3D_INITIALIZE_DATA(A3DAsmModelFileData, m_sModelFileData); + A3DAsmModelFileGet(pModelFile, &m_sModelFileData); + } + + ~A3DModelFileConnector() { A3DAsmModelFileGet(NULL, &m_sModelFileData); } + + A3DStatus Traverse(A3DVisitorContainer* psVisitor, bool bVisitPrototype = false); + +public: + + A3DAsmModelFileData m_sModelFileData; +}; + +//###################################################################################################################### +class A3DProductOccurrenceConnector : public A3DConnector +{ + friend class A3DModelFileConnector; + const A3DAsmProductOccurrence* m_pFather; + bool m_bIsInstanciated; + bool m_bIsPrototype; + bool m_bIsExternal; + +private: + + A3DProductOccurrenceConnector(const A3DAsmProductOccurrence* pProductOccurrence) + : A3DConnector(pProductOccurrence) + { + m_pFather = NULL; + m_bIsInstanciated = false; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, m_sProductOccurrenceData); + A3DAsmProductOccurrenceGet(pProductOccurrence, &m_sProductOccurrenceData); + m_bIsPrototype = false; + m_bIsExternal = false; + } + + ~A3DProductOccurrenceConnector() { A3DAsmProductOccurrenceGet(NULL, &m_sProductOccurrenceData); } + + A3DStatus TraversePO(const A3DAsmProductOccurrence* pOccurrence, A3DVisitorContainer* psVisitor, bool bVisitPrototype = false); + + void SetProductOccurrenceFather(const A3DAsmProductOccurrence* pFather) { m_pFather = pFather; } + +public: + A3DStatus GetPart(A3DAsmPartDefinition*& pPart) const; + A3DStatus CollectSons(std::vector& apSons) const; + + A3DAsmProductOccurrenceData m_sProductOccurrenceData; + const A3DAsmProductOccurrence* GetProductOccurrenceFather() { return m_pFather; } + void SetIsInstanciated(bool bIsInstanciated) { m_bIsInstanciated = bIsInstanciated; } + bool IsInstanciated() { return m_bIsInstanciated; } + void SetPrototypeType(bool bIsPrototype) { m_bIsPrototype = bIsPrototype; } + bool IsProtoType() const { return m_bIsPrototype; } + void SetExternalType(bool bIsExternal) { m_bIsExternal = bIsExternal; } + bool IsExternal() const { return m_bIsExternal; } +}; + +//###################################################################################################################### +class A3DPartConnector : public A3DConnector +{ + friend class A3DProductOccurrenceConnector; + const A3DAsmProductOccurrence* m_pFather; + bool m_bIsInstanciated; + +private: + + A3DPartConnector(const A3DAsmPartDefinition *pPart) : A3DConnector(pPart) + { + m_pFather = NULL; + m_bIsInstanciated = false; + A3D_INITIALIZE_DATA(A3DAsmPartDefinitionData, m_sPartData); + A3DAsmPartDefinitionGet(pPart, &m_sPartData); + } + + ~A3DPartConnector() + { + A3DAsmPartDefinitionGet(NULL, &m_sPartData); + } + + void SetProductOccurenceFather(const A3DAsmProductOccurrence* pFather) { m_pFather = pFather; } + +public: + A3DStatus TraversePart(A3DVisitorContainer* psVisitor) const; + A3DAsmPartDefinitionData m_sPartData; + const A3DAsmProductOccurrence* GetProductOccurenceFather() { return m_pFather; } + void SetIsInstanciated(bool bIsInstanciated) { m_bIsInstanciated = bIsInstanciated; } + bool IsInstanciated() { return m_bIsInstanciated; } +}; + +//###################################################################################################################### +class A3DRiConnector : public A3DConnector +{ + friend class A3DPartConnector; + friend class A3DRiSetConnector; + bool m_bIsInstanciated; + +public: + + A3DRiConnector(const A3DRiRepresentationItem *pRi) : A3DConnector(pRi) + { + m_bIsInstanciated = false; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, m_sRiData); + A3DRiRepresentationItemGet(pRi, &m_sRiData); + } + + ~A3DRiConnector() + { + A3DRiRepresentationItemGet(NULL, &m_sRiData); + } + + A3DStatus TraverseRi(A3DVisitorContainer* psVisitor); + +public: + + A3DRiRepresentationItemData m_sRiData; + void SetIsInstanciated(bool bIsInstanciated) { m_bIsInstanciated = bIsInstanciated; } + bool IsInstanciated() { return m_bIsInstanciated; } +}; + +//###################################################################################################################### +class A3DRiBrepModelConnector : public A3DConnector +{ + friend class A3DRiConnector; +public: + + A3DRiBrepModelConnector(const A3DRiBrepModel *pRi) : m_pRiBrepModel(pRi), A3DConnector(pRi) + { + A3D_INITIALIZE_DATA(A3DRiBrepModelData, m_sRiBrepModelData); + A3DRiBrepModelGet(m_pRiBrepModel, &m_sRiBrepModelData); + } + + ~A3DRiBrepModelConnector() + { + A3DRiBrepModelGet(NULL, &m_sRiBrepModelData); + } + + A3DStatus TraverseRiBrepModel(A3DVisitorContainer* psVisitor) const; + +public: + A3DRiBrepModel const* m_pRiBrepModel; + A3DRiBrepModelData m_sRiBrepModelData; +}; + +//###################################################################################################################### +class A3DRiSetConnector : public A3DConnector +{ + friend class A3DRiConnector; +private: + + A3DRiSetConnector(const A3DRiSet *pRi) : A3DConnector(pRi) + { + A3D_INITIALIZE_DATA(A3DRiSetData, m_sRiSetData); + A3DRiSetGet(pRi, &m_sRiSetData); + } + + ~A3DRiSetConnector() + { + A3DRiSetGet(NULL, &m_sRiSetData); + } + + A3DStatus TraverseRiSet(A3DVisitorContainer* psVisitor); + +public: + + A3DRiSetData m_sRiSetData; +}; + +//###################################################################################################################### +class A3DPolyRiBrepModelConnector : public A3DConnector +{ + friend class A3DRiConnector; +private: + + A3DPolyRiBrepModelConnector(const A3DRiPolyBrepModel* pRi) : A3DConnector(pRi) + { + A3D_INITIALIZE_DATA(A3DRiPolyBrepModelData, m_sRiPolyBrepModelData); + A3DRiPolyBrepModelGet(pRi, &m_sRiPolyBrepModelData); + } + + ~A3DPolyRiBrepModelConnector() + { + A3DRiPolyBrepModelGet(NULL, &m_sRiPolyBrepModelData); + } + +public: + A3DStatus TraverseRiPolyBrepModel(A3DVisitorContainer* psVisitor) const; + A3DRiPolyBrepModelData m_sRiPolyBrepModelData; +}; + +//###################################################################################################################### +class A3DRiCurveConnector : public A3DConnector +{ + friend class A3DRiConnector; +private: + + A3DRiCurveConnector(const A3DRiCurve* pRi) : A3DConnector(pRi) + { + A3D_INITIALIZE_DATA(A3DRiCurveData, m_sRiCurveData); + A3DRiCurveGet(pRi, &m_sRiCurveData); + } + + ~A3DRiCurveConnector() + { + A3DRiCurveGet(NULL, &m_sRiCurveData); + } + + A3DStatus TraverseRiCurve(A3DVisitorContainer* psVisitor); + +public: + + A3DRiCurveData m_sRiCurveData; +}; + +//###################################################################################################################### +class A3DRiPolyWireConnector : public A3DConnector +{ + friend class A3DRiConnector; +private: + + A3DRiPolyWireConnector(const A3DRiPolyWire* pRi) : A3DConnector(pRi) + { + A3D_INITIALIZE_DATA(A3DRiPolyWireData, m_sRiPolyWireData); + A3DRiPolyWireGet(pRi, &m_sRiPolyWireData); + } + + ~A3DRiPolyWireConnector() + { + A3DRiPolyWireGet(NULL, &m_sRiPolyWireData); + } + + A3DStatus TraverseRiPolyWire(A3DVisitorContainer* psVisitor); + +public: + + A3DRiPolyWireData m_sRiPolyWireData; +}; + +#endif diff --git a/exchange/exchangesource/Viewer/ViewTraverse.h b/exchange/exchangesource/Viewer/ViewTraverse.h new file mode 100644 index 0000000..ccf14de --- /dev/null +++ b/exchange/exchangesource/Viewer/ViewTraverse.h @@ -0,0 +1,45 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_VIEW_TRAVERSE +#define A3D_VIEW_TRAVERSE + +#include +#include "Connector.h" + + +class A3DVisitorContainer; + +class A3DMkpViewConnector : public A3DConnector +{ +public: + A3DMkpViewConnector(const A3DMkpView *pView) : A3DConnector(pView) + { + A3D_INITIALIZE_DATA( A3DMkpViewData, m_sViewData); + m_pView = pView; + A3DMkpViewGet(pView,&m_sViewData); + } + + ~A3DMkpViewConnector() + { + A3DMkpViewGet(NULL, &m_sViewData); + } + + A3DStatus TraverseView(A3DVisitorContainer* pVisitor); + + A3DMkpViewData const& GetViewData() const { return m_sViewData; } + A3DMkpView const* GetView() const { return m_pView; } + +private: + A3DMkpViewData m_sViewData; + A3DMkpView const* m_pView; +}; +#endif // A3D_VIEW_TRAVERSE \ No newline at end of file diff --git a/exchange/exchangesource/Viewer/Viewer.cpp b/exchange/exchangesource/Viewer/Viewer.cpp new file mode 100644 index 0000000..2958c0a --- /dev/null +++ b/exchange/exchangesource/Viewer/Viewer.cpp @@ -0,0 +1,1414 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file Viewer.cpp + +This file demonstrates how to programmatically visualize a PRC file with a basic OpenGL program using HOOPS Exchange +and the connectors and visitors tools. +In the main function, we open the file. +Then we traverse once the model in order to retrieve the bounding box of the model. +Then we re-traverse the model to draw the different items. + +***********************************************************************************************************************/ + +//#define DIRECT_RENDERING + +#define INITIALIZE_A3D_API +#include + +#include "../common.hpp" + +#define TF_A3DLIBS + +#include +#include +#include +#include + +#include "callback_opengl.h" +#include "Matrix.h" +#include "trackball.h" +#include "TreeTraverse.h" +#include "VisitorContainer.h" +#include "VisitorTessellation.h" +#include "VisitorTransfo.h" +#include "VisitorTree.h" +#include "Viewer.h" +#include "VisitorCascadedAttribute.h" + +//##################################################################################################################### +A3DUns32 mNumberOfViews; +A3DUns32 mCurrentViewIndex = ~0U; +bool stbDrawView = false; + +//##################################################################################################################### +static A3DStatus DrawModel(const A3DAsmModelFile* pModelFile); + +//###################################################################################################################### +A3DStatus DrawGetBoundingBox(const A3DAsmModelFile* pModelFile, A3DBoundingBoxData* psBoundingBox, + A3DUns32 uiDrawFlags); + +//###################################################################################################################### +static A3DStatus Draw(const A3DAsmModelFile* pModelFile, A3DUns32 uiDrawFlags); + +//###################################################################################################################### +A3DAsmModelFile* ComputeSection(A3DAsmModelFile* pModelFile, A3DPlanarSectionData sSectionParametersData); + +//###################################################################################################################### +void ComputeHLR( + A3DAsmModelFile const * pModelFile, + A3DMkpView const *pActiveView, + A3DHLRViewPlaneData const &sHLRViewPlaneData, + GLuint &uiHLRDisplayList, + GLuint &uiHLRTanEdgeDisplayList, + GLuint &uiHLRHiddenDisplayList, + GLuint &uiHLRHiddenTanEdgeDisplayList, + GLuint &uiHLRSectionDisplayList); + +//###################################################################################################################### +static bool stbTrackBallAnimate = GL_FALSE; + +//###################################################################################################################### +static GLsizei stiXScreen = 0; +static GLsizei stiYScreen = 0; +static GLdouble stdXPan = 0.0; +static GLdouble stdYPan = 0.0; +static GLdouble stdZoom = 1.0; +static GLdouble stdXPan_Save = 0.0; +static GLdouble stdYPan_Save = 0.0; +static GLdouble stdZoom_Save = 1.0; +static GLint staiViewport[4]; + +//###################################################################################################################### +static bool stbLButtonDown = false; +static bool stbRButtonDown = false; + +//###################################################################################################################### +static GLuint stuiModelFileDisplayList = 0; +static GLuint stuiMarkupsDisplayList = 0; +static GLuint stuiTriedronDisplayList = 0; +static GLuint stuiHLRDisplayList = 0; +static GLuint stuiHLRTanEdgeDisplayList = 0; +static GLuint stuiHLRHiddenDisplayList = 0; +static GLuint stuiHLRHiddenTanEdgeDisplayList = 0; +static GLuint stuiHLRSectionDisplayList = 0; + + +//###################################################################################################################### +static GLfloat stafLightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }; +static GLfloat stafLightAmbient[] = { 0.1f, 0.1f, 0.1f, 1.0f }; +static GLfloat stafLightPosition[] = { 0.0f, 0.0f, 1.0f, 0.0f }; + +//###################################################################################################################### +static GLfloat stafMaterialDiffuse[] = { 0.6f, 0.6f, 0.6f, 1.0f }; +static GLfloat stafMaterialSpecular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; +static GLfloat stafMaterialShininess[] = { 100.0f }; + +//###################################################################################################################### +static GLfloat stafTextColor[] = { 1.0f, 1.0f, 0.0f, 1.0f }; +static GLfloat stafErrorTextColor[] = { 1.0f, 0.0f, 0.0f, 1.0f }; + +//###################################################################################################################### +static unsigned int stuiClearColor = 0xB2B2B2; + +//###################################################################################################################### +static GLint staiWinSize[2]; +static GLint staiWinPosition[2]; +static bool stbFullScreen = false; + +//###################################################################################################################### +static clock_t stiStart, stiEnd; +static float stfElapsed; +static unsigned int stiNbFrames = 0; +static float stfFps = 0.0f; + +//###################################################################################################################### +static A3DUTF8Char stpcWinTitle[_MAX_PATH]; + +//###################################################################################################################### +static bool stbDisplayHelp = false; +static bool stbDisplayInfos = false; +//static bool stbDisplayMarkups = true; +static bool stbDisplaySection = false; +static bool stbDisplayHLR = false; +static bool stbDisplayHLRHidden = true; +static bool stbDisplayHLRTanEdge = true; +static bool stbDisplayHLRSection = true; +static bool stbDoubleSideRendering = true; +static A3DVector3dData origin3d; +static A3DVector3dData direction3d; +static A3DVector3dData stHLROrigin; + + + +//###################################################################################################################### +#define TRIEDRON_SIZE 40.0 + +//###################################################################################################################### +#define A3DGL_MIN(a,b) (((a) < (b)) ? (a) : (b)) +#define A3DGL_MAX(a,b) (((a) > (b)) ? (a) : (b)) + +static int stTraverseSet(A3DRiSet* pSet, A3DRiSet ** ppRISectionElements); + +//###################################################################################################################### +class A3DPRCViewerGLInfo +{ +public: + A3DBoundingBoxData sBoundingBox; + double dBoundingBoxRadius; + A3DVector3dData sBoundingBoxCenter; + +public: + //################################################################################################################## + A3DPRCViewerGLInfo() { Init(); } + + //################################################################################################################## + void Init() + { + A3D_INITIALIZE_DATA(A3DBoundingBoxData, sBoundingBox); + A3D_INITIALIZE_DATA(A3DVector3dData, sBoundingBoxCenter); + dBoundingBoxRadius = 0.0; + } + + //################################################################################################################## + void operator=(const A3DPRCViewerGLInfo& sOther) + { + sBoundingBox.m_sMin.m_dX = sOther.sBoundingBox.m_sMin.m_dX; + sBoundingBox.m_sMin.m_dY = sOther.sBoundingBox.m_sMin.m_dY; + sBoundingBox.m_sMin.m_dZ = sOther.sBoundingBox.m_sMin.m_dZ; + sBoundingBox.m_sMax.m_dX = sOther.sBoundingBox.m_sMax.m_dX; + sBoundingBox.m_sMax.m_dY = sOther.sBoundingBox.m_sMax.m_dY; + sBoundingBox.m_sMax.m_dZ = sOther.sBoundingBox.m_sMax.m_dZ; + dBoundingBoxRadius = sOther.dBoundingBoxRadius; + sBoundingBoxCenter.m_dX = sOther.sBoundingBoxCenter.m_dX; + sBoundingBoxCenter.m_dY = sOther.sBoundingBoxCenter.m_dY; + sBoundingBoxCenter.m_dZ = sOther.sBoundingBoxCenter.m_dZ; + } + + //################################################################################################################## + void Calculate() + { + A3DVector3dData sMin; + A3DVector3dData sMax; + sMin.m_dX = sBoundingBox.m_sMin.m_dX; + sMin.m_dY = sBoundingBox.m_sMin.m_dY; + sMin.m_dZ = sBoundingBox.m_sMin.m_dZ; + sMax.m_dX = sBoundingBox.m_sMax.m_dX; + sMax.m_dY = sBoundingBox.m_sMax.m_dY; + sMax.m_dZ = sBoundingBox.m_sMax.m_dZ; + + A3DDouble dBX = sMax.m_dX - sMin.m_dX; + A3DDouble dBY = sMax.m_dY - sMin.m_dY; + A3DDouble dBZ = sMax.m_dZ - sMin.m_dZ; + dBoundingBoxRadius = (float) sqrt(dBX*dBX + dBY*dBY + dBZ*dBZ) / 2.0f; + sBoundingBoxCenter.m_dX = (sMin.m_dX + sMax.m_dX) / 2.0; + sBoundingBoxCenter.m_dY = (sMin.m_dY + sMax.m_dY) / 2.0; + sBoundingBoxCenter.m_dZ = (sMin.m_dZ + sMax.m_dZ) / 2.0; + } + + //################################################################################################################## + A3DPRCViewerGLInfo operator+(const A3DPRCViewerGLInfo& sOther) + { + A3DPRCViewerGLInfo sSum; + ExtentUnion(&sBoundingBox, &sOther.sBoundingBox, &sSum.sBoundingBox); + sSum.Calculate(); + return sSum; + } +private: + + //################################################################################################################## + void ExtentUnion(const A3DBoundingBoxData* e1, const A3DBoundingBoxData* e2, A3DBoundingBoxData* r) + { + r->m_sMin.m_dX = A3DGL_MIN(e1->m_sMin.m_dX, e2->m_sMin.m_dX); + r->m_sMax.m_dX = A3DGL_MAX(e1->m_sMax.m_dX, e2->m_sMax.m_dX); + r->m_sMin.m_dY = A3DGL_MIN(e1->m_sMin.m_dY, e2->m_sMin.m_dY); + r->m_sMax.m_dY = A3DGL_MAX(e1->m_sMax.m_dY, e2->m_sMax.m_dY); + r->m_sMin.m_dZ = A3DGL_MIN(e1->m_sMin.m_dZ, e2->m_sMin.m_dZ); + r->m_sMax.m_dZ = A3DGL_MAX(e1->m_sMax.m_dZ, e2->m_sMax.m_dZ); + } +}; + +//###################################################################################################################### +static A3DDrawCallbacksData stsDrawCallbacksData; +static A3DSDKHOOPSExchangeLoader* stpHOOPSExchangeLoader = nullptr; +static A3DAsmModelFile* pSectionnedModelFile = nullptr; + +//###################################################################################################################### +static A3DPRCViewerGLInfo stsInfo; +static A3DPRCViewerGLInfo stsInfo3D; +static A3DPRCViewerGLInfo stsInfoMarkups; + +//###################################################################################################################### +#define HEX_TO_RED(hexcolor) ((GLclampf) ((hexcolor & 0xFF0000) >> 16) / 255.0f) +#define HEX_TO_GREEN(hexcolor) ((GLclampf) ((hexcolor & 0x00FF00) >> 8) / 255.0f) +#define HEX_TO_BLUE(hexcolor) ((GLclampf) (hexcolor & 0x0000FF) / 255.0f) + +//###################################################################################################################### +static enum +{ + KE_NONE = 0, + KE_ZOOMING, + KE_PANNING +} eMotionType; + +//###################################################################################################################### +void Reshape(GLsizei w, GLsizei h) +{ + tbReshape(w, h); + + glViewport(0, 0, w, h); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); +// gluPerspective(FOVY, (float)w / (h == 0.0 ? 1.0: (float)h), stsInfo.dBoundingBoxRadius * 0.1, +// stsInfo.dBoundingBoxRadius * 100.0); +// glOrtho(-w/2., w/2., -h/2., h/2., stsInfo.dBoundingBoxRadius * 0.1,stsInfo.dBoundingBoxRadius * 100.0); + glOrtho( -stsInfo.dBoundingBoxRadius * (float)w / (h == 0.0 ? 1.0: (float)h), stsInfo.dBoundingBoxRadius * (float)w / (h == 0.0 ? 1.0: (float)h), + -stsInfo.dBoundingBoxRadius, stsInfo.dBoundingBoxRadius, + -stsInfo.dBoundingBoxRadius-100,stsInfo.dBoundingBoxRadius * 100.0); + + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glGetIntegerv(GL_VIEWPORT, staiViewport); + + if(!stbFullScreen) + { + staiWinSize[0] = w; + staiWinSize[1] = h; + } +} + +//###################################################################################################################### +void InitGL(void) +{ + glClearColor(HEX_TO_RED(stuiClearColor), HEX_TO_GREEN(stuiClearColor), HEX_TO_BLUE(stuiClearColor), 1.0f); + + glPointSize(5.0f); + + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LEQUAL); + glEnable(GL_NORMALIZE); + glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); + + glShadeModel(GL_SMOOTH); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + glLightfv(GL_LIGHT0, GL_DIFFUSE, stafLightDiffuse); + glLightfv(GL_LIGHT0, GL_AMBIENT, stafLightAmbient); + + //glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, stafMaterialDiffuse); + //glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, stafMaterialSpecular); + //glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, stafMaterialShininess); + + stuiTriedronDisplayList = glGenLists(1); + glNewList(stuiTriedronDisplayList, GL_COMPILE); + { + glPushAttrib(GL_LIGHTING_BIT | GL_LINE_BIT); + glDisable(GL_LIGHTING); + glLineWidth(2.0); + glBegin(GL_LINES); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(0.0f, 0.0f, 0.0f); + glVertex3f(TRIEDRON_SIZE, 0.0f, 0.0f); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(0.0f, 0.0f, 0.0f); + glVertex3f(0.0f, TRIEDRON_SIZE, 0.0f); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(0.0f, 0.0f, 0.0f); + glVertex3f(0.0f, 0.0f, TRIEDRON_SIZE); + glEnd(); + glPopAttrib(); + } + glEndList(); + + stdZoom = 1.0; + stdXPan = 0.0; + stdYPan = 0.0; + +#ifdef _DEBUG + stiStart = clock(); +#endif +} + +//###################################################################################################################### +void DrawTriedron(void) +{ + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + { + glLoadIdentity(); + glOrtho(0.0, staiViewport[2], 0.0, staiViewport[3], -100.0, 100.0); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + { + glLoadIdentity(); + glTranslated(TRIEDRON_SIZE*1.5, TRIEDRON_SIZE*1.5, 0.0); + tbMatrix(); + glCallList(stuiTriedronDisplayList); + } + glPopMatrix(); + } + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); +} + +//###################################################################################################################### +static float stfX = 1.0f, stfY = 97.0f, stfLineH = 2.0f; + +//###################################################################################################################### +static char stpcMsg[2048]; + +//###################################################################################################################### +void PrintString(const char* format, ...) +{ + va_list args; + va_start(args, format); + vsprintf(stpcMsg, format, args); + va_end(args); + + glRasterPos2f(stfX, stfY); + char* pcPos = &stpcMsg[0]; + while(*pcPos) + { + if(*pcPos == '\n') + { + stfY -= stfLineH; + glRasterPos2f(stfX, stfY); + } + else + glutBitmapCharacter(GLUT_BITMAP_8_BY_13, *pcPos); + pcPos++; + } +} + +//###################################################################################################################### +void DrawError(char const * acMessage, A3DStatus sStatus) +{ + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluOrtho2D(0.0, 100.0, 0.0, 100.0); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + + glColor3fv(stafErrorTextColor); + + stfX = 1.0f; + stfY = 85.0f; + if (acMessage) + PrintString("%s %d\n", acMessage, sStatus); + else + PrintString("ERROR %d\n", sStatus); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + +} + +//##################################################################################################################### +void DrawStrings(void) +{ + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluOrtho2D(0.0, 100.0, 0.0, 100.0); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + + glColor3fv(stafTextColor); + + if (stbDrawView) + { + stfX = 1.0f; + stfY = 80.0f; + PrintString("VIEWS\n"); + PrintString("Total of views: %d \n",mNumberOfViews); + PrintString(" View number: %d\n", mCurrentViewIndex); + + } + + if(stbDisplayInfos) + { + stfX = 1.0f; + stfY = 97.0f; + + stiNbFrames++; + stiEnd = clock(); + stfElapsed = (float)(stiEnd - stiStart) / CLOCKS_PER_SEC; + if(stfElapsed >= 1.0) + { + stfFps = stiNbFrames/stfElapsed; + stiStart = stiEnd; + stiNbFrames = 0; + } + + PrintString("%.2f fps\n", stfFps); + PrintString("Bounding box\n"); + A3DVector3dData& sMin = stsInfo.sBoundingBox.m_sMin; + A3DVector3dData& sMax = stsInfo.sBoundingBox.m_sMax; + PrintString(" Extent: [%.3f, %.3f, %.3f] -> [%.3f, %.3f, %.3f]\n", + sMin.m_dX, sMin.m_dY, sMin.m_dZ, sMax.m_dX, sMax.m_dY, sMax.m_dZ); + PrintString(" Radius: %.3f\n", stsInfo.dBoundingBoxRadius); + } + + if(stbDisplayHelp) + { + stfX = 1.0f; + stfY = 70.0f; + PrintString("HELP\n"); + PrintString(" MOUSE:\n"); + PrintString(" Left button: rotating\n"); + PrintString(" Right button: zooming\n"); + PrintString(" Right+Left button: panning\n"); + PrintString("\n"); + PrintString(" KEYBOARD:\n"); + PrintString(" F1: print this help\n"); + PrintString(" F2: open a file (in the console)\n"); + PrintString(" F3: toggle markup display\n"); + PrintString(" F4: toggle full screen\n"); + PrintString(" F5: change background color\n"); + PrintString(" F6: toggle render mode %s\n", DisplayTriangles() == 1 ? "[SHADING]" : + DisplayTriangles() == 2 ? "[WIREFRAME]" : + DisplayTriangles() == 3 ? "[SHADING&WIREFRAME]":"NONE"); + PrintString(" F7: toggle normals display %s\n", DisplayTriangleNormals() == 0 ? "[NONE]" : + DisplayTriangleNormals() == 1 ? "[TRIANGLE PLANE NORMALS (blue)]" : + DisplayTriangleNormals() == 2 ? "[NORMALS (green)]" : + DisplayTriangleNormals() == 3 ? "[TRIANGLE PLANE NORMALS (blue) & NORMALS (green)]" : "?"); + PrintString(" (Up and down keys to change normals display length) %lf\n", DisplayTriangleNormalLength()); + PrintString(" F8: toggle rotation animation\n"); + PrintString(" F9: toggle double-side rendering %s\n", stbDoubleSideRendering ? "[ON]" : "[OFF]"); + PrintString(" F10: compute a planar section. Use the page up and page down keys to change the origin coordinates of the section\n"); + PrintString(" F11: toggle information display\n"); + PrintString(" h: toggle computed HLR\n"); + PrintString(" s: in HLR mode, hide/show section\n"); + PrintString(" t: in HLR mode, hide/show tangent edge\n"); + PrintString(" v: in HLR mode, hide/show hidden element\n"); + PrintString(" Use the RIGHT and LEFT keys to toggle the views\n"); + } + + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} + +//###################################################################################################################### +void DrawHLR() +{ + glPushMatrix(); + { + glLoadIdentity(); + glTranslated(-stsInfo.dBoundingBoxRadius*stdXPan, -stsInfo.dBoundingBoxRadius*stdYPan, 0.); + glScalef(stdZoom, stdZoom, stdZoom); + if (stbDisplayHLRHidden) + glCallList(stuiHLRHiddenDisplayList); + if (stbDisplayHLRHidden && stbDisplayHLRTanEdge) + glCallList(stuiHLRHiddenTanEdgeDisplayList); + glCallList(stuiHLRDisplayList); + if (stbDisplayHLRTanEdge) + glCallList(stuiHLRTanEdgeDisplayList); + if (stbDisplayHLRSection) + glCallList(stuiHLRSectionDisplayList); + } + glPopMatrix(); +} + +//###################################################################################################################### +void Display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + if (stbDisplayHLR) + { + DrawHLR(); + } + else + { + glPushMatrix(); + { + glLoadIdentity(); + + glLightfv(GL_LIGHT0, GL_POSITION, stafLightPosition); + + glTranslated(0.0f, 0.0f, -3.0*stsInfo.dBoundingBoxRadius); + + glTranslated(-stsInfo.dBoundingBoxRadius*stdXPan, -stsInfo.dBoundingBoxRadius*stdYPan, + 0); + tbMatrix(); + glTranslated(-stsInfo.sBoundingBoxCenter.m_dX, -stsInfo.sBoundingBoxCenter.m_dY, + 0); + glScalef(stdZoom, stdZoom, stdZoom); // scale the matrix + +#ifdef DIRECT_RENDERING + Draw(stpHOOPSExchangeLoader->m_psModelFile, kA3DDraw3D); + if(GetstbDrawMarkups()) + Draw(stpHOOPSExchangeLoader->m_psModelFile, kA3DDrawMarkups); +#else + glCallList(stuiModelFileDisplayList); + if(GetstbDrawMarkups()) + glCallList(stuiMarkupsDisplayList); +#endif + } + glPopMatrix(); + + DrawTriedron(); + } + + if(stbDisplayInfos || stbDisplayHelp || stbDrawView) + DrawStrings(); + + glFlush(); + glFinish(); + glutSwapBuffers(); +} + +void GetOpenGLMatrix(A3DDouble adModelView[16], A3DDouble adProjectMatrix[16]) +{ + glPushMatrix(); + { + glLoadIdentity(); + + glLightfv(GL_LIGHT0, GL_POSITION, stafLightPosition); + + glTranslated(0.0f, 0.0f, -3.0*stsInfo.dBoundingBoxRadius); + + glTranslated(-stsInfo.dBoundingBoxRadius*stdXPan, -stsInfo.dBoundingBoxRadius*stdYPan, + 0.); + tbMatrix(); + glTranslated(-stsInfo.sBoundingBoxCenter.m_dX, -stsInfo.sBoundingBoxCenter.m_dY, + 0.); + glScalef(stdZoom, stdZoom, stdZoom); // scale the matrix + + glGetDoublev(GL_MODELVIEW_MATRIX, adModelView); + glGetDoublev(GL_PROJECTION_MATRIX , adProjectMatrix); + } + glPopMatrix(); +} + +//###################################################################################################################### +static bool stbTBRunning = false; + +//###################################################################################################################### +void MouseButton(int button, int state, GLsizei x, GLsizei y) +{ + //GLboolean bActiveShift = glutGetModifiers() & GLUT_ACTIVE_SHIFT; + //GLboolean bActiveCtrl = glutGetModifiers() & GLUT_ACTIVE_CTRL; + //GLboolean bDownState = (state == GLUT_DOWN); + + if(button == GLUT_LEFT_BUTTON) + { + if(state == GLUT_DOWN) + stbLButtonDown = true; + else if(state == GLUT_UP) + stbLButtonDown = false; + } + else if(button == GLUT_RIGHT_BUTTON) + { + if(state == GLUT_DOWN) + stbRButtonDown = true; + else if(state == GLUT_UP) + stbRButtonDown = false; + } + + if(!stbLButtonDown && !stbRButtonDown) + glutSetCursor(GLUT_CURSOR_LEFT_ARROW); + + eMotionType = KE_NONE; + + if(stbLButtonDown) + { + if(!stbRButtonDown) + { + tbMouse(button, state, x, y); + stbTBRunning = true; + } + else + { + if(stbTBRunning) + tbMouse(GLUT_LEFT_BUTTON, GLUT_UP, x, y); + eMotionType = KE_PANNING; + glutSetCursor(GLUT_CURSOR_SPRAY); + } + } + else + { + if(stbRButtonDown) + { + eMotionType = KE_ZOOMING; + glutSetCursor(GLUT_CURSOR_UP_DOWN); + } + else + { + tbMouse(button, state, x, y); + stbTBRunning = false; + } + } + + stiXScreen = x; + stiYScreen = y; + + glutPostRedisplay(); +} + +//###################################################################################################################### +//void MouseWheel(int /* number */, int direction, int /* x */, int /* y */) +//{ +// // TODO +// stdZoom += stsReadModelResult.dBoundingBoxRadius * 0.001 * direction; +// glutPostRedisplay(); +//} + +//###################################################################################################################### +void Motion(GLsizei x, GLsizei y) +{ + tbMotion(x, y); + + switch(eMotionType) + { + case KE_PANNING: + { + stdXPan -= (GLdouble)(x - stiXScreen)/(GLdouble)staiViewport[2] * 2.0; + stdYPan += (GLdouble)(y - stiYScreen)/(GLdouble)staiViewport[3] * 2.0; + break; + } + case KE_ZOOMING: + { + stdZoom -= (GLdouble)(y - stiYScreen)/(GLdouble)staiViewport[3] * 10.0; + if (stdZoom<0) + stdZoom = 0; + break; + } + default: + break; + } + stiXScreen = x; + stiYScreen = y; + + glutPostRedisplay(); +} + +//###################################################################################################################### +A3DStatus OpenFile(const A3DUTF8Char* pcCADFile); + +//###################################################################################################################### +A3DStatus CloseFile(); + +//###################################################################################################################### +static void stRebuildGenList() +{ + glDeleteLists(stuiModelFileDisplayList, 1); + stuiModelFileDisplayList = glGenLists(1); + glNewList(stuiModelFileDisplayList, GL_COMPILE); + + if(!stbDisplaySection) + Draw(stpHOOPSExchangeLoader->m_psModelFile, kA3DDraw3D); + + else + Draw(pSectionnedModelFile, kA3DDraw3D); + + glEndList(); + + Reshape(staiWinSize[0], staiWinSize[1]); + glutPostRedisplay(); +} + +static void stRebuildGenListHLR() +{ + // Get active View + A3DAsmModelFileData sData; + A3D_INITIALIZE_DATA(A3DAsmModelFileData, sData); + A3DAsmModelFileGet(stpHOOPSExchangeLoader->m_psModelFile, &sData); + A3DAsmProductOccurrenceData sPOData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sPOData); + A3DAsmProductOccurrenceGet(sData.m_ppPOccurrences[0], &sPOData); + + A3DMkpView const *pActiveView = nullptr; + if (sPOData.m_uiViewsSize > 0) + { + mNumberOfViews = sPOData.m_uiViewsSize; + if (mCurrentViewIndex != -1) + { + pActiveView = sPOData.m_ppViews[mCurrentViewIndex]; + } + } + else if (sPOData.m_pPart != nullptr) + { + A3DAsmPartDefinitionData sPartData; + A3D_INITIALIZE_DATA(A3DAsmPartDefinitionData, sPartData); + if (A3DAsmPartDefinitionGet(sPOData.m_pPart, &sPartData) == A3D_SUCCESS) + { + mNumberOfViews = sPartData.m_uiViewsSize; + if (mCurrentViewIndex != -1) + { + pActiveView = sPartData.m_ppViews[mCurrentViewIndex]; + } + A3DAsmPartDefinitionGet(nullptr, &sPartData); + } + } + + A3DDouble adModelView[16], adProjectMatrix[16]; + GetOpenGLMatrix( adModelView, adProjectMatrix); + + A3DMatrix4x4 sModelViewMat(adModelView), sCameraMat; + sModelViewMat.Invert(sCameraMat); + + A3DHLRViewPlaneData sHLRViewPlaneData; + A3D_INITIALIZE_DATA(A3DHLRViewPlaneData,sHLRViewPlaneData); + sHLRViewPlaneData.m_adOrigin[0] = stHLROrigin.m_dX = sCameraMat[12]; + sHLRViewPlaneData.m_adOrigin[1] = stHLROrigin.m_dY = sCameraMat[13]; + sHLRViewPlaneData.m_adOrigin[2] = stHLROrigin.m_dZ = sCameraMat[14]; + + double dLength = stsInfo.dBoundingBoxRadius / 2.; + sHLRViewPlaneData.m_adAxis1[0] = sCameraMat[0] * dLength; + sHLRViewPlaneData.m_adAxis1[1] = sCameraMat[1] * dLength; + sHLRViewPlaneData.m_adAxis1[2] = sCameraMat[2] * dLength; + + sHLRViewPlaneData.m_adAxis2[0] = sCameraMat[4] * dLength; + sHLRViewPlaneData.m_adAxis2[1] = sCameraMat[5] * dLength; + sHLRViewPlaneData.m_adAxis2[2] = sCameraMat[6] * dLength; + sHLRViewPlaneData.m_bUseClipBox = false; + + ComputeHLR(stpHOOPSExchangeLoader->m_psModelFile, pActiveView, sHLRViewPlaneData, + stuiHLRDisplayList, stuiHLRTanEdgeDisplayList, stuiHLRHiddenDisplayList, stuiHLRHiddenTanEdgeDisplayList, stuiHLRSectionDisplayList); + + stbDisplayHLR = true; + + Reshape(staiWinSize[0], staiWinSize[1]); + + A3DAsmModelFileGet(nullptr, &sData); + A3DAsmProductOccurrenceGet(nullptr, &sPOData); +} + +//###################################################################################################################### +void SpecialKey(int key, int /* x */, int /* y */) +{ + + switch(key) + { + case 27: + exit(0); + + case GLUT_KEY_F1: + stbDisplayHelp = !stbDisplayHelp; + glutPostRedisplay(); + break; + + case GLUT_KEY_F2: + { + A3DUTF8Char pcFilePath[_MAX_PATH]; + fprintf(stdout, "\nFile path: "); + scanf("%s", pcFilePath); + + CloseFile(); + if(OpenFile(pcFilePath) == A3D_SUCCESS) + { + mCurrentViewIndex=~0U; + stbDrawView = false; + Reshape(staiWinSize[0], staiWinSize[1]); + stdZoom = 1.; + + stdYPan = 0.0; + } + Display(); + } + break; + + case GLUT_KEY_F3: + + SetstbDrawMarkups(!GetstbDrawMarkups()); + + if(GetstbDrawMarkups()) + stsInfo = stsInfo3D + stsInfoMarkups; + else + stsInfo = stsInfo3D; + Reshape(staiWinSize[0], staiWinSize[1]); + glutPostRedisplay(); + break; + + case GLUT_KEY_F4: + stbFullScreen = !stbFullScreen; + if(stbFullScreen) + glutFullScreen(); + else + { + glutPositionWindow(staiWinPosition[0], staiWinPosition[1]); + glutReshapeWindow(staiWinSize[0], staiWinSize[1]); + } + break; + + case GLUT_KEY_F5: + { + char pcNewColor[_MAX_PATH]; + fprintf(stdout, "\nNew color (0xHHHHHH): "); + scanf("%s", pcNewColor); + sscanf(pcNewColor, "%x", &stuiClearColor); + glClearColor(HEX_TO_RED(stuiClearColor), HEX_TO_GREEN(stuiClearColor), HEX_TO_BLUE(stuiClearColor), 1.0f); + glutPostRedisplay(); + } + break; + + case GLUT_KEY_F6: + DisplayTriangles()++; + if(DisplayTriangles() > 3) + DisplayTriangles() = 1; + stRebuildGenList(); + break; + + case GLUT_KEY_F7: + DisplayTriangleNormals()++; + if(DisplayTriangleNormals() > 3) + DisplayTriangleNormals() = 0; + DisplayTriangleNormalLength() = stsInfo3D.dBoundingBoxRadius*2 / 100; + stRebuildGenList(); + break; + + case GLUT_KEY_F8: + tbMouse(GLUT_LEFT_BUTTON, GLUT_UP, 0, 0); + stbTBRunning = false; + stbTrackBallAnimate = !stbTrackBallAnimate; + tbAnimate(stbTrackBallAnimate); + break; + + case GLUT_KEY_F9: + stbDoubleSideRendering = !stbDoubleSideRendering; + if(stbDoubleSideRendering) + { + glDisable(GL_CULL_FACE); + glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); + } + else + { + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); + } + stRebuildGenList(); + break; + + case GLUT_KEY_F10: + { + stbDisplaySection = !stbDisplaySection; + fprintf(stdout, "DisplaySection = %s\n", (stbDisplaySection) ? "true" : "false"); + + if(stbDisplaySection) + { + A3D_INITIALIZE_DATA(A3DVector3dData, origin3d); + + origin3d.m_dX = stsInfo.sBoundingBoxCenter.m_dX; + origin3d.m_dY = stsInfo.sBoundingBoxCenter.m_dY; + origin3d.m_dZ = stsInfo.sBoundingBoxCenter.m_dZ; + + A3D_INITIALIZE_DATA(A3DVector3dData, direction3d); + + char Direction[20] = "Direction"; + int nb1 = 0; + int nb2 = 0; + int nb3 = 0; + + fprintf(stdout, "\nEnter the x direction of your section: \n"); + scanf("%s", Direction); + sscanf(Direction, "%d", &nb1); + + fprintf(stdout, "\nEnter the y direction of your section: \n"); + scanf("%s", Direction); + sscanf(Direction, "%d", &nb2); + + fprintf(stdout, "\nEnter the z direction of your section: \n"); + scanf("%s", Direction); + sscanf(Direction, "%d", &nb3); + + direction3d.m_dX = (A3DDouble) nb1; + direction3d.m_dY = (A3DDouble) nb2; + direction3d.m_dZ = (A3DDouble) nb3; + + A3DPlanarSectionData sSectionParametersData; + A3D_INITIALIZE_DATA(A3DPlanarSectionData, sSectionParametersData); + + sSectionParametersData.m_sOrigin = origin3d; + sSectionParametersData.m_sDirection = direction3d; + sSectionParametersData.m_bColor = true; + sSectionParametersData.m_bCreateFaces = true; + + pSectionnedModelFile = ComputeSection(stpHOOPSExchangeLoader->m_psModelFile, sSectionParametersData); + stRebuildGenList(); + } + else + stRebuildGenList(); + } + break; + + case GLUT_KEY_F11: + stbDisplayInfos = !stbDisplayInfos; + glutPostRedisplay(); + break; + + case GLUT_KEY_UP: + DisplayTriangleNormalLength() *= 2; + stRebuildGenList(); + break; + + case GLUT_KEY_DOWN: + DisplayTriangleNormalLength() /= 2; + stRebuildGenList(); + break; + + case GLUT_KEY_RIGHT: + { + if (mCurrentViewIndex==mNumberOfViews-1) + mCurrentViewIndex = ~0U; + else + mCurrentViewIndex++; + + stbDrawView = (mCurrentViewIndex != ~0U); + stRebuildGenList(); + glutPostRedisplay(); + } + break; + + case GLUT_KEY_INSERT: + { + stRebuildGenList(); + glutPostRedisplay(); + } + break; + + case GLUT_KEY_LEFT: + { + if (mCurrentViewIndex==~0U) + mCurrentViewIndex = mNumberOfViews-1; + else + mCurrentViewIndex--; + + stbDrawView = (mCurrentViewIndex != ~0U); + stRebuildGenList(); + glutPostRedisplay(); + } + break; + + case GLUT_KEY_PAGE_UP: + { + if(stbDisplaySection) + { + origin3d.m_dX = origin3d.m_dX+direction3d.m_dX*0.1; + origin3d.m_dY = origin3d.m_dY+direction3d.m_dY*0.1; + origin3d.m_dZ = origin3d.m_dZ+direction3d.m_dZ*0.1; + + A3DPlanarSectionData sSectionParametersData; + A3D_INITIALIZE_DATA(A3DPlanarSectionData, sSectionParametersData); + + sSectionParametersData.m_sOrigin = origin3d; + sSectionParametersData.m_sDirection = direction3d; + sSectionParametersData.m_bColor = true; + sSectionParametersData.m_bCreateFaces = true; + + pSectionnedModelFile = ComputeSection(stpHOOPSExchangeLoader->m_psModelFile, sSectionParametersData); + stRebuildGenList(); + } + } + break; + + case GLUT_KEY_PAGE_DOWN: + { + if(stbDisplaySection) + { + origin3d.m_dX = origin3d.m_dX-direction3d.m_dX*0.1; + origin3d.m_dY = origin3d.m_dY-direction3d.m_dY*0.1; + origin3d.m_dZ = origin3d.m_dZ-direction3d.m_dZ*0.1; + + A3DPlanarSectionData sSectionParametersData; + A3D_INITIALIZE_DATA(A3DPlanarSectionData, sSectionParametersData); + + sSectionParametersData.m_sOrigin = origin3d; + sSectionParametersData.m_sDirection = direction3d; + sSectionParametersData.m_bColor = true; + sSectionParametersData.m_bCreateFaces = true; + + pSectionnedModelFile = ComputeSection(stpHOOPSExchangeLoader->m_psModelFile, sSectionParametersData); + stRebuildGenList(); + } + } + break; + } +} + +//###################################################################################################################### +A3DStatus DrawGetBoundingBox(const A3DAsmModelFile* pModelFile, A3DBoundingBoxData* psBoundingBox, A3DUns32 uiDrawFlags) +{ + A3DStatus iRet = A3D_SUCCESS; + + if (pModelFile == nullptr) + return A3D_INVALID_ENTITY_NULL; + + if (psBoundingBox == nullptr) + return A3D_INVALID_DATA_STRUCT_NULL; + + stLoadIdentity(); + stExtentInit(psBoundingBox); + SetstbDraw3D((uiDrawFlags & kA3DDraw3D) != 0); + SetstbDrawMarkups((uiDrawFlags & kA3DDrawMarkups) != 0); + SetstpsBoundingBox(psBoundingBox); + SetstbUseCallbacks(false); + CHECK_RET(DrawModel(pModelFile)); + + return iRet; +} + +//###################################################################################################################### +void Key( unsigned char key, int /*x*/, int /*y*/) +{ + switch (key) + { + case 's': + stbDisplayHLRSection = !stbDisplayHLRSection; + glutPostRedisplay(); + break; + case 't': + stbDisplayHLRTanEdge = !stbDisplayHLRTanEdge; + glutPostRedisplay(); + break; + case 'v': + stbDisplayHLRHidden = !stbDisplayHLRHidden; + glutPostRedisplay(); + break; + case 'h': + { + if( !stbDisplayHLR) + { + stRebuildGenListHLR(); + stbDisplayHLR = true; + stdXPan_Save = stdXPan; stdXPan = 0.; + stdYPan_Save = stdYPan; stdYPan = 0.; + stdZoom_Save = stdZoom; + } + else + { + stbDisplayHLR = false; + stdXPan = stdXPan_Save; + stdYPan = stdYPan_Save; + stdZoom = stdZoom_Save; + } + } + glutPostRedisplay(); + break; + + case 27: + exit(0); + break; + + default: + break; + } +} + +//###################################################################################################################### +static A3DStatus DrawModel(const A3DAsmModelFile* pModelFile) +{ + A3DAsmModelFileData sData; + A3D_INITIALIZE_DATA(A3DAsmModelFileData, sData); + CHECK_RET(A3DAsmModelFileGet(pModelFile, &sData)); + + // Creation of the ModelFile Connector + A3DModelFileConnector sModelFileConnector(pModelFile); + A3DVisitorContainer sCadVisitorContainer(CONNECT_TRANSFO); + sCadVisitorContainer.SetTraverseInstance(true); + + A3DAsmProductOccurrenceData sPOData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sPOData); + CHECK_RET(A3DAsmProductOccurrenceGet(sData.m_ppPOccurrences[0], &sPOData)); + if (sPOData.m_uiViewsSize > 0) + { + mNumberOfViews = sPOData.m_uiViewsSize; + if (mCurrentViewIndex != -1 && mCurrentViewIndexImport(sImport); + if(iRet != A3D_SUCCESS && iRet != A3D_LOAD_MULTI_MODELS_CADFILE && iRet != A3D_LOAD_MISSING_COMPONENTS) + return iRet; + + // Traverse the model once to retrieve the bounding box + CHECK_RET(DrawGetBoundingBox(stpHOOPSExchangeLoader->m_psModelFile, &stsInfo3D.sBoundingBox, kA3DDraw3D)); + stsInfo3D.Calculate(); + +#ifndef DIRECT_RENDERING + stuiModelFileDisplayList = glGenLists(1); + glNewList(stuiModelFileDisplayList, GL_COMPILE); + { + if(!stbDisplaySection) + { + // Traverse the model a second time to draw the items + CHECK_RET(Draw(stpHOOPSExchangeLoader->m_psModelFile, kA3DDraw3D)); + } + else + { + // Draw the section + CHECK_RET(Draw(pSectionnedModelFile, kA3DDraw3D)); + } + } + glEndList(); +#endif + + Reshape(staiWinSize[0], staiWinSize[1]); + + // Traverse the model once to retrieve the bounding box with the markups + CHECK_RET(DrawGetBoundingBox(stpHOOPSExchangeLoader->m_psModelFile, &stsInfoMarkups.sBoundingBox, kA3DDrawMarkups)); + stsInfoMarkups.Calculate(); + +#ifndef DIRECT_RENDERING + stuiMarkupsDisplayList = glGenLists(1); + glNewList(stuiMarkupsDisplayList, GL_COMPILE_AND_EXECUTE); + { + if(!stbDisplaySection) + { + // Traverse the model a second time to draw the items (including the markups) + CHECK_RET(Draw(stpHOOPSExchangeLoader->m_psModelFile, kA3DDrawMarkups)); + } + } + glEndList(); +#endif + + Reshape(staiWinSize[0], staiWinSize[1]); + + fprintf(stdout, "Done.\n"); + + if(GetstbDrawMarkups()) + stsInfo = stsInfo3D + stsInfoMarkups; + else + stsInfo = stsInfo3D; + + sprintf(stpcWinTitle, "HOOPS Exchange Viewer - %s", pcCADFileName); + glutSetWindowTitle(stpcWinTitle); + + return A3D_SUCCESS; +} + +//###################################################################################################################### +A3DStatus CloseFile() +{ +#ifndef DIRECT_RENDERING + glDeleteLists(stuiModelFileDisplayList, 1); + glDeleteLists(stuiMarkupsDisplayList, 1); + glDeleteLists(stuiHLRDisplayList, 1); + glDeleteLists(stuiHLRTanEdgeDisplayList, 1); + glDeleteLists(stuiHLRHiddenDisplayList,1); + glDeleteLists(stuiHLRHiddenTanEdgeDisplayList,1); + glDeleteLists(stuiHLRSectionDisplayList, 1); + + //glDeleteLists(stuiTriedronDisplayList, 1); + stuiModelFileDisplayList = stuiMarkupsDisplayList = stuiHLRDisplayList = stuiHLRTanEdgeDisplayList = stuiHLRHiddenDisplayList = stuiHLRHiddenTanEdgeDisplayList = stuiHLRSectionDisplayList = 0; +#endif + return A3D_SUCCESS; +} + +//###################################################################################################################### +void terminate2() +{ + CloseFile(); + + delete stpHOOPSExchangeLoader; + stpHOOPSExchangeLoader = nullptr; + ListLeaks(); +} + +static MY_CHAR acSrcFileName[_MAX_PATH * 2]; +static MY_CHAR acLogFileName[_MAX_PATH * 2]; + +//###################################################################################################################### +// Main function +#ifdef _MSC_VER +int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv) +#else +int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) +#endif +{ + // + // ### COMMAND LINE ARGUMENTS + // + + if (iArgc > 4) + { + MY_PRINTF2("Usage:\n %s [input CAD file] [Clear color value] [output LOG file]\n", ppcArgv[0]); + MY_PRINTF(" Default output LOG file is [input CAD file]_Log.txt\n\n"); + return A3D_ERROR; + } + + if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]); + else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD); + if (iArgc > 2) MY_SSCANF(ppcArgv[2], "%x", &stuiClearColor); + else stuiClearColor = 0xB2B2B2; + if (iArgc > 3) MY_STRCPY(acLogFileName, ppcArgv[3]); + else MY_SPRINTF(acLogFileName, "%s_Log.txt", acSrcFileName); + GetLogFile(acLogFileName); // Initialize log file + + // + // ### INITIALIZE HOOPS EXCHANGE + // + + stpHOOPSExchangeLoader = new A3DSDKHOOPSExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); + if (stpHOOPSExchangeLoader->m_eSDKStatus != A3D_SUCCESS) + { + A3DStatus eSDKStatus = stpHOOPSExchangeLoader->m_eSDKStatus; + delete stpHOOPSExchangeLoader; + stpHOOPSExchangeLoader = nullptr; + return eSDKStatus; + } + + CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree)); + CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError)); + + // + // ### PROCESS SAMPLE CODE + // + + glutInit((int*)(&iArgc), (char**)ppcArgv); + GLsizei iScreenW = glutGet(GLUT_SCREEN_WIDTH); + GLsizei iScreenH = glutGet(GLUT_SCREEN_HEIGHT); + staiWinSize[0] = (GLsizei)((double)iScreenW * 0.7); + staiWinSize[1] = (GLsizei)((double)iScreenH * 0.7); + staiWinPosition[0] = (iScreenW - staiWinSize[0]) / 2; + staiWinPosition[1] = (iScreenH - staiWinSize[1]) / 2; + + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + glutInitWindowPosition(staiWinPosition[0], staiWinPosition[1]); + glutInitWindowSize(staiWinSize[0], staiWinSize[1]); + + glutCreateWindow("A3DPRCViewerGL"); + glViewport(0, 0, staiWinSize[0], staiWinSize[1]); + + tbInit(GLUT_LEFT_BUTTON); + tbAnimate(stbTrackBallAnimate); + + stsInfo.Init(); + stsInfo3D.Init(); + stsInfoMarkups.Init(); + + A3DUTF8Char sSrcFileNameUTF8[_MAX_PATH]; +#ifdef _MSC_VER + A3DMiscUTF16ToUTF8(acSrcFileName, sSrcFileNameUTF8); +#else + MY_STRCPY(sSrcFileNameUTF8, acSrcFileName); +#endif + CHECK_RET_TERM(OpenFile(sSrcFileNameUTF8)); + + InitGL(); + + glutReshapeFunc(Reshape); + glutDisplayFunc(Display); + glutKeyboardFunc(Key); + glutSpecialFunc(SpecialKey); + glutMouseFunc(MouseButton); + //glutMouseWheelFunc(MouseWheel); + glutMotionFunc(Motion); + glutIdleFunc(nullptr); + + fprintf(stdout, "\nF1 for help\n"); + + // glut call exit(0) when closing windows, so set atexit to properly close the DLL + atexit(terminate2); + + glutMainLoop(); + + // + // ### TERMINATE HOOPS EXCHANGE + // + + return 0; +} diff --git a/exchange/exchangesource/Viewer/Viewer.h b/exchange/exchangesource/Viewer/Viewer.h new file mode 100644 index 0000000..1f946b2 --- /dev/null +++ b/exchange/exchangesource/Viewer/Viewer.h @@ -0,0 +1,61 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file Viewer.h + +***********************************************************************************************************************/ + +#ifndef _A3DPRCViewerGL_H +#define _A3DPRCViewerGL_H + +#define _CRT_SECURE_NO_DEPRECATE 1 +#include +#include +#include + +#ifdef __APPLE__ +# include +#else +# include +#endif + +//###################################################################################################################### +#ifndef M_PI +# define M_PI 3.141592653589793238462643383279502884197169399375105820974944592308 +#endif + +//###################################################################################################################### +#ifdef _DEBUG +# define PRINT_XML_ERROR(err) printf("\n", err, __FILE__, __LINE__); +#else +# define PRINT_XML_ERROR(err) printf("\n", err); +#endif + +//###################################################################################################################### +#define CHECK_RET_TERM(function_call)\ +{\ + const A3DStatus iRet__ = function_call;\ + if(iRet__ != A3D_SUCCESS)\ + {\ + PRINT_XML_ERROR(iRet__)\ + terminate2();\ + return iRet__;\ + }\ +} + +//###################################################################################################################### +#define FOVY 40.0f +#define Stringize(L) #L +#define MakeString(M, L) M(L) +#define $Line MakeString(Stringize, __LINE__) +#define Todo __FILE__ "(" $Line ") : TODO: " + +#endif diff --git a/exchange/exchangesource/Viewer/Viewer.vcxproj b/exchange/exchangesource/Viewer/Viewer.vcxproj new file mode 100644 index 0000000..8941ba1 --- /dev/null +++ b/exchange/exchangesource/Viewer/Viewer.vcxproj @@ -0,0 +1,240 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {D8B6598C-913F-4507-AE93-518F7C76EBDA} + A3DPRCViewerGL + Win32Proj + 10.0 + + + + Application + v145 + false + true + + + Application + v145 + false + + + Application + v145 + false + true + + + Application + v145 + false + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + + Disabled + .\glut\include;.\;.\traverse\;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + Sync + EnableFastChecks + MultiThreadedDebugDLL + true + + Level4 + ProgramDatabase + 4505;%(DisableSpecificWarnings) + false + + + glut32.lib;legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + LinkVerboseLib + $(OutDir)$(ProjectName).exe + .\glut\lib;%(AdditionalLibraryDirectories) + true + Console + false + + MachineX86 + + + if $(SolutionName) equ exchange copy /y .\glut\dll\glut32.dll .\$(Platform)\$(Configuration)\ + + + + + X64 + + + Disabled + .\glut\include;.\;.\traverse\;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + Sync + EnableFastChecks + MultiThreadedDebugDLL + true + + Level4 + ProgramDatabase + 4505;%(DisableSpecificWarnings) + false + + + glut64.lib;legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + LinkVerboseLib + $(OutDir)$(ProjectName).exe + .\glut\lib;%(AdditionalLibraryDirectories) + true + Console + false + + MachineX64 + + + if $(SolutionName) equ exchange copy /y .\glut\dll\glut64.dll .\$(Platform)\$(Configuration)\ + + + + + .\glut\include;.\;.\traverse\;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level4 + ProgramDatabase + 4505;%(DisableSpecificWarnings) + false + + + glut32.lib;legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + $(OutDir)$(ProjectName).exe + .\glut\lib;%(AdditionalLibraryDirectories) + false + Console + true + true + false + + MachineX86 + + + if $(SolutionName) equ exchange copy /y .\glut\dll\glut32.dll .\$(Platform)\$(Configuration)\ + + + + + X64 + + + .\glut\include;.\;.\traverse\;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level4 + ProgramDatabase + 4505;%(DisableSpecificWarnings) + false + + + glut64.lib;legacy_stdio_float_rounding.obj;%(AdditionalDependencies) + $(OutDir)$(ProjectName).exe + .\glut\lib;%(AdditionalLibraryDirectories) + false + Console + true + true + false + + MachineX64 + + + if $(SolutionName) equ exchange copy /y .\glut\dll\glut64.dll .\$(Platform)\$(Configuration)\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/exchange/exchangesource/Viewer/Viewer.vcxproj.filters b/exchange/exchangesource/Viewer/Viewer.vcxproj.filters new file mode 100644 index 0000000..c4190ed --- /dev/null +++ b/exchange/exchangesource/Viewer/Viewer.vcxproj.filters @@ -0,0 +1,141 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {fa58183b-a9c6-4219-a4cd-8a23ed1c2dce} + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {4df28683-5e8e-4f65-adfa-25a531dde98a} + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files\Visitors + + + Source Files\Visitors + + + Source Files\Visitors + + + Source Files\Visitors + + + Source Files\Visitors + + + Source Files\Visitors + + + Source Files\Visitors + + + Source Files\Visitors + + + Source Files\Visitors + + + Source Files\Visitors + + + Source Files\Visitors + + + Source Files\Visitors + + + Source Files\Visitors + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files\Visitors + + + Header Files\Visitors + + + Header Files\Visitors + + + Header Files\Visitors + + + Header Files\Visitors + + + Header Files\Visitors + + + Header Files\Visitors + + + Header Files\Visitors + + + Header Files\Visitors + + + Header Files\Visitors + + + Header Files\Visitors + + + Header Files\Visitors + + + Header Files\Visitors + + + Header Files\Visitors + + + Header Files\Visitors + + + Header Files\Visitors + + + Header Files\Visitors + + + diff --git a/exchange/exchangesource/Viewer/VisitorBrep.h b/exchange/exchangesource/Viewer/VisitorBrep.h new file mode 100644 index 0000000..a59dcb8 --- /dev/null +++ b/exchange/exchangesource/Viewer/VisitorBrep.h @@ -0,0 +1,73 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef VISIT_BREP +#define VISIT_BREP +#include "Visitors.h" +#include "BrepTraverse.h" +#include + +class A3DVisitorBrep : public A3DVisitor +{ + std::map m_MapEdgeCoEdge; + //friend class A3DVisitorContainer; + +protected: + double m_dScale; + +public: + + A3DVisitorBrep(A3DVisitorContainer* psContainer = NULL) : A3DVisitor("Brep", psContainer) { m_dScale = 1.0;} + + virtual A3DStatus visitEnter(const A3DRiConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DRiConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DBrepDataConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DBrepDataConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DConnexConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DConnexConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DShellConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DShellConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DFaceConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DFaceConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DLoopConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DLoopConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DCoEdgeConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DCoEdgeConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DEdgeConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DEdgeConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DUniqueVertexConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DUniqueVertexConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMultipleVertexConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMultipleVertexConnector&) { return A3D_SUCCESS; } + + double GetScale() const + { + return m_dScale; + } + + std::map GetMapEdgeCoEdge() + { + return m_MapEdgeCoEdge; + } + +}; + + +#endif //VISIT_TOPO \ No newline at end of file diff --git a/exchange/exchangesource/Viewer/VisitorCascadedAttribute.h b/exchange/exchangesource/Viewer/VisitorCascadedAttribute.h new file mode 100644 index 0000000..7b9aedd --- /dev/null +++ b/exchange/exchangesource/Viewer/VisitorCascadedAttribute.h @@ -0,0 +1,76 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef VISITOR_CASCADED_ATTRIBUTE +#define VISITOR_CASCADED_ATTRIBUTE +#include "Visitors.h" +#include + +class A3DCascadedAttribute; +class ColorMaterialsConnector; + +class A3DVisitorColorMaterials : public A3DVisitor +{ +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) // Suppress the warning C4251 because it leads to have that kind of warning : "warning + // C4251: 'A3DVisitorColorMaterials::m_apsCascadedAttribute' : class 'std::vector<_Ty>' needs to have dll-interface to + // be used by clients of class 'A3DVisitorColorMaterials" + // This is because of the "dllexport" on the visitor classes, as they use stl members and it seems that stl causes + // warning with dllexport with microsoft compiler +#endif // _MSC_VER + + //friend class A3DVisitorContainer; + std::vector m_apsCascadedAttribute; + A3DRiRepresentationItem* m_pCurrentRi; //needed for FaceTessDataConnector + +#ifdef _MSC_VER +#pragma warning(pop) +#endif // _MSC_VER + +public: + + A3DVisitorColorMaterials(A3DVisitorContainer* psContainer = NULL); + + virtual ~A3DVisitorColorMaterials(); + + virtual A3DStatus pushCascadedAttribute(const A3DConnector& sEntity); + virtual A3DStatus visitEnter(const A3DProductOccurrenceConnector& sEntity); + virtual A3DStatus visitEnter(const A3DPartConnector& sEntity); + virtual A3DStatus visitEnter(const A3DRiConnector& sEntity); + virtual A3DStatus visitEnter(const A3DFaceTessDataConnector& sEntity); + + virtual A3DStatus popCascadedAttribute(/*const A3DConnector& sEntity*/); + virtual A3DStatus visitLeave(const A3DProductOccurrenceConnector& sEntity); + virtual A3DStatus visitLeave(const A3DPartConnector& sEntity); + virtual A3DStatus visitLeave(const A3DRiConnector& sEntity); + virtual A3DStatus visitLeave(const A3DFaceTessDataConnector& sEntity); + + std::vector GetCascadedAttributes() const { return m_apsCascadedAttribute; } + void _Set(std::vector const & val) { m_apsCascadedAttribute = val; } + void _SetCurrentRi(A3DRiRepresentationItem* const val) { m_pCurrentRi = val; } + +public: + + /////////////////////////////////////////////////////////////////// + // Please, redefined this function in a inherited class to connect + // the meshes provide by 3DX in your application + ////////////////////////////////////////////////////////////////// + + virtual A3DStatus SetGlobalAttributeOnLeaf(const A3DMiscCascadedAttributes* /*psCascadedAttribute*/) { return A3D_SUCCESS; } + + A3DStatus GetColorMaterialConnector(ColorMaterialsConnector& rsColorConnector, bool bUseInstances = false); + + A3DMiscCascadedAttributes* GetLastCascadedAttributes() const; + +}; + +#endif diff --git a/exchange/exchangesource/Viewer/VisitorContainer.h b/exchange/exchangesource/Viewer/VisitorContainer.h new file mode 100644 index 0000000..c1c1603 --- /dev/null +++ b/exchange/exchangesource/Viewer/VisitorContainer.h @@ -0,0 +1,227 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3DVISITOR_CONTAINER +#define A3DVISITOR_CONTAINER +#include +#include "Visitors.h" + +//This class allow to use several vistor when traversing 3DX Tree. +//It allow also to exchange parameters between visitors + +#define NODE_INSTANCES 0x0001 + +class A3DStepEntityRefManager +{ +public: + unsigned int m_uiPOLevel; // Level of creation + unsigned int m_uiPushLevel; // if not ~0U , then is activated + bool m_bRefOnTopoItem;; + A3DMiscEntityReference* m_pStepEntityRef; + A3DEntity* m_pA3DEntityRef; + // std::vector m_apYourEntity; + + A3DStepEntityRefManager() : m_uiPOLevel(~0U), m_uiPushLevel(~0U), m_pStepEntityRef(NULL), m_bRefOnTopoItem(false), + m_pA3DEntityRef(NULL){} + void GetMatrix(); + + bool IsFirst( A3DStepEntityRefManager const & sOther) const { return (m_uiPOLevelsOther.m_uiPushLevel);} +}; + + + +class A3DViewLinkedItemManager + +{ +public: + unsigned int m_uiPOLevel; + unsigned int m_uiPushLevel; // if not ~0U , then is activated + bool m_bRefOnTopoItem; + A3DMiscMarkupLinkedItem * m_pMarkupLinkedItem; + A3DAsmProductOccurrence * m_POOwner; + A3DEntity * m_pA3DEntityRef; + // std::vector m_apYourEntity; + + A3DViewLinkedItemManager() : m_uiPOLevel(~0U), m_uiPushLevel(~0U), m_pMarkupLinkedItem(NULL),m_bRefOnTopoItem(false), + m_POOwner(NULL), m_pA3DEntityRef(NULL){} + void GetMatrix(); + + bool IsFirst( A3DViewLinkedItemManager const & sOther) const { return (m_uiPOLevelsOther.m_uiPushLevel);} +}; + +class A3DVisitorContainer : public A3DVisitor +{ +#ifdef _MSC_VER + +#pragma warning(push) +#pragma warning(disable:4251) // Suppress the warning C4251 because it leads to have that kind of warning : "warning +// C4251: 'A3DVisitorColorMaterials::m_apsCascadedAttribute' : class 'std::vector<_Ty>' needs to have dll-interface to +// be used by clients of class 'A3DVisitorColorMaterials" +// This is because of the "dllexport" on the visitor classes, as they use stl members and it seems that stl causes +// warning with dllexport with microsoft compiler +#endif // _MSC_VER + + std::map m_apA3DEntityYourEntityMap; + std::vector m_apVisitor; + bool m_bTraverseInstance; + + A3DVisitor* m_pTreeVisitor; + A3DAsmProductOccurrence const * m_pCurrentPOFather; + A3DMkpView const * m_psActivatedView; + bool m_bTraverseActivatedViewOnly; + + std::vector m_asStepEntityRefManager; + std::vector m_asViewLinkedItemManager; + unsigned int m_uiCurrentLevel; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif // _MSC_VER + +public: + A3DVisitorContainer(unsigned int uFlagElementToconnect = 0); + + virtual ~A3DVisitorContainer(); + + void push( A3DVisitor* psVisitor); + + //A3DConnector + virtual A3DStatus visitEnter(const A3DConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DConnector& /*sConnector*/) { return A3D_SUCCESS; } + + //Assmebly Tree +#ifdef CONNECT_ASSEMBLY_TREE + virtual A3DStatus visitEnter(const A3DModelFileConnector& sConnector); + virtual A3DStatus visitLeave(const A3DModelFileConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DProductOccurrenceConnector& sConnector); + virtual A3DStatus visitLeave(const A3DProductOccurrenceConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DPartConnector& sConnector); + virtual A3DStatus visitLeave(const A3DPartConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DRiConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiConnector& sConnector); + + + virtual A3DStatus visitEnter(const A3DRiBrepModelConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiBrepModelConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DRiSetConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiSetConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DPolyRiBrepModelConnector& sConnector); + virtual A3DStatus visitLeave(const A3DPolyRiBrepModelConnector& sConnector); + +#endif +#ifdef CONNECT_PMI + //Markup Tree + virtual A3DStatus visitEnter(const A3DMkpAnnotationEntityConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMkpAnnotationEntityConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMkpAnnotationSetConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMkpAnnotationSetConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMkpAnnotationItemConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMkpAnnotationItemConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMarkupConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMarkupConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMarkupDimensionConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMarkupDimensionConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMarkupGDTConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMarkupGDTConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMarkupTessConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMarkupTessConnector& sConnector); + +#endif + +#ifdef CONNECT_BREP + //Brep + virtual A3DStatus visitEnter(const A3DBrepDataConnector& sConnector); + virtual A3DStatus visitLeave(const A3DBrepDataConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DConnexConnector& sConnector); + virtual A3DStatus visitLeave(const A3DConnexConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DShellConnector& sConnector); + virtual A3DStatus visitLeave(const A3DShellConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DFaceConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFaceConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DLoopConnector& sConnector); + virtual A3DStatus visitLeave(const A3DLoopConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DCoEdgeConnector& sConnector); + virtual A3DStatus visitLeave(const A3DCoEdgeConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DEdgeConnector& sConnector); + virtual A3DStatus visitLeave(const A3DEdgeConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DUniqueVertexConnector& sConnector); + virtual A3DStatus visitLeave(const A3DUniqueVertexConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMultipleVertexConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMultipleVertexConnector& sConnector); +#endif +#ifdef CONNECT_MESH + //Mesh + virtual A3DStatus visitEnter(const A3DTessDataConnector& sConnector); + virtual A3DStatus visitLeave(const A3DTessDataConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DFaceTessDataConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFaceTessDataConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMarkupDatumConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMarkupDatumConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DWireTessDataConnector& sConnector); + virtual A3DStatus visitLeave(const A3DWireTessDataConnector& sConnector); + + +#endif + //Views +#ifdef CONNECT_VIEWS + virtual A3DStatus visitEnter(const A3DMkpViewConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMkpViewConnector& sConnector); +#endif + void* FindInMap(const A3DEntity* pA3DEntity); + void SetInMap(const A3DEntity* pA3DEntity, void* pYourEntity); + + std::vector& GetVisitor() { return m_apVisitor; } + + + bool TraverseInstances() { return m_bTraverseInstance; } + void SetTraverseInstance(bool bTraverseInstance) { m_bTraverseInstance = bTraverseInstance; } + + A3DVisitor* GetVisitorByName(std::string strName); + A3DVisitor* GetTreeVisitor() const; + + void SetCurrentPoFather(A3DAsmProductOccurrence const * pCurrentPOFather) { m_pCurrentPOFather = pCurrentPOFather; } + A3DAsmProductOccurrence const * GetCurrentPoFather() { return m_pCurrentPOFather; } + + void SetActivateView(A3DMkpView const * psActivatedView) { m_psActivatedView = psActivatedView; } + A3DMkpView const * GetActivatedView() { return m_psActivatedView; } + + void SetTraverseActivatedViewOnly(bool bTraverseActivatedViewOnly) { m_bTraverseActivatedViewOnly = bTraverseActivatedViewOnly; } + + // StepEntityReference and ViewLinkedItem treatment + A3DStepEntityRefManager const* GetActiveStepEntityRefManager(A3DEntity const * pEntity) const; + A3DViewLinkedItemManager const* GetActiveViewLinkedItemManager(A3DEntity const * pEntity) const; + + void ActivateEntityReference( A3DEntity const* pEntity ); + void DeactivateEntityReference(A3DEntity const* pEntity); +}; +#endif diff --git a/exchange/exchangesource/Viewer/VisitorTessellation.h b/exchange/exchangesource/Viewer/VisitorTessellation.h new file mode 100644 index 0000000..8afe55e --- /dev/null +++ b/exchange/exchangesource/Viewer/VisitorTessellation.h @@ -0,0 +1,49 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_VISIST_TESSELLATION +#define A3D_VISIST_TESSELLATION + +#include "Visitors.h" +#include "TessConnector.h" +#include "MarkupTessConnector.h" + +class A3DVisitorTessellation : public A3DVisitor +{ + friend class A3DVisitorContainer; + + +protected: + bool m_bShow; + +public: + + A3DVisitorTessellation(A3DVisitorContainer* psContainer = NULL) : A3DVisitor("Tessellation", psContainer) {}; + virtual ~A3DVisitorTessellation() {} + + virtual A3DStatus visitEnter(const A3DFaceTessDataConnector& sConnector); + virtual A3DStatus visitLeave(const A3DFaceTessDataConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DTessDataConnector& sTessConnector); + virtual A3DStatus visitLeave(const A3DTessDataConnector& sTessConnector); + + virtual A3DStatus visitEnter(const A3DRiConnector& sTessConnector); + virtual A3DStatus visitLeave(const A3DRiConnector& sTessConnector); + + virtual A3DStatus visitEnter(const A3DMarkupTessConnector& sMarkupTessConnector); + virtual A3DStatus visitLeave(const A3DMarkupTessConnector& /*sMarkupTessConnector*/) { return A3D_SUCCESS; }; + + virtual A3DStatus visitEnter(const A3DWireTessDataConnector& sTessConnector); + virtual A3DStatus visitLeave(const A3DWireTessDataConnector& sTessConnector); + +}; +#endif + diff --git a/exchange/exchangesource/Viewer/VisitorTransfo.h b/exchange/exchangesource/Viewer/VisitorTransfo.h new file mode 100644 index 0000000..258516f --- /dev/null +++ b/exchange/exchangesource/Viewer/VisitorTransfo.h @@ -0,0 +1,83 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef VISIT_TRANSFO +#define VISIT_TRANSFO +#include "Visitors.h" +#include +#include "Matrix.h" + + +class A3DTransfoConnector; + + +//Visitor used to Get transfo on each ProductOccurences and Representation Item Nodes +class A3DVisitorTransfo : public A3DVisitor +{ + //friend class A3DVisitorContainer; + +protected: + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) // Suppress the warning C4251 because it leads to have that kind of warning : "warning + // C4251: 'A3DVisitorColorMaterials::m_apsCascadedAttribute' : class 'std::vector<_Ty>' needs to have dll-interface to + // be used by clients of class 'A3DVisitorColorMaterials" + // This is because of the "dllexport" on the visitor classes, as they use stl members and it seems that stl causes + // warning with dllexport with microsoft compiler +#endif // _MSC_VER + + std::vector m_adPushTransfo; + A3DMatrix4x4 m_adLocalMatrix; + bool m_bUnitFormCad; + double m_dUnit; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif // _MSC_VER + + A3DMiscTransformation* CreateTransfo(A3DMatrix4x4 const & rMatrix); + +public: + + A3DVisitorTransfo(bool bModelFileUnitFormCAD, + double dUnitModelFile, + A3DVisitorContainer* psContainer = NULL); + + A3DVisitorTransfo(A3DVisitorContainer* psContainer = NULL); + + virtual ~A3DVisitorTransfo(); + + virtual A3DStatus visitEnter(const A3DRiConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiConnector& sConnector); + virtual A3DStatus visitEnter(const A3DProductOccurrenceConnector& sConnector); + virtual A3DStatus visitLeave(const A3DProductOccurrenceConnector& sConnector); + virtual A3DStatus visitEnter(const A3DModelFileConnector& sConnector); + virtual A3DStatus visitLeave(const A3DModelFileConnector& sConnector); + + virtual A3DStatus SetLocalTransfo(A3DMatrix4x4 const& rdLocalTransfo) { m_adLocalMatrix = rdLocalTransfo; return A3D_SUCCESS; } + virtual A3DStatus SetGlobalTransfo(A3DMatrix4x4 const& /*rdLocalTransfo*/) { return A3D_SUCCESS; } + + bool UnitFromCad() const + { + return m_bUnitFormCad; + } + + double Unit() const + { + return m_dUnit; + } + + A3DTransfoConnector* GetTransfoConnector(bool bUseInstance = false); + + A3DTransfoConnector* GetTransfoConnectorFromManager(A3DEntity const * pEntity); +}; +#endif diff --git a/exchange/exchangesource/Viewer/VisitorTree.h b/exchange/exchangesource/Viewer/VisitorTree.h new file mode 100644 index 0000000..8295585 --- /dev/null +++ b/exchange/exchangesource/Viewer/VisitorTree.h @@ -0,0 +1,73 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef VISIT_TREE +#define VISIT_TREE +#include "Visitors.h" +#include "VisitorContainer.h" + + +class A3DConnector; +class A3DVisitorContainer; + +class A3DTreeVisitor : public A3DVisitor +{ + friend class A3DVisitorContainer; +protected: + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) // Suppress the warning C4251 because it leads to have that kind of warning : "warning + // C4251: 'A3DVisitorColorMaterials::m_apsCascadedAttribute' : class 'std::vector<_Ty>' needs to have dll-interface to + // be used by clients of class 'A3DVisitorColorMaterials" + // This is because of the "dllexport" on the visitor classes, as they use stl members and it seems that stl causes + // warning with dllexport with microsoft compiler +#endif // _MSC_VER + + unsigned m_uOption; + void* m_pYourEntity; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif // _MSC_VER + +public: + + A3DTreeVisitor(A3DVisitorContainer* psContainer = NULL) : A3DVisitor("Tree", psContainer) + { + m_uOption = 0; + m_pYourEntity = NULL; + } + + virtual ~A3DTreeVisitor() {}; + + virtual A3DStatus visitEnter(const A3DRiBrepModelConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiBrepModelConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DRiSetConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiSetConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DRiConnector& sConnector); + virtual A3DStatus visitLeave(const A3DRiConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DPartConnector& sConnector ); + virtual A3DStatus visitLeave(const A3DPartConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DProductOccurrenceConnector& sConnector); + virtual A3DStatus visitLeave(const A3DProductOccurrenceConnector& sConnector); + + virtual A3DStatus visitEnter(const A3DMkpViewConnector& sConnector); + virtual A3DStatus visitLeave(const A3DMkpViewConnector& sConnector); + + void SetYourEntity(void* pYourEnity); + +}; +#endif \ No newline at end of file diff --git a/exchange/exchangesource/Viewer/Visitors.h b/exchange/exchangesource/Viewer/Visitors.h new file mode 100644 index 0000000..886b29b --- /dev/null +++ b/exchange/exchangesource/Viewer/Visitors.h @@ -0,0 +1,192 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#ifndef A3D_VISITOR +#define A3D_VISITOR + +#define CONNECT_TRANSFO 0x0001 +#define CONNECT_COLORS 0x0002 +#define CONNECT_MESH 0x0004 +#define CONNECT_ASSEMBLY_TREE 0x008 +#define CONNECT_BREP 0x0010 +#define CONNECT_PMI 0x00020 +#define CONNECT_VIEWS 0x00040 + + +#include "TreeTraverse.h" +#ifdef CONNECT_PMI +#include "MarkupTraverse.h" +#endif +#ifdef CONNECT_BREP +#include "BrepTraverse.h" +#endif +#ifdef CONNECT_PMI +#include "MarkupTraverse.h" +#endif +#ifdef CONNECT_MESH +#include "TessConnector.h" +#endif +#ifdef CONNECT_VIEWS +#include "ViewTraverse.h" +#endif + +#include + +#ifndef CALL_A3D_FCTION +#define CALL_A3D_FCTION(fctname, params) \ + fctname params +#endif + +#ifndef CHECK_RET_CALL_A3D_FCTION +#define CHECK_RET_CALL_A3D_FCTION(fctname, params) \ + { \ + if ((iRet = fctname params)!=A3D_SUCCESS) \ + { /*__debugbreak();*/ return iRet; } \ + } +#endif + +#ifndef CHECK_RET +#define CHECK_RET(function_call) \ + {\ + if ((iRet = function_call)!=A3D_SUCCESS) \ + return iRet; \ + } +#endif + +class A3DConnector; +class A3DVisitorContainer; +class A3DVisitor +{ +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) // Suppress the warning C4251 because it leads to have that kind of warning : "warning + // C4251: 'A3DVisitorColorMaterials::m_apsCascadedAttribute' : class 'std::vector<_Ty>' needs to have dll-interface to + // be used by clients of class 'A3DVisitorColorMaterials" + // This is because of the "dllexport" on the visitor classes, as they use stl members and it seems that stl causes + // warning with dllexport with microsoft compiler +#endif // _MSC_VER + +protected: + A3DVisitorContainer* m_psContainer; + std::string m_strName; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif // _MSC_VER + +public : + A3DVisitor(std::string strName, A3DVisitorContainer* psContainer = NULL) + : m_strName(strName), m_psContainer(psContainer){} + + virtual ~A3DVisitor() {} + + virtual std::string GetName() const { return m_strName; } + +//Assembly +#ifdef CONNECT_ASSEMBLY_TREE + virtual A3DStatus visitEnter(const A3DModelFileConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DModelFileConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DProductOccurrenceConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DProductOccurrenceConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DPartConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DPartConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DRiConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DRiConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DRiBrepModelConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DRiBrepModelConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DRiSetConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DRiSetConnector& /*sConnector*/) { return A3D_SUCCESS;} + + virtual A3DStatus visitEnter(const A3DPolyRiBrepModelConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DPolyRiBrepModelConnector& /*sConnector*/) { return A3D_SUCCESS; } + +#endif +//Markup +#ifdef CONNECT_PMI + virtual A3DStatus visitEnter(const A3DMkpAnnotationEntityConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMkpAnnotationEntityConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMkpAnnotationSetConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMkpAnnotationSetConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMkpAnnotationItemConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMkpAnnotationItemConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMarkupConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMarkupConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMarkupDimensionConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMarkupDimensionConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMarkupGDTConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMarkupGDTConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMarkupDatumConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMarkupDatumConnector& /*sConnector*/) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMarkupTessConnector& /*sConnector*/) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMarkupTessConnector& /*sConnector*/) { return A3D_SUCCESS; } + +#endif +//Brep +#ifdef CONNECT_BREP + virtual A3DStatus visitEnter(const A3DBrepDataConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DBrepDataConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DConnexConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DConnexConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DShellConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DShellConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DFaceConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DFaceConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DLoopConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DLoopConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DCoEdgeConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DCoEdgeConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DEdgeConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DEdgeConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DUniqueVertexConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DUniqueVertexConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DMultipleVertexConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMultipleVertexConnector&) { return A3D_SUCCESS; } +#endif + //Mesh +#ifdef CONNECT_MESH + virtual A3DStatus visitEnter(const A3DTessDataConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DTessDataConnector&) { return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DFaceTessDataConnector&) {return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DFaceTessDataConnector&) {return A3D_SUCCESS; } + + virtual A3DStatus visitEnter(const A3DWireTessDataConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DWireTessDataConnector&) { return A3D_SUCCESS; } +#endif + //Views +#ifdef CONNECT_VIEWS + virtual A3DStatus visitEnter(const A3DMkpViewConnector&) { return A3D_SUCCESS; } + virtual A3DStatus visitLeave(const A3DMkpViewConnector&) { return A3D_SUCCESS; } +#endif +}; + + +#endif diff --git a/exchange/exchangesource/Viewer/callback_opengl.cpp b/exchange/exchangesource/Viewer/callback_opengl.cpp new file mode 100644 index 0000000..2cf0989 --- /dev/null +++ b/exchange/exchangesource/Viewer/callback_opengl.cpp @@ -0,0 +1,448 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file callback_opengl.cpp +This file demonstrates how to programmatically visualize a PRC file from a basic OpenGL program using HOOPS Exchange. +***********************************************************************************************************************/ +#include +#include "callback_opengl.h" +#include "A3DVector.h" +#if !defined _MSC_VER && !defined CALLBACK +#define CALLBACK +#endif +#define _USE_MATH_DEFINES +#include +#include +#include +#define IS_EQUAL(A, B) (fabs(A-B) < 1e-12 * (1 + (fabs(A) > fabs(B) ? fabs(A) : fabs(B)))) +static bool stbUseCallbacks = true; +static bool stbCallbacksInitialized = true; +static A3DBoundingBoxData* stpsBoundingBox = nullptr; +static bool stbDraw3D = false; +static bool stbDrawMarkups = false; +//###################################################################################################################### +bool GetstbUseCallbacks() +{ +return stbUseCallbacks; +} +void SetstbUseCallbacks(bool UseCallBack) +{ + stbUseCallbacks = UseCallBack; +} +bool GetstbCallbacksInitialized() +{ + return stbCallbacksInitialized; +} +// *** Bounding Box +A3DBoundingBoxData* GetstpsBoundingBox() +{ + return stpsBoundingBox; +} +void SetstpsBoundingBox(A3DBoundingBoxData* sBoudingBoxData) +{ + stpsBoundingBox = sBoudingBoxData; +} +// *** Draw 3D +bool GetstbDraw3D() +{ + return stbDraw3D; +} +void SetstbDraw3D(bool bDraw3D) +{ + stbDraw3D = bDraw3D; +} +// *** Draw Markups +bool GetstbDrawMarkups() +{ + return stbDrawMarkups; +} +void SetstbDrawMarkups(bool bDrawMarkups) +{ + stbDrawMarkups = bDrawMarkups; +} +//###################################################################################################################### +static double staadStack[32][16]; +static unsigned int uiPos = 0; +static double stadMatrix[16]; +//###################################################################################################################### +void stVectoriel(const A3DVector3dData* X, const A3DVector3dData* Y, A3DVector3dData* Z) +{ + Z->m_dX=X->m_dY*Y->m_dZ - X->m_dZ*Y->m_dY; + Z->m_dY=X->m_dZ*Y->m_dX - X->m_dX*Y->m_dZ; + Z->m_dZ=X->m_dX*Y->m_dY - X->m_dY*Y->m_dX; +} +//###################################################################################################################### +void stMatrixMatrixMult(double m[16], const double o[16]) +{ + memcpy(stadMatrix, m, 16*sizeof(double)); + m[0] = stadMatrix[0] * o[0] + stadMatrix[4] * o[1] + stadMatrix[8] * o[2] + stadMatrix[12] * o[3]; + m[1] = stadMatrix[1] * o[0] + stadMatrix[5] * o[1] + stadMatrix[9] * o[2] + stadMatrix[13] * o[3]; + m[2] = stadMatrix[2] * o[0] + stadMatrix[6] * o[1] + stadMatrix[10] * o[2] + stadMatrix[14] * o[3]; + m[3] = stadMatrix[3] * o[0] + stadMatrix[7] * o[1] + stadMatrix[11] * o[2] + stadMatrix[15] * o[3]; + m[4] = stadMatrix[0] * o[4] + stadMatrix[4] * o[5] + stadMatrix[8] * o[6] + stadMatrix[12] * o[7]; + m[5] = stadMatrix[1] * o[4] + stadMatrix[5] * o[5] + stadMatrix[9] * o[6] + stadMatrix[13] * o[7]; + m[6] = stadMatrix[2] * o[4] + stadMatrix[6] * o[5] + stadMatrix[10] * o[6] + stadMatrix[14] * o[7]; + m[7] = stadMatrix[3] * o[4] + stadMatrix[7] * o[5] + stadMatrix[11] * o[6] + stadMatrix[15] * o[7]; + m[8] = stadMatrix[0] * o[8] + stadMatrix[4] * o[9] + stadMatrix[8] * o[10] + stadMatrix[12] * o[11]; + m[9] = stadMatrix[1] * o[8] + stadMatrix[5] * o[9] + stadMatrix[9] * o[10] + stadMatrix[13] * o[11]; + m[10]= stadMatrix[2] * o[8] + stadMatrix[6] * o[9] + stadMatrix[10] * o[10] + stadMatrix[14] * o[11]; + m[11]= stadMatrix[3] * o[8] + stadMatrix[7] * o[9] + stadMatrix[11] * o[10] + stadMatrix[15] * o[11]; + m[12]= stadMatrix[0] * o[12] + stadMatrix[4] * o[13] + stadMatrix[8] * o[14] + stadMatrix[12] * o[15]; + m[13]= stadMatrix[1] * o[12] + stadMatrix[5] * o[13] + stadMatrix[9] * o[14] + stadMatrix[13] * o[15]; + m[14]= stadMatrix[2] * o[12] + stadMatrix[6] * o[13] + stadMatrix[10] * o[14] + stadMatrix[14] * o[15]; + m[15]= stadMatrix[3] * o[12] + stadMatrix[7] * o[13] + stadMatrix[11] * o[14] + stadMatrix[15] * o[15]; +} +//###################################################################################################################### +void stLoadIdentity() +{ + memset(staadStack[uiPos], 0, 16*sizeof(double)); + staadStack[uiPos][0] = 1.0; + staadStack[uiPos][5] = 1.0; + staadStack[uiPos][10] = 1.0; + staadStack[uiPos][15] = 1.0; +} +//###################################################################################################################### +void stMultMatrix(const double m[16]) +{ + stMatrixMatrixMult(staadStack[uiPos], m); +} +//###################################################################################################################### +void stPushMatrix() +{ + if(uiPos < 7) + { + uiPos++; + memcpy(staadStack[uiPos], staadStack[uiPos-1], 16*sizeof(double)); + } +} +//###################################################################################################################### +void stPopMatrix() +{ + if(uiPos > 0) + { + uiPos--; + } +} +//###################################################################################################################### +void stExtentInit(A3DBoundingBoxData* e) +{ + e->m_sMin.m_dX = 1e10; + e->m_sMin.m_dY = 1e10; + e->m_sMin.m_dZ = 1e10; + e->m_sMax.m_dX = -1e10; + e->m_sMax.m_dY = -1e10; + e->m_sMax.m_dZ = -1e10; +} +//###################################################################################################################### +void stBoundingBoxAddPoint(A3DBoundingBoxData* e, double x, double y, double z) +{ + if (e == nullptr) + return; + if(x < e->m_sMin.m_dX) e->m_sMin.m_dX = x; + if(y < e->m_sMin.m_dY) e->m_sMin.m_dY = y; + if(z < e->m_sMin.m_dZ) e->m_sMin.m_dZ = z; + if(x > e->m_sMax.m_dX) e->m_sMax.m_dX = x; + if(y > e->m_sMax.m_dY) e->m_sMax.m_dY = y; + if(z > e->m_sMax.m_dZ) e->m_sMax.m_dZ = z; +} +//###################################################################################################################### +static int stiDisplayTriangles = 1; +static int stiDisplayTriangleNormals = 0; +static double stdDisplayTriangleNormalLength = 1; +//###################################################################################################################### +int& DisplayTriangles() { return stiDisplayTriangles; } +//###################################################################################################################### +int& DisplayTriangleNormals() { return stiDisplayTriangleNormals; } +//###################################################################################################################### +double& DisplayTriangleNormalLength() { return stdDisplayTriangleNormalLength; } +//###################################################################################################################### +void OpenGL_PushMatrix() +{ + glPushMatrix(); +} +//###################################################################################################################### +void OpenGL_PopMatrix() +{ + glPopMatrix(); +} +//###################################################################################################################### +void OpenGL_MultMatrix(const A3DDouble adMatrix[16]) +{ + glMultMatrixd(adMatrix); +} +//###################################################################################################################### +void OpenGL_Begin(A3DEDrawBeginEndType eType, const A3DUTF8Char* /* pcName */, A3DUns32 /* uiTrianglesCount */) +{ + switch(eType) + { + case kA3DDrawBeginEndMarkup : + glPushAttrib(GL_LIGHTING_BIT | GL_COLOR_BUFFER_BIT ); + glDisable(GL_LIGHTING); + break; + case kA3DDrawBeginEndProductOccurrence: + case kA3DDrawBeginEndRepresentationItem: + break; + default: + break; + } +} +//###################################################################################################################### +void OpenGL_End(A3DEDrawBeginEndType eType) +{ + switch(eType) + { + case kA3DDrawBeginEndMarkup : + glPopAttrib(); + break; + default: + break; + } +} +//###################################################################################################################### +inline void glStartLineDrawing() +{ + glPushAttrib(GL_LIGHTING_BIT | GL_LINE_BIT | GL_TEXTURE_BIT); + glDisable(GL_TEXTURE); + glDisable(GL_LIGHTING); + glLineWidth(2); + glBegin(GL_LINES); +} +//###################################################################################################################### +inline void glEndLineDrawing() +{ + glEnd(); + glPopAttrib(); +} +//###################################################################################################################### +inline void glVertex3d(const A3DVector3dData& aPoint) +{ + glVertex3d(aPoint.m_dX, aPoint.m_dY, aPoint.m_dZ); +} +//###################################################################################################################### +inline void glNormal3d(const A3DVector3dData& aNormal) +{ + glNormal3d(aNormal.m_dX, aNormal.m_dY, aNormal.m_dZ); +} +//###################################################################################################################### +void OpenGL_Triangle(const double* pasNormals, A3DUns32 /*uiNormalSize*/, const double* pasPoints, A3DUns32 /*uiPointSize*/, + std::vector auIndiceTrianglePerFace, + unsigned uTextureCount) +{ + size_t uIndiceTriangleSize = auIndiceTrianglePerFace.size(); + unsigned int uIncr = 2 + uTextureCount; + unsigned int uIncrPt = 1 + uTextureCount; + unsigned* pCurrentTriangleIndice = &auIndiceTrianglePerFace[0]; + unsigned* pCurrentTriangleIndiceTemp; + unsigned* pEndTriangleIndice = &auIndiceTrianglePerFace[uIndiceTriangleSize - 1]; + A3DVector3d sP1, sP2, sP3, sNormal; + unsigned int uPt2Indice = uIncr + uIncrPt; + unsigned int uPt3Indice = uIncr*2 + uIncrPt; + if(stiDisplayTriangles&1) + { + glBegin(GL_TRIANGLES); + while (pCurrentTriangleIndice <= pEndTriangleIndice) + { + // Draw triangles + pCurrentTriangleIndiceTemp = pCurrentTriangleIndice; + for(unsigned uI = 0; uI < 3; uI++) + { + // In case there is no normal + if (pasNormals) + { + if (pasNormals[*pCurrentTriangleIndice] == 0 && + pasNormals[*(pCurrentTriangleIndice)+1] == 0 && + pasNormals[*(pCurrentTriangleIndice)+2] == 0) + { + sP1.set(pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt)], + pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt) + 1], + pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt) + 2]); + sP2.set(pasPoints[*(pCurrentTriangleIndiceTemp + uPt2Indice)], + pasPoints[*(pCurrentTriangleIndiceTemp + uPt2Indice) + 1], + pasPoints[*(pCurrentTriangleIndiceTemp + uPt2Indice) + 2]); + sP3.set(pasPoints[*(pCurrentTriangleIndiceTemp + uPt3Indice)], + pasPoints[*(pCurrentTriangleIndiceTemp + uPt3Indice) + 1], + pasPoints[*(pCurrentTriangleIndiceTemp + uPt3Indice) + 2]); + sNormal = (sP2 - sP1).Cross(sP3 - sP2); + sNormal.normalize(); + glNormal3d(sNormal.x, sNormal.y, sNormal.z); + } + // if normals are defined, we draw the normals + else + glNormal3d(pasNormals[*pCurrentTriangleIndice], pasNormals[*(pCurrentTriangleIndice)+1], pasNormals[*(pCurrentTriangleIndice)+2]); + } + else + { + sP1.set(pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt)], + pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt) + 1], + pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt) + 2]); + sP2.set(pasPoints[*(pCurrentTriangleIndiceTemp + uPt2Indice)], + pasPoints[*(pCurrentTriangleIndiceTemp + uPt2Indice) + 1], + pasPoints[*(pCurrentTriangleIndiceTemp + uPt2Indice) + 2]); + sP3.set(pasPoints[*(pCurrentTriangleIndiceTemp + uPt3Indice)], + pasPoints[*(pCurrentTriangleIndiceTemp + uPt3Indice) + 1], + pasPoints[*(pCurrentTriangleIndiceTemp + uPt3Indice) + 2]); + sNormal = (sP2 - sP1).Cross(sP3 - sP2); + sNormal.normalize(); + glNormal3d(sNormal.x, sNormal.y, sNormal.z); + } + + glVertex3d(pasPoints[*(pCurrentTriangleIndice + uIncrPt)], pasPoints[*(pCurrentTriangleIndice + uIncrPt) + 1], pasPoints[*(pCurrentTriangleIndice + uIncrPt) + 2]); + pCurrentTriangleIndice+=uIncr; + } + } + glEnd(); + } + glStartLineDrawing(); + + // Draw wireframe + if(stiDisplayTriangles&2) + { + glColor3d(0, 0, 0); + pCurrentTriangleIndice = &auIndiceTrianglePerFace[0]; + while (pCurrentTriangleIndice <= pEndTriangleIndice) + { + pCurrentTriangleIndiceTemp = pCurrentTriangleIndice; + glVertex3d(pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt)], pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt) + 1], pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt) + 2]); + glVertex3d(pasPoints[*(pCurrentTriangleIndiceTemp + uPt2Indice)], pasPoints[*(pCurrentTriangleIndiceTemp + uPt2Indice) + 1], pasPoints[*(pCurrentTriangleIndiceTemp + uPt2Indice) + 2]); + glVertex3d(pasPoints[*(pCurrentTriangleIndiceTemp+uPt2Indice)], pasPoints[*(pCurrentTriangleIndiceTemp+uPt2Indice)+1], pasPoints[*(pCurrentTriangleIndiceTemp+uPt2Indice)+2]); + glVertex3d(pasPoints[*(pCurrentTriangleIndiceTemp+uPt3Indice)], pasPoints[*(pCurrentTriangleIndiceTemp+uPt3Indice)+1], pasPoints[*(pCurrentTriangleIndiceTemp+uPt3Indice)+2]); + glVertex3d(pasPoints[*(pCurrentTriangleIndiceTemp + uPt3Indice)], pasPoints[*(pCurrentTriangleIndiceTemp + uPt3Indice) + 1], pasPoints[*(pCurrentTriangleIndiceTemp + uPt3Indice) + 2]); + glVertex3d(pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt)], pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt) + 1], pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt) + 2]); + pCurrentTriangleIndice += uIncr * 3; + } + } + //Draw triangle plane normal + if(stiDisplayTriangleNormals&1) + { + glColor3d(0, 0, 1); + pCurrentTriangleIndice = &auIndiceTrianglePerFace[0]; + while (pCurrentTriangleIndice <= pEndTriangleIndice) + { + pCurrentTriangleIndiceTemp = pCurrentTriangleIndice; + for(unsigned uI = 0; uI < 3; uI++) + { + sP1.set(pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt)], + pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt) + 1], + pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt) + 2]); + sP2.set(pasPoints[*(pCurrentTriangleIndiceTemp+uPt2Indice)], + pasPoints[*(pCurrentTriangleIndiceTemp+uPt2Indice)+1], + pasPoints[*(pCurrentTriangleIndiceTemp+uPt2Indice)+2]); + sP3.set(pasPoints[*(pCurrentTriangleIndiceTemp+uPt3Indice)], + pasPoints[*(pCurrentTriangleIndiceTemp+uPt3Indice)+1], + pasPoints[*(pCurrentTriangleIndiceTemp+uPt3Indice)+2]); + sNormal = (sP2-sP1).Cross(sP3-sP2); + sNormal.normalize(); + glVertex3d((pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt)] + pasPoints[*(pCurrentTriangleIndiceTemp + uPt2Indice)] + pasPoints[*(pCurrentTriangleIndiceTemp + uPt3Indice)]) / 3, + (pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt) + 1] + pasPoints[*(pCurrentTriangleIndiceTemp + uPt2Indice) + 1] + pasPoints[*(pCurrentTriangleIndiceTemp + uPt3Indice) + 1]) / 3, + (pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt) + 2] + pasPoints[*(pCurrentTriangleIndiceTemp + uPt2Indice) + 2] + pasPoints[*(pCurrentTriangleIndiceTemp + uPt3Indice) + 2]) / 3); + glVertex3d((pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt)] + pasPoints[*(pCurrentTriangleIndiceTemp + uPt2Indice)] + pasPoints[*(pCurrentTriangleIndiceTemp + uPt3Indice)]) / 3 + sNormal.x * stdDisplayTriangleNormalLength, + (pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt) + 1] + pasPoints[*(pCurrentTriangleIndiceTemp + uPt2Indice) + 1] + pasPoints[*(pCurrentTriangleIndiceTemp + uPt3Indice) + 1]) / 3 + sNormal.y * stdDisplayTriangleNormalLength, + (pasPoints[*(pCurrentTriangleIndiceTemp + uIncrPt) + 2] + pasPoints[*(pCurrentTriangleIndiceTemp + uPt2Indice) + 2] + pasPoints[*(pCurrentTriangleIndiceTemp + uPt3Indice) + 2]) / 3 + sNormal.z * stdDisplayTriangleNormalLength); + + pCurrentTriangleIndice+=uIncr; + } + } + } + //Draw normals + if(stiDisplayTriangleNormals&2) + { + glColor3d(0, 1, 0); + pCurrentTriangleIndice = &auIndiceTrianglePerFace[0]; + while (pCurrentTriangleIndice < pEndTriangleIndice) + { + pCurrentTriangleIndiceTemp = pCurrentTriangleIndice; + for(unsigned uI = 0; uI < 3; uI++) + { + glVertex3d(pasPoints[*(pCurrentTriangleIndice+uIncrPt)],pasPoints[*(pCurrentTriangleIndice+uIncrPt)+1],pasPoints[*(pCurrentTriangleIndice+uIncrPt)+2]); + glVertex3d(pasPoints[*(pCurrentTriangleIndice+uIncrPt)]+pasNormals[*(pCurrentTriangleIndice)]*stdDisplayTriangleNormalLength, + pasPoints[*(pCurrentTriangleIndice+uIncrPt)+1]+pasNormals[*(pCurrentTriangleIndice)+1]*stdDisplayTriangleNormalLength, + pasPoints[*(pCurrentTriangleIndice+uIncrPt)+2]+pasNormals[*(pCurrentTriangleIndice)+2]*stdDisplayTriangleNormalLength); + + pCurrentTriangleIndice+=uIncr; + } + } + } + glEndLineDrawing(); +} +//###################################################################################################################### +void OpenGL_Color(const double a_adRGB[3]) +{ + GLfloat afValues[3] = { static_cast(a_adRGB[0]), static_cast(a_adRGB[1]), static_cast(a_adRGB[2]) }; + glColor3fv(afValues); +} +//###################################################################################################################### +void OpenGL_Material(A3DEDrawMaterialType eType, const A3DDouble* pdValues, A3DUns32 uiSize) +{ + if(uiSize == 1 && eType == kA3DDrawMaterialShininess) + { + GLfloat afValues[] = { static_cast(pdValues[0]) }; + glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, afValues); + } + else + { + GLfloat afValues[4] = { static_cast(pdValues[0]), static_cast(pdValues[1]), static_cast(pdValues[2]), static_cast((uiSize == 4) ? pdValues[3] : 1) }; + GLenum glMaterialType = GL_AMBIENT; + switch(eType) + { + case kA3DDrawMaterialDiffuse: glMaterialType = GL_DIFFUSE; break; + case kA3DDrawMaterialAmbient: glMaterialType = GL_AMBIENT; break; + case kA3DDrawMaterialEmission: glMaterialType = GL_EMISSION; break; + case kA3DDrawMaterialShininess: return; + default: + break; + } + glMaterialfv(GL_FRONT_AND_BACK, glMaterialType, afValues); + } +} +//###################################################################################################################### +void OpenGL_Point(const A3DDouble* pdPoints, A3DUns32 uiPointSize) +{ + const A3DDouble* pdData = &pdPoints[0]; + glBegin(GL_POINTS); + for(A3DUns32 ui = 0; ui < uiPointSize; ++ui) + { + glVertex3dv(pdData); + pdData += 3; + } + glEnd(); +} +//###################################################################################################################### +void OpenGL_Font(const A3DFontKeyData* /*psFontKeyData*/) +{ +} +//###################################################################################################################### +void OpenGL_MarkupTriangle(A3DDouble* pdPoints, A3DUns32 uiPointSize) +{ + const A3DDouble* pdData = &pdPoints[0]; + glBegin(GL_TRIANGLES); + for(A3DUns32 ui = 0; ui < uiPointSize/3; ++ui) + { + glVertex3dv(pdData); + pdData += 3; + glVertex3dv(pdData); + pdData += 3; + glVertex3dv(pdData); + pdData += 3; + } + glEnd(); +} +//###################################################################################################################### +void OpenGL_PolyLine(A3DDouble* pdPoints, A3DUns32 uiPointSize) +{ + const A3DDouble* pdData = &pdPoints[0]; + glBegin(GL_LINE_STRIP); + for(A3DUns32 ui = 0; ui < uiPointSize; ++ui) + { + glVertex3dv(pdData); + pdData += 3; + } + glEnd(); +} \ No newline at end of file diff --git a/exchange/exchangesource/Viewer/callback_opengl.h b/exchange/exchangesource/Viewer/callback_opengl.h new file mode 100644 index 0000000..9c49643 --- /dev/null +++ b/exchange/exchangesource/Viewer/callback_opengl.h @@ -0,0 +1,125 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file callback_opengl.h + +This file demonstrates how to programmatically visualize a PRC file from a basic OpenGL program using HOOPS Exchange. + +***********************************************************************************************************************/ + +#ifndef _CALLBACK_OPENGL_H_ +#define _CALLBACK_OPENGL_H_ + +#include + +#ifdef __APPLE__ +#include +#else +#include +#endif + +#include "TreeTraverse.h" + + +//###################################################################################################################### + +bool GetstbUseCallbacks(); +void SetstbUseCallbacks(bool UseCallBack); +A3DDrawCallbacksData GetA3DDrawCallbacksData(); +bool GetstbCallbacksInitialized(); +A3DBoundingBoxData* GetstpsBoundingBox(); +void SetstpsBoundingBox(A3DBoundingBoxData* sBoudingBoxData); +bool GetstbDraw3D(); +void SetstbDraw3D(bool bDraw3D); +bool GetstbDrawMarkups(); +void SetstbDrawMarkups(bool bDrawMarkups); + +//###################################################################################################################### +#define A3D_MIN(a,b) (((a)<(b)) ? (a) : (b)) +#define A3D_MAX(a,b) (((a)>(b)) ? (a) : (b)) + +//###################################################################################################################### +void stVectoriel(const A3DVector3dData* X, const A3DVector3dData* Y, A3DVector3dData* Z); + +//###################################################################################################################### +void stMatrixMatrixMult(double m[16], const double o[16]); + +//###################################################################################################################### +void stLoadIdentity(); + +//###################################################################################################################### +void stMultMatrix(const double m[16]); + +//###################################################################################################################### +void stPushMatrix(); + +//###################################################################################################################### +void stPopMatrix(); + +//###################################################################################################################### +void stExtentInit(A3DBoundingBoxData* e); + +//###################################################################################################################### +void stBoundingBoxAddPoint(A3DBoundingBoxData* e, double x, double y, double z); + +//###################################################################################################################### +void OpenGL_PushMatrix(); + +//###################################################################################################################### +void OpenGL_PopMatrix(); + +//###################################################################################################################### +void OpenGL_MultMatrix(const A3DDouble adMatrix[16]); + +//###################################################################################################################### +void OpenGL_Begin(A3DEDrawBeginEndType eType, const A3DUTF8Char* pcName, A3DUns32 uiTrianglesCount); + +//###################################################################################################################### +void OpenGL_End(A3DEDrawBeginEndType eType); + +//###################################################################################################################### +void OpenGL_Triangle(const double* pasNormals, A3DUns32 uiNormalSize, const double* pasPoints, A3DUns32 uiPointSize, + std::vector auIndiceTrianglePerFace, + unsigned uTextureCount); + +//###################################################################################################################### + +void OpenGL_Material(A3DEDrawMaterialType eType, const A3DDouble* pdValues, A3DUns32 uiSize); + +//###################################################################################################################### +void OpenGL_MarkupTriangle(A3DDouble* pdPoints, A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_Point(const A3DDouble* pdPoints, A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_Font(const A3DFontKeyData* psFontKeyData); + +//###################################################################################################################### +void OpenGL_Symbol(const A3DGraphVPicturePatternData* psPatternData, const A3DVector3dData* psPosition); + +//###################################################################################################################### +void OpenGL_PolyLine(A3DDouble* pdPoints, A3DUns32 uiPointSize); + +//###################################################################################################################### +void OpenGL_Color(const A3DDouble [3]); + +//###################################################################################################################### +int& DisplayTriangles(); + +//###################################################################################################################### +int& DisplayTriangleNormals(); + +//###################################################################################################################### +double& DisplayTriangleNormalLength(); + + +#endif diff --git a/exchange/exchangesource/Viewer/glut/include/GL/glut.h b/exchange/exchangesource/Viewer/glut/include/GL/glut.h new file mode 100644 index 0000000..0e6ddfb --- /dev/null +++ b/exchange/exchangesource/Viewer/glut/include/GL/glut.h @@ -0,0 +1,716 @@ +#ifndef __glut_h__ +#define __glut_h__ + +/* Copyright (c) Mark J. Kilgard, 1994, 1995, 1996, 1998. */ + +/* This program is freely distributable without licensing fees and is + provided without guarantee or warrantee expressed or implied. This + program is -not- in the public domain. */ + +#if defined(_WIN32) + +/* GLUT 3.7 now tries to avoid including + to avoid name space pollution, but Win32's + needs APIENTRY and WINGDIAPI defined properly. */ +# if 0 + /* This would put tons of macros and crap in our clean name space. */ +# define WIN32_LEAN_AND_MEAN +# include +# else + /* XXX This is from Win32's */ +# ifndef APIENTRY +# define GLUT_APIENTRY_DEFINED +# if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) || defined(__BORLANDC__) || defined(__LCC__) +# define APIENTRY __stdcall +# else +# define APIENTRY +# endif +# endif + /* XXX This is from Win32's */ +# ifndef CALLBACK +# if (defined(_M_MRX000) || defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC)) && !defined(MIDL_PASS) || defined(__LCC__) +# define CALLBACK __stdcall +# else +# define CALLBACK +# endif +# endif + /* XXX Hack for lcc compiler. It doesn't support __declspec(dllimport), just __stdcall. */ +# if defined( __LCC__ ) +# undef WINGDIAPI +# define WINGDIAPI __stdcall +# else + /* XXX This is from Win32's and */ +# ifndef WINGDIAPI +# define GLUT_WINGDIAPI_DEFINED +# define WINGDIAPI __declspec(dllimport) +# endif +# endif + /* XXX This is from Win32's */ +# ifndef _WCHAR_T_DEFINED +typedef unsigned short wchar_t; +# define _WCHAR_T_DEFINED +# endif +# endif + +/* To disable automatic library usage for GLUT, define GLUT_NO_LIB_PRAGMA + in your compile preprocessor options. */ +# if !defined(GLUT_BUILDING_LIB) && !defined(GLUT_NO_LIB_PRAGMA) +# pragma comment (lib, "winmm.lib") /* link with Windows MultiMedia lib */ +/* To enable automatic SGI OpenGL for Windows library usage for GLUT, + define GLUT_USE_SGI_OPENGL in your compile preprocessor options. */ +# ifdef GLUT_USE_SGI_OPENGL +# pragma comment (lib, "opengl.lib") /* link with SGI OpenGL for Windows lib */ +# pragma comment (lib, "glu.lib") /* link with SGI OpenGL Utility lib */ +# pragma comment (lib, "glut.lib") /* link with Win32 GLUT for SGI OpenGL lib */ +# else +# pragma comment (lib, "opengl32.lib") /* link with Microsoft OpenGL lib */ +# pragma comment (lib, "glu32.lib") /* link with Microsoft OpenGL Utility lib */ +# pragma comment (lib, "glut32.lib") /* link with Win32 GLUT lib */ +# endif +# endif + +/* To disable supression of annoying warnings about floats being promoted + to doubles, define GLUT_NO_WARNING_DISABLE in your compile preprocessor + options. */ +# ifndef GLUT_NO_WARNING_DISABLE +# pragma warning (disable:4244) /* Disable bogus VC++ 4.2 conversion warnings. */ +# pragma warning (disable:4305) /* VC++ 5.0 version of above warning. */ +# endif + +/* Win32 has an annoying issue where there are multiple C run-time + libraries (CRTs). If the executable is linked with a different CRT + from the GLUT DLL, the GLUT DLL will not share the same CRT static + data seen by the executable. In particular, atexit callbacks registered + in the executable will not be called if GLUT calls its (different) + exit routine). GLUT is typically built with the + "/MD" option (the CRT with multithreading DLL support), but the Visual + C++ linker default is "/ML" (the single threaded CRT). + + One workaround to this issue is requiring users to always link with + the same CRT as GLUT is compiled with. That requires users supply a + non-standard option. GLUT 3.7 has its own built-in workaround where + the executable's "exit" function pointer is covertly passed to GLUT. + GLUT then calls the executable's exit function pointer to ensure that + any "atexit" calls registered by the application are called if GLUT + needs to exit. + + Note that the __glut*WithExit routines should NEVER be called directly. + To avoid the atexit workaround, #define GLUT_DISABLE_ATEXIT_HACK. */ + +/* XXX This is from Win32's */ +# if !defined(_MSC_VER) && !defined(__cdecl) + /* Define __cdecl for non-Microsoft compilers. */ +# define __cdecl +# define GLUT_DEFINED___CDECL +# endif +# ifndef _CRTIMP +# ifdef _NTSDK + /* Definition compatible with NT SDK */ +# define _CRTIMP +# else + /* Current definition */ +# ifdef _DLL +# define _CRTIMP __declspec(dllimport) +# else +# define _CRTIMP +# endif +# endif +# define GLUT_DEFINED__CRTIMP +# endif + +/* GLUT API entry point declarations for Win32. */ +# ifdef GLUT_BUILDING_LIB +# define GLUTAPI __declspec(dllexport) +# else +# ifdef _DLL +# define GLUTAPI __declspec(dllimport) +# else +# define GLUTAPI extern +# endif +# endif + +/* GLUT callback calling convention for Win32. */ +# define GLUTCALLBACK __cdecl + +#endif /* _WIN32 */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_WIN32) +# ifndef GLUT_BUILDING_LIB +extern _CRTIMP void __cdecl exit(int); +# endif +#else +/* non-Win32 case. */ +/* Define APIENTRY and CALLBACK to nothing if we aren't on Win32. */ +# define APIENTRY +# define GLUT_APIENTRY_DEFINED +# define CALLBACK +/* Define GLUTAPI and GLUTCALLBACK as below if we aren't on Win32. */ +# define GLUTAPI extern +# define GLUTCALLBACK +/* Prototype exit for the non-Win32 case (see above). */ +extern void exit(int); +#endif + +/** + GLUT API revision history: + + GLUT_API_VERSION is updated to reflect incompatible GLUT + API changes (interface changes, semantic changes, deletions, + or additions). + + GLUT_API_VERSION=1 First public release of GLUT. 11/29/94 + + GLUT_API_VERSION=2 Added support for OpenGL/GLX multisampling, + extension. Supports new input devices like tablet, dial and button + box, and Spaceball. Easy to query OpenGL extensions. + + GLUT_API_VERSION=3 glutMenuStatus added. + + GLUT_API_VERSION=4 glutInitDisplayString, glutWarpPointer, + glutBitmapLength, glutStrokeLength, glutWindowStatusFunc, dynamic + video resize subAPI, glutPostWindowRedisplay, glutKeyboardUpFunc, + glutSpecialUpFunc, glutIgnoreKeyRepeat, glutSetKeyRepeat, + glutJoystickFunc, glutForceJoystickFunc (NOT FINALIZED!). +**/ +#ifndef GLUT_API_VERSION /* allow this to be overriden */ +#define GLUT_API_VERSION 3 +#endif + +/** + GLUT implementation revision history: + + GLUT_XLIB_IMPLEMENTATION is updated to reflect both GLUT + API revisions and implementation revisions (ie, bug fixes). + + GLUT_XLIB_IMPLEMENTATION=1 mjk's first public release of + GLUT Xlib-based implementation. 11/29/94 + + GLUT_XLIB_IMPLEMENTATION=2 mjk's second public release of + GLUT Xlib-based implementation providing GLUT version 2 + interfaces. + + GLUT_XLIB_IMPLEMENTATION=3 mjk's GLUT 2.2 images. 4/17/95 + + GLUT_XLIB_IMPLEMENTATION=4 mjk's GLUT 2.3 images. 6/?/95 + + GLUT_XLIB_IMPLEMENTATION=5 mjk's GLUT 3.0 images. 10/?/95 + + GLUT_XLIB_IMPLEMENTATION=7 mjk's GLUT 3.1+ with glutWarpPoitner. 7/24/96 + + GLUT_XLIB_IMPLEMENTATION=8 mjk's GLUT 3.1+ with glutWarpPoitner + and video resize. 1/3/97 + + GLUT_XLIB_IMPLEMENTATION=9 mjk's GLUT 3.4 release with early GLUT 4 routines. + + GLUT_XLIB_IMPLEMENTATION=11 Mesa 2.5's GLUT 3.6 release. + + GLUT_XLIB_IMPLEMENTATION=12 mjk's GLUT 3.6 release with early GLUT 4 routines + signal handling. + + GLUT_XLIB_IMPLEMENTATION=13 mjk's GLUT 3.7 beta with GameGLUT support. + + GLUT_XLIB_IMPLEMENTATION=14 mjk's GLUT 3.7 beta with f90gl friend interface. + + GLUT_XLIB_IMPLEMENTATION=15 mjk's GLUT 3.7 beta sync'ed with Mesa +**/ +#ifndef GLUT_XLIB_IMPLEMENTATION /* Allow this to be overriden. */ +#define GLUT_XLIB_IMPLEMENTATION 15 +#endif + +/* Display mode bit masks. */ +#define GLUT_RGB 0 +#define GLUT_RGBA GLUT_RGB +#define GLUT_INDEX 1 +#define GLUT_SINGLE 0 +#define GLUT_DOUBLE 2 +#define GLUT_ACCUM 4 +#define GLUT_ALPHA 8 +#define GLUT_DEPTH 16 +#define GLUT_STENCIL 32 +#if (GLUT_API_VERSION >= 2) +#define GLUT_MULTISAMPLE 128 +#define GLUT_STEREO 256 +#endif +#if (GLUT_API_VERSION >= 3) +#define GLUT_LUMINANCE 512 +#endif + +/* Mouse buttons. */ +#define GLUT_LEFT_BUTTON 0 +#define GLUT_MIDDLE_BUTTON 1 +#define GLUT_RIGHT_BUTTON 2 + +/* Mouse button state. */ +#define GLUT_DOWN 0 +#define GLUT_UP 1 + +#if (GLUT_API_VERSION >= 2) +/* function keys */ +#define GLUT_KEY_F1 1 +#define GLUT_KEY_F2 2 +#define GLUT_KEY_F3 3 +#define GLUT_KEY_F4 4 +#define GLUT_KEY_F5 5 +#define GLUT_KEY_F6 6 +#define GLUT_KEY_F7 7 +#define GLUT_KEY_F8 8 +#define GLUT_KEY_F9 9 +#define GLUT_KEY_F10 10 +#define GLUT_KEY_F11 11 +#define GLUT_KEY_F12 12 +/* directional keys */ +#define GLUT_KEY_LEFT 100 +#define GLUT_KEY_UP 101 +#define GLUT_KEY_RIGHT 102 +#define GLUT_KEY_DOWN 103 +#define GLUT_KEY_PAGE_UP 104 +#define GLUT_KEY_PAGE_DOWN 105 +#define GLUT_KEY_HOME 106 +#define GLUT_KEY_END 107 +#define GLUT_KEY_INSERT 108 +#endif + +/* Entry/exit state. */ +#define GLUT_LEFT 0 +#define GLUT_ENTERED 1 + +/* Menu usage state. */ +#define GLUT_MENU_NOT_IN_USE 0 +#define GLUT_MENU_IN_USE 1 + +/* Visibility state. */ +#define GLUT_NOT_VISIBLE 0 +#define GLUT_VISIBLE 1 + +/* Window status state. */ +#define GLUT_HIDDEN 0 +#define GLUT_FULLY_RETAINED 1 +#define GLUT_PARTIALLY_RETAINED 2 +#define GLUT_FULLY_COVERED 3 + +/* Color index component selection values. */ +#define GLUT_RED 0 +#define GLUT_GREEN 1 +#define GLUT_BLUE 2 + +#if defined(_WIN32) +/* Stroke font constants (use these in GLUT program). */ +#define GLUT_STROKE_ROMAN ((void*)0) +#define GLUT_STROKE_MONO_ROMAN ((void*)1) + +/* Bitmap font constants (use these in GLUT program). */ +#define GLUT_BITMAP_9_BY_15 ((void*)2) +#define GLUT_BITMAP_8_BY_13 ((void*)3) +#define GLUT_BITMAP_TIMES_ROMAN_10 ((void*)4) +#define GLUT_BITMAP_TIMES_ROMAN_24 ((void*)5) +#if (GLUT_API_VERSION >= 3) +#define GLUT_BITMAP_HELVETICA_10 ((void*)6) +#define GLUT_BITMAP_HELVETICA_12 ((void*)7) +#define GLUT_BITMAP_HELVETICA_18 ((void*)8) +#endif +#else +/* Stroke font opaque addresses (use constants instead in source code). */ +GLUTAPI void *glutStrokeRoman; +GLUTAPI void *glutStrokeMonoRoman; + +/* Stroke font constants (use these in GLUT program). */ +#define GLUT_STROKE_ROMAN (&glutStrokeRoman) +#define GLUT_STROKE_MONO_ROMAN (&glutStrokeMonoRoman) + +/* Bitmap font opaque addresses (use constants instead in source code). */ +GLUTAPI void *glutBitmap9By15; +GLUTAPI void *glutBitmap8By13; +GLUTAPI void *glutBitmapTimesRoman10; +GLUTAPI void *glutBitmapTimesRoman24; +GLUTAPI void *glutBitmapHelvetica10; +GLUTAPI void *glutBitmapHelvetica12; +GLUTAPI void *glutBitmapHelvetica18; + +/* Bitmap font constants (use these in GLUT program). */ +#define GLUT_BITMAP_9_BY_15 (&glutBitmap9By15) +#define GLUT_BITMAP_8_BY_13 (&glutBitmap8By13) +#define GLUT_BITMAP_TIMES_ROMAN_10 (&glutBitmapTimesRoman10) +#define GLUT_BITMAP_TIMES_ROMAN_24 (&glutBitmapTimesRoman24) +#if (GLUT_API_VERSION >= 3) +#define GLUT_BITMAP_HELVETICA_10 (&glutBitmapHelvetica10) +#define GLUT_BITMAP_HELVETICA_12 (&glutBitmapHelvetica12) +#define GLUT_BITMAP_HELVETICA_18 (&glutBitmapHelvetica18) +#endif +#endif + +/* glutGet parameters. */ +#define GLUT_WINDOW_X ((GLenum) 100) +#define GLUT_WINDOW_Y ((GLenum) 101) +#define GLUT_WINDOW_WIDTH ((GLenum) 102) +#define GLUT_WINDOW_HEIGHT ((GLenum) 103) +#define GLUT_WINDOW_BUFFER_SIZE ((GLenum) 104) +#define GLUT_WINDOW_STENCIL_SIZE ((GLenum) 105) +#define GLUT_WINDOW_DEPTH_SIZE ((GLenum) 106) +#define GLUT_WINDOW_RED_SIZE ((GLenum) 107) +#define GLUT_WINDOW_GREEN_SIZE ((GLenum) 108) +#define GLUT_WINDOW_BLUE_SIZE ((GLenum) 109) +#define GLUT_WINDOW_ALPHA_SIZE ((GLenum) 110) +#define GLUT_WINDOW_ACCUM_RED_SIZE ((GLenum) 111) +#define GLUT_WINDOW_ACCUM_GREEN_SIZE ((GLenum) 112) +#define GLUT_WINDOW_ACCUM_BLUE_SIZE ((GLenum) 113) +#define GLUT_WINDOW_ACCUM_ALPHA_SIZE ((GLenum) 114) +#define GLUT_WINDOW_DOUBLEBUFFER ((GLenum) 115) +#define GLUT_WINDOW_RGBA ((GLenum) 116) +#define GLUT_WINDOW_PARENT ((GLenum) 117) +#define GLUT_WINDOW_NUM_CHILDREN ((GLenum) 118) +#define GLUT_WINDOW_COLORMAP_SIZE ((GLenum) 119) +#if (GLUT_API_VERSION >= 2) +#define GLUT_WINDOW_NUM_SAMPLES ((GLenum) 120) +#define GLUT_WINDOW_STEREO ((GLenum) 121) +#endif +#if (GLUT_API_VERSION >= 3) +#define GLUT_WINDOW_CURSOR ((GLenum) 122) +#endif +#define GLUT_SCREEN_WIDTH ((GLenum) 200) +#define GLUT_SCREEN_HEIGHT ((GLenum) 201) +#define GLUT_SCREEN_WIDTH_MM ((GLenum) 202) +#define GLUT_SCREEN_HEIGHT_MM ((GLenum) 203) +#define GLUT_MENU_NUM_ITEMS ((GLenum) 300) +#define GLUT_DISPLAY_MODE_POSSIBLE ((GLenum) 400) +#define GLUT_INIT_WINDOW_X ((GLenum) 500) +#define GLUT_INIT_WINDOW_Y ((GLenum) 501) +#define GLUT_INIT_WINDOW_WIDTH ((GLenum) 502) +#define GLUT_INIT_WINDOW_HEIGHT ((GLenum) 503) +#define GLUT_INIT_DISPLAY_MODE ((GLenum) 504) +#if (GLUT_API_VERSION >= 2) +#define GLUT_ELAPSED_TIME ((GLenum) 700) +#endif +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13) +#define GLUT_WINDOW_FORMAT_ID ((GLenum) 123) +#endif + +#if (GLUT_API_VERSION >= 2) +/* glutDeviceGet parameters. */ +#define GLUT_HAS_KEYBOARD ((GLenum) 600) +#define GLUT_HAS_MOUSE ((GLenum) 601) +#define GLUT_HAS_SPACEBALL ((GLenum) 602) +#define GLUT_HAS_DIAL_AND_BUTTON_BOX ((GLenum) 603) +#define GLUT_HAS_TABLET ((GLenum) 604) +#define GLUT_NUM_MOUSE_BUTTONS ((GLenum) 605) +#define GLUT_NUM_SPACEBALL_BUTTONS ((GLenum) 606) +#define GLUT_NUM_BUTTON_BOX_BUTTONS ((GLenum) 607) +#define GLUT_NUM_DIALS ((GLenum) 608) +#define GLUT_NUM_TABLET_BUTTONS ((GLenum) 609) +#endif +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13) +#define GLUT_DEVICE_IGNORE_KEY_REPEAT ((GLenum) 610) +#define GLUT_DEVICE_KEY_REPEAT ((GLenum) 611) +#define GLUT_HAS_JOYSTICK ((GLenum) 612) +#define GLUT_OWNS_JOYSTICK ((GLenum) 613) +#define GLUT_JOYSTICK_BUTTONS ((GLenum) 614) +#define GLUT_JOYSTICK_AXES ((GLenum) 615) +#define GLUT_JOYSTICK_POLL_RATE ((GLenum) 616) +#endif + +#if (GLUT_API_VERSION >= 3) +/* glutLayerGet parameters. */ +#define GLUT_OVERLAY_POSSIBLE ((GLenum) 800) +#define GLUT_LAYER_IN_USE ((GLenum) 801) +#define GLUT_HAS_OVERLAY ((GLenum) 802) +#define GLUT_TRANSPARENT_INDEX ((GLenum) 803) +#define GLUT_NORMAL_DAMAGED ((GLenum) 804) +#define GLUT_OVERLAY_DAMAGED ((GLenum) 805) + +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) +/* glutVideoResizeGet parameters. */ +#define GLUT_VIDEO_RESIZE_POSSIBLE ((GLenum) 900) +#define GLUT_VIDEO_RESIZE_IN_USE ((GLenum) 901) +#define GLUT_VIDEO_RESIZE_X_DELTA ((GLenum) 902) +#define GLUT_VIDEO_RESIZE_Y_DELTA ((GLenum) 903) +#define GLUT_VIDEO_RESIZE_WIDTH_DELTA ((GLenum) 904) +#define GLUT_VIDEO_RESIZE_HEIGHT_DELTA ((GLenum) 905) +#define GLUT_VIDEO_RESIZE_X ((GLenum) 906) +#define GLUT_VIDEO_RESIZE_Y ((GLenum) 907) +#define GLUT_VIDEO_RESIZE_WIDTH ((GLenum) 908) +#define GLUT_VIDEO_RESIZE_HEIGHT ((GLenum) 909) +#endif + +/* glutUseLayer parameters. */ +#define GLUT_NORMAL ((GLenum) 0) +#define GLUT_OVERLAY ((GLenum) 1) + +/* glutGetModifiers return mask. */ +#define GLUT_ACTIVE_SHIFT 1 +#define GLUT_ACTIVE_CTRL 2 +#define GLUT_ACTIVE_ALT 4 + +/* glutSetCursor parameters. */ +/* Basic arrows. */ +#define GLUT_CURSOR_RIGHT_ARROW 0 +#define GLUT_CURSOR_LEFT_ARROW 1 +/* Symbolic cursor shapes. */ +#define GLUT_CURSOR_INFO 2 +#define GLUT_CURSOR_DESTROY 3 +#define GLUT_CURSOR_HELP 4 +#define GLUT_CURSOR_CYCLE 5 +#define GLUT_CURSOR_SPRAY 6 +#define GLUT_CURSOR_WAIT 7 +#define GLUT_CURSOR_TEXT 8 +#define GLUT_CURSOR_CROSSHAIR 9 +/* Directional cursors. */ +#define GLUT_CURSOR_UP_DOWN 10 +#define GLUT_CURSOR_LEFT_RIGHT 11 +/* Sizing cursors. */ +#define GLUT_CURSOR_TOP_SIDE 12 +#define GLUT_CURSOR_BOTTOM_SIDE 13 +#define GLUT_CURSOR_LEFT_SIDE 14 +#define GLUT_CURSOR_RIGHT_SIDE 15 +#define GLUT_CURSOR_TOP_LEFT_CORNER 16 +#define GLUT_CURSOR_TOP_RIGHT_CORNER 17 +#define GLUT_CURSOR_BOTTOM_RIGHT_CORNER 18 +#define GLUT_CURSOR_BOTTOM_LEFT_CORNER 19 +/* Inherit from parent window. */ +#define GLUT_CURSOR_INHERIT 100 +/* Blank cursor. */ +#define GLUT_CURSOR_NONE 101 +/* Fullscreen crosshair (if available). */ +#define GLUT_CURSOR_FULL_CROSSHAIR 102 +#endif + +/* GLUT initialization sub-API. */ +GLUTAPI void APIENTRY glutInit(int *argcp, char **argv); +#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK) +GLUTAPI void APIENTRY __glutInitWithExit(int *argcp, char **argv, void (__cdecl *exitfunc)(int)); +#ifndef GLUT_BUILDING_LIB +static void APIENTRY glutInit_ATEXIT_HACK(int *argcp, char **argv) { __glutInitWithExit(argcp, argv, exit); } +#define glutInit glutInit_ATEXIT_HACK +#endif +#endif +GLUTAPI void APIENTRY glutInitDisplayMode(unsigned int mode); +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) +GLUTAPI void APIENTRY glutInitDisplayString(const char *string); +#endif +GLUTAPI void APIENTRY glutInitWindowPosition(int x, int y); +GLUTAPI void APIENTRY glutInitWindowSize(int width, int height); +GLUTAPI void APIENTRY glutMainLoop(void); + +/* GLUT window sub-API. */ +GLUTAPI int APIENTRY glutCreateWindow(const char *title); +#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK) +GLUTAPI int APIENTRY __glutCreateWindowWithExit(const char *title, void (__cdecl *exitfunc)(int)); +#ifndef GLUT_BUILDING_LIB +static int APIENTRY glutCreateWindow_ATEXIT_HACK(const char *title) { return __glutCreateWindowWithExit(title, exit); } +#define glutCreateWindow glutCreateWindow_ATEXIT_HACK +#endif +#endif +GLUTAPI int APIENTRY glutCreateSubWindow(int win, int x, int y, int width, int height); +GLUTAPI void APIENTRY glutDestroyWindow(int win); +GLUTAPI void APIENTRY glutPostRedisplay(void); +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 11) +GLUTAPI void APIENTRY glutPostWindowRedisplay(int win); +#endif +GLUTAPI void APIENTRY glutSwapBuffers(void); +GLUTAPI int APIENTRY glutGetWindow(void); +GLUTAPI void APIENTRY glutSetWindow(int win); +GLUTAPI void APIENTRY glutSetWindowTitle(const char *title); +GLUTAPI void APIENTRY glutSetIconTitle(const char *title); +GLUTAPI void APIENTRY glutPositionWindow(int x, int y); +GLUTAPI void APIENTRY glutReshapeWindow(int width, int height); +GLUTAPI void APIENTRY glutPopWindow(void); +GLUTAPI void APIENTRY glutPushWindow(void); +GLUTAPI void APIENTRY glutIconifyWindow(void); +GLUTAPI void APIENTRY glutShowWindow(void); +GLUTAPI void APIENTRY glutHideWindow(void); +#if (GLUT_API_VERSION >= 3) +GLUTAPI void APIENTRY glutFullScreen(void); +GLUTAPI void APIENTRY glutSetCursor(int cursor); +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) +GLUTAPI void APIENTRY glutWarpPointer(int x, int y); +#endif + +/* GLUT overlay sub-API. */ +GLUTAPI void APIENTRY glutEstablishOverlay(void); +GLUTAPI void APIENTRY glutRemoveOverlay(void); +GLUTAPI void APIENTRY glutUseLayer(GLenum layer); +GLUTAPI void APIENTRY glutPostOverlayRedisplay(void); +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 11) +GLUTAPI void APIENTRY glutPostWindowOverlayRedisplay(int win); +#endif +GLUTAPI void APIENTRY glutShowOverlay(void); +GLUTAPI void APIENTRY glutHideOverlay(void); +#endif + +/* GLUT menu sub-API. */ +GLUTAPI int APIENTRY glutCreateMenu(void (GLUTCALLBACK *func)(int)); +#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK) +GLUTAPI int APIENTRY __glutCreateMenuWithExit(void (GLUTCALLBACK *func)(int), void (__cdecl *exitfunc)(int)); +#ifndef GLUT_BUILDING_LIB +static int APIENTRY glutCreateMenu_ATEXIT_HACK(void (GLUTCALLBACK *func)(int)) { return __glutCreateMenuWithExit(func, exit); } +#define glutCreateMenu glutCreateMenu_ATEXIT_HACK +#endif +#endif +GLUTAPI void APIENTRY glutDestroyMenu(int menu); +GLUTAPI int APIENTRY glutGetMenu(void); +GLUTAPI void APIENTRY glutSetMenu(int menu); +GLUTAPI void APIENTRY glutAddMenuEntry(const char *label, int value); +GLUTAPI void APIENTRY glutAddSubMenu(const char *label, int submenu); +GLUTAPI void APIENTRY glutChangeToMenuEntry(int item, const char *label, int value); +GLUTAPI void APIENTRY glutChangeToSubMenu(int item, const char *label, int submenu); +GLUTAPI void APIENTRY glutRemoveMenuItem(int item); +GLUTAPI void APIENTRY glutAttachMenu(int button); +GLUTAPI void APIENTRY glutDetachMenu(int button); + +/* GLUT window callback sub-API. */ +GLUTAPI void APIENTRY glutDisplayFunc(void (GLUTCALLBACK *func)(void)); +GLUTAPI void APIENTRY glutReshapeFunc(void (GLUTCALLBACK *func)(int width, int height)); +GLUTAPI void APIENTRY glutKeyboardFunc(void (GLUTCALLBACK *func)(unsigned char key, int x, int y)); +GLUTAPI void APIENTRY glutMouseFunc(void (GLUTCALLBACK *func)(int button, int state, int x, int y)); +GLUTAPI void APIENTRY glutMotionFunc(void (GLUTCALLBACK *func)(int x, int y)); +GLUTAPI void APIENTRY glutPassiveMotionFunc(void (GLUTCALLBACK *func)(int x, int y)); +GLUTAPI void APIENTRY glutEntryFunc(void (GLUTCALLBACK *func)(int state)); +GLUTAPI void APIENTRY glutVisibilityFunc(void (GLUTCALLBACK *func)(int state)); +GLUTAPI void APIENTRY glutIdleFunc(void (GLUTCALLBACK *func)(void)); +GLUTAPI void APIENTRY glutTimerFunc(unsigned int millis, void (GLUTCALLBACK *func)(int value), int value); +GLUTAPI void APIENTRY glutMenuStateFunc(void (GLUTCALLBACK *func)(int state)); +#if (GLUT_API_VERSION >= 2) +GLUTAPI void APIENTRY glutSpecialFunc(void (GLUTCALLBACK *func)(int key, int x, int y)); +GLUTAPI void APIENTRY glutSpaceballMotionFunc(void (GLUTCALLBACK *func)(int x, int y, int z)); +GLUTAPI void APIENTRY glutSpaceballRotateFunc(void (GLUTCALLBACK *func)(int x, int y, int z)); +GLUTAPI void APIENTRY glutSpaceballButtonFunc(void (GLUTCALLBACK *func)(int button, int state)); +GLUTAPI void APIENTRY glutButtonBoxFunc(void (GLUTCALLBACK *func)(int button, int state)); +GLUTAPI void APIENTRY glutDialsFunc(void (GLUTCALLBACK *func)(int dial, int value)); +GLUTAPI void APIENTRY glutTabletMotionFunc(void (GLUTCALLBACK *func)(int x, int y)); +GLUTAPI void APIENTRY glutTabletButtonFunc(void (GLUTCALLBACK *func)(int button, int state, int x, int y)); +#if (GLUT_API_VERSION >= 3) +GLUTAPI void APIENTRY glutMenuStatusFunc(void (GLUTCALLBACK *func)(int status, int x, int y)); +GLUTAPI void APIENTRY glutOverlayDisplayFunc(void (GLUTCALLBACK *func)(void)); +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) +GLUTAPI void APIENTRY glutWindowStatusFunc(void (GLUTCALLBACK *func)(int state)); +#endif +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13) +GLUTAPI void APIENTRY glutKeyboardUpFunc(void (GLUTCALLBACK *func)(unsigned char key, int x, int y)); +GLUTAPI void APIENTRY glutSpecialUpFunc(void (GLUTCALLBACK *func)(int key, int x, int y)); +GLUTAPI void APIENTRY glutJoystickFunc(void (GLUTCALLBACK *func)(unsigned int buttonMask, int x, int y, int z), int pollInterval); +#endif +#endif +#endif + +/* GLUT color index sub-API. */ +GLUTAPI void APIENTRY glutSetColor(int, GLfloat red, GLfloat green, GLfloat blue); +GLUTAPI GLfloat APIENTRY glutGetColor(int ndx, int component); +GLUTAPI void APIENTRY glutCopyColormap(int win); + +/* GLUT state retrieval sub-API. */ +GLUTAPI int APIENTRY glutGet(GLenum type); +GLUTAPI int APIENTRY glutDeviceGet(GLenum type); +#if (GLUT_API_VERSION >= 2) +/* GLUT extension support sub-API */ +GLUTAPI int APIENTRY glutExtensionSupported(const char *name); +#endif +#if (GLUT_API_VERSION >= 3) +GLUTAPI int APIENTRY glutGetModifiers(void); +GLUTAPI int APIENTRY glutLayerGet(GLenum type); +#endif + +/* GLUT font sub-API */ +GLUTAPI void APIENTRY glutBitmapCharacter(void *font, int character); +GLUTAPI int APIENTRY glutBitmapWidth(void *font, int character); +GLUTAPI void APIENTRY glutStrokeCharacter(void *font, int character); +GLUTAPI int APIENTRY glutStrokeWidth(void *font, int character); +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) +GLUTAPI int APIENTRY glutBitmapLength(void *font, const unsigned char *string); +GLUTAPI int APIENTRY glutStrokeLength(void *font, const unsigned char *string); +#endif + +/* GLUT pre-built models sub-API */ +GLUTAPI void APIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks); +GLUTAPI void APIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); +GLUTAPI void APIENTRY glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks); +GLUTAPI void APIENTRY glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks); +GLUTAPI void APIENTRY glutWireCube(GLdouble size); +GLUTAPI void APIENTRY glutSolidCube(GLdouble size); +GLUTAPI void APIENTRY glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings); +GLUTAPI void APIENTRY glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings); +GLUTAPI void APIENTRY glutWireDodecahedron(void); +GLUTAPI void APIENTRY glutSolidDodecahedron(void); +GLUTAPI void APIENTRY glutWireTeapot(GLdouble size); +GLUTAPI void APIENTRY glutSolidTeapot(GLdouble size); +GLUTAPI void APIENTRY glutWireOctahedron(void); +GLUTAPI void APIENTRY glutSolidOctahedron(void); +GLUTAPI void APIENTRY glutWireTetrahedron(void); +GLUTAPI void APIENTRY glutSolidTetrahedron(void); +GLUTAPI void APIENTRY glutWireIcosahedron(void); +GLUTAPI void APIENTRY glutSolidIcosahedron(void); + +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9) +/* GLUT video resize sub-API. */ +GLUTAPI int APIENTRY glutVideoResizeGet(GLenum param); +GLUTAPI void APIENTRY glutSetupVideoResizing(void); +GLUTAPI void APIENTRY glutStopVideoResizing(void); +GLUTAPI void APIENTRY glutVideoResize(int x, int y, int width, int height); +GLUTAPI void APIENTRY glutVideoPan(int x, int y, int width, int height); + +/* GLUT debugging sub-API. */ +GLUTAPI void APIENTRY glutReportErrors(void); +#endif + +#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13) +/* GLUT device control sub-API. */ +/* glutSetKeyRepeat modes. */ +#define GLUT_KEY_REPEAT_OFF 0 +#define GLUT_KEY_REPEAT_ON 1 +#define GLUT_KEY_REPEAT_DEFAULT 2 + +/* Joystick button masks. */ +#define GLUT_JOYSTICK_BUTTON_A 1 +#define GLUT_JOYSTICK_BUTTON_B 2 +#define GLUT_JOYSTICK_BUTTON_C 4 +#define GLUT_JOYSTICK_BUTTON_D 8 + +GLUTAPI void APIENTRY glutIgnoreKeyRepeat(int ignore); +GLUTAPI void APIENTRY glutSetKeyRepeat(int repeatMode); +GLUTAPI void APIENTRY glutForceJoystickFunc(void); + +/* GLUT game mode sub-API. */ +/* glutGameModeGet. */ +#define GLUT_GAME_MODE_ACTIVE ((GLenum) 0) +#define GLUT_GAME_MODE_POSSIBLE ((GLenum) 1) +#define GLUT_GAME_MODE_WIDTH ((GLenum) 2) +#define GLUT_GAME_MODE_HEIGHT ((GLenum) 3) +#define GLUT_GAME_MODE_PIXEL_DEPTH ((GLenum) 4) +#define GLUT_GAME_MODE_REFRESH_RATE ((GLenum) 5) +#define GLUT_GAME_MODE_DISPLAY_CHANGED ((GLenum) 6) + +GLUTAPI void APIENTRY glutGameModeString(const char *string); +GLUTAPI int APIENTRY glutEnterGameMode(void); +GLUTAPI void APIENTRY glutLeaveGameMode(void); +GLUTAPI int APIENTRY glutGameModeGet(GLenum mode); +#endif + +#ifdef __cplusplus +} + +#endif + +#ifdef GLUT_APIENTRY_DEFINED +# undef GLUT_APIENTRY_DEFINED +# undef APIENTRY +#endif + +#ifdef GLUT_WINGDIAPI_DEFINED +# undef GLUT_WINGDIAPI_DEFINED +# undef WINGDIAPI +#endif + +#ifdef GLUT_DEFINED___CDECL +# undef GLUT_DEFINED___CDECL +# undef __cdecl +#endif + +#ifdef GLUT_DEFINED__CRTIMP +# undef GLUT_DEFINED__CRTIMP +# undef _CRTIMP +#endif + +#endif /* __glut_h__ */ diff --git a/exchange/exchangesource/Viewer/trackball.cpp b/exchange/exchangesource/Viewer/trackball.cpp new file mode 100644 index 0000000..541158a --- /dev/null +++ b/exchange/exchangesource/Viewer/trackball.cpp @@ -0,0 +1,243 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +/* + * Simple trackball-like motion adapted (ripped off) from projtex.c + * (written by David Yu and David Blythe). See the SIGGRAPH '96 + * Advanced OpenGL course notes. + * + * + * Usage: + * + * o call tbInit() in before any other tb call + * o call tbReshape() from the reshape callback + * o call tbMatrix() to get the trackball matrix rotation + * o call tbStartMotion() to begin trackball movememt + * o call tbStopMotion() to stop trackball movememt + * o call tbMotion() from the motion callback + * o call tbAnimate(GL_TRUE) if you want the trackball to continue + * spinning after the mouse button has been released + * o call tbAnimate(GL_FALSE) if you want the trackball to stop + * spinning after the mouse button has been released + * + * Typical setup: + * + * + void + init(void) + { + tbInit(GLUT_MIDDLE_BUTTON); + tbAnimate(GL_TRUE); + . . . + } + + void + reshape(int width, int height) + { + tbReshape(width, height); + . . . + } + + void + display(void) + { + glPushMatrix(); + + tbMatrix(); + . . . draw the scene . . . + + glPopMatrix(); + } + + void + mouse(int button, int state, int x, int y) + { + tbMouse(button, state, x, y); + . . . + } + + void + motion(int x, int y) + { + tbMotion(x, y); + . . . + } + + int + main(int argc, char** argv) + { + . . . + init(); + glutReshapeFunc(reshape); + glutDisplayFunc(display); + glutMouseFunc(mouse); + glutMotionFunc(motion); + . . . + } + * + * */ + +/* includes */ +#include +#include +#ifdef __APPLE__ +#include +#else +#include +#endif +#include "trackball.h" + + +/* globals */ +static GLuint tb_lasttime; +static GLfloat tb_lastposition[3]; + +static GLfloat tb_angle = 0.0; +static GLfloat tb_axis[3]; +static GLfloat tb_transform[4][4]; + +static GLuint tb_width; +static GLuint tb_height; + +static GLint tb_button = -1; +static GLboolean tb_tracking = GL_FALSE; +static GLboolean tb_animate = GL_TRUE; + + +/* functions */ +static void _tbPointToVector(int x, int y, int width, int height, float v[3]) +{ + float d, a; + + /* project x, y onto a hemi-sphere centered within width, height. */ + v[0] = (2.0 * x - width) / width; + v[1] = (height - 2.0 * y) / height; + d = sqrt(v[0] * v[0] + v[1] * v[1]); + v[2] = cos((3.14159265 / 2.0) * ((d < 1.0) ? d : 1.0)); + a = 1.0 / sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + v[0] *= a; + v[1] *= a; + v[2] *= a; +} + +static void _tbAnimate(void) +{ + glutPostRedisplay(); +} + +void _tbStartMotion(int x, int y, int /*button*/, int time) +{ + assert(tb_button != -1); + + tb_tracking = GL_TRUE; + tb_lasttime = time; + _tbPointToVector(x, y, tb_width, tb_height, tb_lastposition); +} + +void _tbStopMotion(int /*button*/, unsigned time) +{ + assert(tb_button != -1); + + tb_tracking = GL_FALSE; + + if(time == tb_lasttime && tb_animate) { + glutIdleFunc(_tbAnimate); + } else { + tb_angle = 0.0; + if(tb_animate) + glutIdleFunc(0); + } +} + +void tbAnimate(GLboolean animate) +{ + tb_animate = animate; +} + +void tbInit(GLuint button) +{ + tb_button = button; + tb_angle = 0.0; + + /* put the identity in the trackball transform */ + glPushMatrix(); + glLoadIdentity(); + glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *)tb_transform); + glPopMatrix(); +} + +void tbMatrix() +{ + assert(tb_button != -1); + + glPushMatrix(); + glLoadIdentity(); + glRotatef(tb_angle, tb_axis[0], tb_axis[1], tb_axis[2]); + glMultMatrixf((GLfloat *)tb_transform); + glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *)tb_transform); + glPopMatrix(); + + glMultMatrixf((GLfloat *)tb_transform); +} + +void tbReshape(int width, int height) +{ + assert(tb_button != -1); + + tb_width = width; + tb_height = height; +} + +void tbMouse(int button, int state, int x, int y) +{ + assert(tb_button != -1); + + if(state == GLUT_DOWN && button == tb_button) + _tbStartMotion(x, y, button, glutGet(GLUT_ELAPSED_TIME)); + else if(state == GLUT_UP && button == tb_button) + _tbStopMotion(button, glutGet(GLUT_ELAPSED_TIME)); +} + +void tbMotion(int x, int y) +{ + GLfloat current_position[3], dx, dy, dz; + + assert(tb_button != -1); + + if(tb_tracking == GL_FALSE) + return; + + _tbPointToVector(x, y, tb_width, tb_height, current_position); + + /* calculate the angle to rotate by (directly proportional to the + length of the mouse movement */ + dx = current_position[0] - tb_lastposition[0]; + dy = current_position[1] - tb_lastposition[1]; + dz = current_position[2] - tb_lastposition[2]; + tb_angle = 90.0 * sqrt(dx * dx + dy * dy + dz * dz); + + /* calculate the axis of rotation (cross product) */ + tb_axis[0] = tb_lastposition[1] * current_position[2] - + tb_lastposition[2] * current_position[1]; + tb_axis[1] = tb_lastposition[2] * current_position[0] - + tb_lastposition[0] * current_position[2]; + tb_axis[2] = tb_lastposition[0] * current_position[1] - + tb_lastposition[1] * current_position[0]; + + /* reset for next time */ + tb_lasttime = glutGet(GLUT_ELAPSED_TIME); + tb_lastposition[0] = current_position[0]; + tb_lastposition[1] = current_position[1]; + tb_lastposition[2] = current_position[2]; + + /* remember to draw new position */ + glutPostRedisplay(); +} diff --git a/exchange/exchangesource/Viewer/trackball.h b/exchange/exchangesource/Viewer/trackball.h new file mode 100644 index 0000000..655d4dd --- /dev/null +++ b/exchange/exchangesource/Viewer/trackball.h @@ -0,0 +1,100 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +/* + * Simple trackball-like motion adapted (ripped off) from projtex.c + * (written by David Yu and David Blythe). See the SIGGRAPH '96 + * Advanced OpenGL course notes. + * + * + * Usage: + * + * o call gltbInit() in before any other gltb call + * o call gltbReshape() from the reshape callback + * o call gltbMatrix() to get the trackball matrix rotation + * o call gltbStartMotion() to begin trackball movememt + * o call gltbStopMotion() to stop trackball movememt + * o call gltbMotion() from the motion callback + * o call gltbAnimate(GL_TRUE) if you want the trackball to continue + * spinning after the mouse button has been released + * o call gltbAnimate(GL_FALSE) if you want the trackball to stop + * spinning after the mouse button has been released + * + * Typical setup: + * + * + void + init(void) + { + gltbInit(GLUT_MIDDLE_BUTTON); + gltbAnimate(GL_TRUE); + . . . + } + + void + reshape(int width, int height) + { + gltbReshape(width, height); + . . . + } + + void + display(void) + { + glPushMatrix(); + + gltbMatrix(); + . . . draw the scene . . . + + glPopMatrix(); + } + + void + mouse(int button, int state, int x, int y) + { + gltbMouse(button, state, x, y); + . . . + } + + void + motion(int x, int y) + { + gltbMotion(x, y); + . . . + } + + int + main(int argc, char** argv) + { + . . . + init(); + glutReshapeFunc(reshape); + glutDisplayFunc(display); + glutMouseFunc(mouse); + glutMotionFunc(motion); + . . . + } + ***/ + + + /* functions */ + void tbInit(GLuint button); + + void tbMatrix(void); + + void tbReshape(int width, int height); + + void tbMouse(int button, int state, int x, int y); + + void tbMotion(int x, int y); + + void tbAnimate(GLboolean animate); + diff --git a/exchange/exchangesource/Viewer/traverse/BrepTraverse.cpp b/exchange/exchangesource/Viewer/traverse/BrepTraverse.cpp new file mode 100644 index 0000000..8281a7b --- /dev/null +++ b/exchange/exchangesource/Viewer/traverse/BrepTraverse.cpp @@ -0,0 +1,312 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file BrepTraverse.cpp +This file demonstrates how to programmatically traverse the Brep structure + +***********************************************************************************************************************/ + +#include "../VisitorContainer.h" +#include "../BrepTraverse.h" +#include + + +////////////////////////////////////////////////////////////////////////////// +// Traverse Brep +////////////////////////////////////////////////////////////////////////////// + +A3DBrepDataConnector::A3DBrepDataConnector(const A3DTopoBrepData *pBrep) : A3DConnector(pBrep) +{ + A3D_INITIALIZE_DATA(A3DTopoBrepDataData, m_sBrepData); + CALL_A3D_FCTION(A3DTopoBrepDataGet,(pBrep, &m_sBrepData)); +} + +A3DBrepDataConnector::~A3DBrepDataConnector() +{ + CALL_A3D_FCTION(A3DTopoBrepDataGet,(NULL, &m_sBrepData)); +} + +A3DStatus A3DBrepDataConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + + //TopoContext + A3DTopoBody *psTopoBody = (A3DTopoBody*)GetA3DEntity(); + A3DTopoBodyData sA3DTopoBodyData; + A3D_INITIALIZE_DATA(A3DTopoBodyData, sA3DTopoBodyData); + CHECK_RET_CALL_A3D_FCTION(A3DTopoBodyGet,(psTopoBody, &sA3DTopoBodyData)); + A3DTopoContext* psContext = sA3DTopoBodyData.m_pContext; + + A3DTopoContextData sA3DTopoContextData; + A3D_INITIALIZE_DATA(A3DTopoContextData, sA3DTopoContextData); + CHECK_RET_CALL_A3D_FCTION(A3DTopoContextGet,(psContext, &sA3DTopoContextData)); + //m_dScale = sA3DTopoContextData.m_dScale; + + CHECK_RET(psVisitor->visitEnter(*this)); + A3DUns32 uNbConnex = m_sBrepData.m_uiConnexSize; + for (A3DUns32 uI = 0; uI < uNbConnex; uI++) + { + A3DConnexConnector sConnecConnector(m_sBrepData.m_ppConnexes[uI]); + CHECK_RET(sConnecConnector.Traverse(psVisitor)); + } + + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////// +// Connex +////////////////////////////////////////////////////////////////////////////// + +A3DConnexConnector::A3DConnexConnector(const A3DTopoConnex *pConnex) : A3DConnector(pConnex) +{ + A3D_INITIALIZE_DATA(A3DTopoConnexData, m_sConnexData); + CALL_A3D_FCTION(A3DTopoConnexGet,(pConnex, &m_sConnexData)); +} + +A3DConnexConnector::~A3DConnexConnector() +{ + CALL_A3D_FCTION(A3DTopoConnexGet,(NULL, &m_sConnexData)); +} + +A3DStatus A3DConnexConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned uI, uNbShell = m_sConnexData.m_uiShellSize; + for (uI = 0; uI < uNbShell; uI++) + { + A3DShellConnector sShellConnector(m_sConnexData.m_ppShells[uI]); + CHECK_RET(sShellConnector.Traverse(psVisitor)); + } + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////// +// Shell +////////////////////////////////////////////////////////////////////////////// + +A3DShellConnector::A3DShellConnector(const A3DTopoShell *pShell) : A3DConnector(pShell) +{ + A3D_INITIALIZE_DATA(A3DTopoShellData, m_sShellData); + CALL_A3D_FCTION(A3DTopoShellGet,(pShell, &m_sShellData)); +} + +A3DShellConnector::~A3DShellConnector() +{ + CALL_A3D_FCTION(A3DTopoShellGet,(NULL, &m_sShellData)); +} + +A3DStatus A3DShellConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned int uI, uFaceSize = m_sShellData.m_uiFaceSize; + for (uI = 0; uI < uFaceSize; uI++) + { + A3DFaceConnector sFaceConnector(m_sShellData.m_ppFaces[uI]); + CHECK_RET(sFaceConnector.Traverse(psVisitor)); + } + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////// +// Face +////////////////////////////////////////////////////////////////////////////// + +A3DFaceConnector::A3DFaceConnector(const A3DTopoFace* pFace) : A3DConnector(pFace) +{ + A3D_INITIALIZE_DATA(A3DTopoFaceData, m_sFaceData); + CALL_A3D_FCTION(A3DTopoFaceGet,(pFace, &m_sFaceData)); +} + +A3DFaceConnector::~A3DFaceConnector() +{ + CALL_A3D_FCTION(A3DTopoFaceGet,(NULL, &m_sFaceData)); +} + +A3DStatus A3DFaceConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned int uI, uLoopSize = m_sFaceData.m_uiLoopSize; + for (uI = 0; uI < uLoopSize; uI++) + { + A3DLoopConnector sLoopConnector(m_sFaceData.m_ppLoops[uI]); + CHECK_RET(sLoopConnector.Traverse(psVisitor)); + } + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////// +// Loop +////////////////////////////////////////////////////////////////////////////// + +A3DLoopConnector::A3DLoopConnector(const A3DTopoLoop *pLoop) : A3DConnector(pLoop) +{ + A3D_INITIALIZE_DATA(A3DTopoLoopData, m_sLoopData); + CALL_A3D_FCTION(A3DTopoLoopGet,(pLoop, &m_sLoopData)); +} + +A3DLoopConnector::~A3DLoopConnector() +{ + CALL_A3D_FCTION(A3DTopoLoopGet,(NULL, &m_sLoopData)); +} + +A3DStatus A3DLoopConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + unsigned uI, uCoEdgeSize = m_sLoopData.m_uiCoEdgeSize; + for (uI = 0; uI < uCoEdgeSize; uI++) + { + A3DCoEdgeConnector sCoEdgeConnector(m_sLoopData.m_ppCoEdges[uI]); + CHECK_RET(sCoEdgeConnector.Traverse(psVisitor)); + } + + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////// +// CoEdge +////////////////////////////////////////////////////////////////////////////// + +A3DCoEdgeConnector::A3DCoEdgeConnector(const A3DTopoCoEdge *pCoEdge) : A3DConnector(pCoEdge) +{ + A3D_INITIALIZE_DATA(A3DTopoCoEdgeData, m_sCoEdgeData); + CALL_A3D_FCTION(A3DTopoCoEdgeGet,(pCoEdge, &m_sCoEdgeData)); +} + +A3DCoEdgeConnector::~A3DCoEdgeConnector() +{ + CALL_A3D_FCTION(A3DTopoCoEdgeGet,(NULL, &m_sCoEdgeData)); +} + +A3DStatus A3DCoEdgeConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + if (!(psVisitor->FindInMap(m_sCoEdgeData.m_pEdge))) + { + psVisitor->SetInMap(m_sCoEdgeData.m_pEdge, (void*) this->GetA3DEntity()); + A3DEdgeConnector sEdgeConnector(m_sCoEdgeData.m_pEdge); + CHECK_RET(sEdgeConnector.Traverse(psVisitor)); + } + CHECK_RET(psVisitor->visitLeave(*this)); + + return A3D_SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////// +// Edge +////////////////////////////////////////////////////////////////////////////// + +A3DEdgeConnector::A3DEdgeConnector(const A3DTopoEdge *pEdge) + : A3DConnector(pEdge) +{ + A3D_INITIALIZE_DATA(A3DTopoEdgeData, m_sEdgeData); + CALL_A3D_FCTION(A3DTopoEdgeGet,(pEdge, &m_sEdgeData)); +} + +A3DEdgeConnector::~A3DEdgeConnector() +{ + CALL_A3D_FCTION(A3DTopoEdgeGet,(NULL, &m_sEdgeData)); +} + +A3DStatus A3DEdgeConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + A3DEEntityType eType; + //Start Vertex + if (m_sEdgeData.m_pStartVertex != NULL) + { + CHECK_RET_CALL_A3D_FCTION(A3DEntityGetType,(m_sEdgeData.m_pStartVertex,&eType)); + if (eType == kA3DTypeTopoMultipleVertex) + { + A3DMultipleVertexConnector sStart(m_sEdgeData.m_pStartVertex); + sStart.Traverse(psVisitor); + } + else if (eType == kA3DTypeTopoUniqueVertex) + { + A3DUniqueVertexConnector sStart(m_sEdgeData.m_pStartVertex); + sStart.Traverse(psVisitor); + } + } + + //End Vertex + if (m_sEdgeData.m_pEndVertex != NULL) + { + CHECK_RET_CALL_A3D_FCTION(A3DEntityGetType,(m_sEdgeData.m_pEndVertex,&eType)); + if (eType == kA3DTypeTopoMultipleVertex) + { + A3DMultipleVertexConnector sStart(m_sEdgeData.m_pEndVertex); + sStart.Traverse(psVisitor); + } + else if (eType == kA3DTypeTopoUniqueVertex) + { + A3DUniqueVertexConnector sStart(m_sEdgeData.m_pEndVertex); + sStart.Traverse(psVisitor); + } + } + + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +////////////////////////////////////////////////////////////////////////////// +// Vertex +////////////////////////////////////////////////////////////////////////////// + +A3DUniqueVertexConnector::A3DUniqueVertexConnector(const A3DTopoVertex *pVertex) + : A3DConnector(pVertex) +{ + A3D_INITIALIZE_DATA(A3DTopoUniqueVertexData, m_sVertexData); + CALL_A3D_FCTION(A3DTopoUniqueVertexGet,(pVertex, &m_sVertexData)); +} + +A3DUniqueVertexConnector::~A3DUniqueVertexConnector() +{ + CALL_A3D_FCTION(A3DTopoUniqueVertexGet,(NULL, &m_sVertexData)); +} + +A3DStatus A3DUniqueVertexConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + return A3D_SUCCESS; +} + + +A3DMultipleVertexConnector::A3DMultipleVertexConnector(const A3DTopoVertex *pVertex) : A3DConnector(pVertex) +{ + A3D_INITIALIZE_DATA(A3DTopoMultipleVertexData, m_sVertexData); + CALL_A3D_FCTION(A3DTopoMultipleVertexGet,(pVertex, &m_sVertexData)); +} + +A3DMultipleVertexConnector::~A3DMultipleVertexConnector() +{ + CALL_A3D_FCTION(A3DTopoMultipleVertexGet,(NULL, &m_sVertexData)); +} + +A3DStatus A3DMultipleVertexConnector::Traverse(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + return A3D_SUCCESS; +} diff --git a/exchange/exchangesource/Viewer/traverse/CascadedAttributeConnector.cpp b/exchange/exchangesource/Viewer/traverse/CascadedAttributeConnector.cpp new file mode 100644 index 0000000..10cdccc --- /dev/null +++ b/exchange/exchangesource/Viewer/traverse/CascadedAttributeConnector.cpp @@ -0,0 +1,213 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "../CascadedAttributeConnector.h" +#include "../Visitors.h" + +ColorMaterialsConnector::ColorMaterialsConnector(A3DMiscCascadedAttributes* pAttr) : A3DConnector(pAttr) +{ + A3D_INITIALIZE_DATA(A3DMiscCascadedAttributesData, m_sCascadedAttributeData); + CALL_A3D_FCTION(A3DMiscCascadedAttributesGet,(pAttr, &(m_sCascadedAttributeData))); +} + +ColorMaterialsConnector::~ColorMaterialsConnector() +{ + CALL_A3D_FCTION(A3DMiscCascadedAttributesGet,(NULL, &(m_sCascadedAttributeData))); +} + + +bool ColorMaterialsConnector::IsShow() +{ + return m_sCascadedAttributeData.m_bShow ? true : false; +} + +bool ColorMaterialsConnector::IsRemoved() +{ + return m_sCascadedAttributeData.m_bRemoved ? true : false; +} + +bool ColorMaterialsConnector::IsMaterial() +{ + //Todo Test it's not a texture + return m_sCascadedAttributeData.m_sStyle.m_bMaterial ? true : false; +} + +bool ColorMaterialsConnector::IsRGBColor() +{ + return !(IsMaterial()); +} + +bool ColorMaterialsConnector::IsTranparent() +{ + return m_sCascadedAttributeData.m_sStyle.m_bIsTransparencyDefined ? true : false; +} + +A3DStatus ColorMaterialsConnector::GetRGB(double adRGB[3])//, char& cInheritance = 0) +{ + A3DStatus iRet = A3D_SUCCESS; + A3DGraphRgbColorData sA3DGraphRgbColorData; + A3D_INITIALIZE_DATA(A3DGraphRgbColorData, sA3DGraphRgbColorData); + if(CALL_A3D_FCTION(A3DGlobalGetGraphRgbColorData,(m_sCascadedAttributeData.m_sStyle.m_uiRgbColorIndex, &sA3DGraphRgbColorData)) == A3D_DEFAULT_COLOR) + { + adRGB[0] = 192.0 / 255.0; + adRGB[1] = 192.0 / 255.0; + adRGB[2] = 192.0 / 255.0; + } + else + { + CHECK_RET(iRet); + adRGB[0] = sA3DGraphRgbColorData.m_dRed; + adRGB[1] = sA3DGraphRgbColorData.m_dGreen; + adRGB[2] = sA3DGraphRgbColorData.m_dBlue; + } + + return A3D_SUCCESS; +} + +A3DStatus ColorMaterialsConnector::Transparency(unsigned char& cTransparenty) +{ + cTransparenty = m_sCascadedAttributeData.m_sStyle.m_ucTransparency; + return A3D_SUCCESS; +} + +A3DStatus ColorMaterialsConnector::Compare( + ColorMaterialsConnector const & sOtherCascadedAttribute, + bool& bSameDispalyParameter, + bool& bSamebSameDispalyParameterOnFace) +{ + if ( + sOtherCascadedAttribute.m_sCascadedAttributeData.m_bShow != m_sCascadedAttributeData.m_bShow + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_bRemoved != m_sCascadedAttributeData.m_bRemoved + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_usLayer != m_sCascadedAttributeData.m_usLayer + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_dWidth != m_sCascadedAttributeData.m_sStyle.m_dWidth + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_bVPicture != m_sCascadedAttributeData.m_sStyle.m_bVPicture + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_uiLinePatternIndex != m_sCascadedAttributeData.m_sStyle.m_uiLinePatternIndex + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_bMaterial != m_sCascadedAttributeData.m_sStyle.m_bMaterial + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_uiRgbColorIndex != m_sCascadedAttributeData.m_sStyle.m_uiRgbColorIndex + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_bIsTransparencyDefined != m_sCascadedAttributeData.m_sStyle.m_bIsTransparencyDefined + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_ucTransparency != m_sCascadedAttributeData.m_sStyle.m_ucTransparency + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_bSpecialCulling != m_sCascadedAttributeData.m_sStyle.m_bSpecialCulling + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_bFrontCulling != m_sCascadedAttributeData.m_sStyle.m_bFrontCulling + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_bBackCulling != m_sCascadedAttributeData.m_sStyle.m_bBackCulling + || sOtherCascadedAttribute.m_sCascadedAttributeData.m_sStyle.m_bNoLight != m_sCascadedAttributeData.m_sStyle.m_bNoLight) + + bSameDispalyParameter = bSamebSameDispalyParameterOnFace = false; + else + bSameDispalyParameter = true; + + return A3D_SUCCESS; +} + +int ColorMaterialsConnector::GetMaterial(double dEmmisive[4], + double dDiffuse[4], + double dAmbient[4], + double dSpecular[4], + double& dShininess) +{ + int iRet = eBAD_Diffuse + eBAD_Emissive + eBAD_Specular + eBAD_Ambient; + A3DStatus iErr = A3D_SUCCESS; + A3DGraphMaterialData sMaterialData; + + memset(dEmmisive, 0, sizeof(double) * 4); + memset(dDiffuse, 0, sizeof(double) * 4); + memset(dAmbient, 0, sizeof(double) * 4); + memset(dSpecular, 0, sizeof(double) * 4); + dShininess = 0; + + A3D_INITIALIZE_DATA(A3DGraphMaterialData, sMaterialData); + iErr = CALL_A3D_FCTION(A3DGlobalGetGraphMaterialData,(m_sCascadedAttributeData.m_sStyle.m_uiRgbColorIndex, &sMaterialData)); + if (iErr == A3D_SUCCESS) + { + iRet = 0; + A3DGraphRgbColorData sColorData; + A3D_INITIALIZE_DATA(A3DGraphRgbColorData, sColorData); + + if (sMaterialData.m_uiDiffuse != A3D_DEFAULT_COLOR_INDEX) + { + CALL_A3D_FCTION(A3DGlobalGetGraphRgbColorData,(sMaterialData.m_uiDiffuse, &sColorData)); + + dDiffuse[0] = sColorData.m_dRed; + dDiffuse[1] = sColorData.m_dGreen; + dDiffuse[2] = sColorData.m_dBlue; + if (m_sCascadedAttributeData.m_sStyle.m_bIsTransparencyDefined) + { + dDiffuse[3] = (double)(m_sCascadedAttributeData.m_sStyle.m_ucTransparency) / 255.0; + } + else + { + dDiffuse[3] = 1.0; + } + } + else + iRet |= eBAD_Diffuse; + + if (sMaterialData.m_uiEmissive != A3D_DEFAULT_COLOR_INDEX) + { + CALL_A3D_FCTION(A3DGlobalGetGraphRgbColorData,(sMaterialData.m_uiEmissive, &sColorData)); + dEmmisive[0] = sColorData.m_dRed; + dEmmisive[1] = sColorData.m_dGreen; + dEmmisive[2] = sColorData.m_dBlue; + if (m_sCascadedAttributeData.m_sStyle.m_bIsTransparencyDefined) + { + dEmmisive[3] = sMaterialData.m_dEmissiveAlpha; + } + else + { + dEmmisive[3] = 1.0; + } + } + else + iRet |= eBAD_Emissive; + + + dShininess = sMaterialData.m_dShininess; + + if (sMaterialData.m_uiSpecular != A3D_DEFAULT_COLOR_INDEX) + { + CALL_A3D_FCTION(A3DGlobalGetGraphRgbColorData,(sMaterialData.m_uiSpecular, &sColorData)); + + dSpecular[0] = sColorData.m_dRed; + dSpecular[1] = sColorData.m_dGreen; + dSpecular[2] = sColorData.m_dBlue; + if (m_sCascadedAttributeData.m_sStyle.m_bIsTransparencyDefined) + { + dSpecular[3] = sMaterialData.m_dSpecularAlpha; + } + else + { + dSpecular[3] = 1.0; + } + } + else + iRet |= eBAD_Specular; + + if (sMaterialData.m_uiAmbient != A3D_DEFAULT_COLOR_INDEX) + { + CALL_A3D_FCTION(A3DGlobalGetGraphRgbColorData,(sMaterialData.m_uiAmbient, &sColorData)); + + dAmbient[0] = sColorData.m_dRed; + dAmbient[1] = sColorData.m_dGreen; + dAmbient[2] = sColorData.m_dBlue; + if (m_sCascadedAttributeData.m_sStyle.m_bIsTransparencyDefined) + { + dAmbient[3] = sMaterialData.m_dAmbientAlpha; + } + else + { + dAmbient[3] = 1.0; + } + } + else + iRet |= eBAD_Ambient; + } + return iRet; +} + diff --git a/exchange/exchangesource/Viewer/traverse/MarkupTessConnector.cpp b/exchange/exchangesource/Viewer/traverse/MarkupTessConnector.cpp new file mode 100644 index 0000000..9eed41f --- /dev/null +++ b/exchange/exchangesource/Viewer/traverse/MarkupTessConnector.cpp @@ -0,0 +1,644 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file MarkupConnector.cpp + +This file provides tools to get the visual representation of markup + +***********************************************************************************************************************/ + +#include "../MarkupTessConnector.h" +#include "../Visitors.h" +#include +#include "../Matrix.h" + +#define DEFAULT_OFFSET {\ + pData += *(puiStart+1); \ + puiStart += (uiCount + 1); \ + } +#define MAKE_OFFSET(CountInt, CountFloats) {\ + pData += CountFloats; \ + puiStart += (CountInt + 1); \ + } + +A3DMarkupTessDataConnectorCreator::A3DMarkupTessDataConnectorCreator(std::vector& a_rvMkpTessConnector) + : m_bStartToDrawSet(false), m_bFaceViewActivated(false), m_bFramedrawActivated(false), m_bFixedSizeActivated(false), + m_rvMarkupTessData(a_rvMkpTessConnector) +{ + m_rvMarkupTessData.push_back(new A3DMarkupTessConnector()); + + //Set Indentity On Matrix + memset(&m_adCurrentWorldMatrix[0], 0, sizeof(double) * 16); + m_adCurrentWorldMatrix[0] = m_adCurrentWorldMatrix[5] = m_adCurrentWorldMatrix[10] = m_adCurrentWorldMatrix[15] = 1; + m_adPushedWorldMatrices.resize(16); + memcpy(&m_adPushedWorldMatrices[0], m_adCurrentWorldMatrix, sizeof(double) * 16); + +} + +A3DMarkupTessDataConnectorCreator::~A3DMarkupTessDataConnectorCreator() +{ +} + +A3DStatus A3DMarkupTessDataConnectorCreator::pushMatrix(const double* a_pdLocalMatrix) +{ + size_t uSize = m_adPushedWorldMatrices.size(); + if (uSize < 16) + return A3D_ERROR; + m_adPushedWorldMatrices.resize(uSize + 16); + + MultiplyMatrix(&m_adCurrentWorldMatrix[0], a_pdLocalMatrix, &m_adPushedWorldMatrices[uSize]); + memcpy(&m_adCurrentWorldMatrix[0], &m_adPushedWorldMatrices[uSize], sizeof(double) * 16); + return A3D_SUCCESS; +} + +A3DStatus A3DMarkupTessDataConnectorCreator::popMatrix() +{ + size_t uSize = m_adPushedWorldMatrices.size() - 16; + m_adPushedWorldMatrices.resize(uSize); + memcpy(&m_adCurrentWorldMatrix[0], &m_adPushedWorldMatrices[uSize - 16], sizeof(double) * 16); + return A3D_SUCCESS; +} + +A3DMarkupTessConnector& A3DMarkupTessDataConnectorCreator::GetMarkupTessConnector(const double* pdMatrix) +{ + bool bSameMatrix = true; + size_t uI, uSize = m_rvMarkupTessData.size(); + + for (uI = 0; uI < 16; uI++) + { + if (m_adCurrentWorldMatrix[uI] != pdMatrix[uI]) + { + bSameMatrix = false; + break; + } + } + if (!bSameMatrix/* && m_bStartToDrawSet*/) + { + m_rvMarkupTessData.push_back(new A3DMarkupTessConnector(*m_rvMarkupTessData[uSize - 1])); + m_bStartToDrawSet = false; + uSize++; + } + return *m_rvMarkupTessData[uSize - 1]; +} + + +A3DMarkupTessConnector& A3DMarkupTessDataConnectorCreator::GetMarkupTessConnector(unsigned uiExtraDataValue, bool& bCameraDependant) +{ + size_t uSize = m_rvMarkupTessData.size(); + + bCameraDependant = false; + m_bStartToDrawSet = m_rvMarkupTessData.back()->HasAlreadySomethingToDisplay(); + switch (uiExtraDataValue) + { + case A3D_DECODE_EXTRA_DATA(kA3DMarkupFaceViewMask): // 6 : Camera Dependant - Faceview + m_bFaceViewActivated = !m_bFaceViewActivated; + case A3D_DECODE_EXTRA_DATA(kA3DMarkupFrameDrawMask): // 7 : CameraDependant - Frame draw + m_bFramedrawActivated = !m_bFramedrawActivated; + case A3D_DECODE_EXTRA_DATA(kA3DMarkupFixedSizeMask): // 8 : CameraDependant - Fixedsize + m_bFixedSizeActivated = !m_bFixedSizeActivated; + case A3D_DECODE_EXTRA_DATA(kA3DMarkupSymbolMask): // 9 : Camera Dependant - Symbol + case A3D_DECODE_EXTRA_DATA(kA3DMarkupColorMask): // 11 : color + case A3D_DECODE_EXTRA_DATA(kA3DMarkupLineStippleMask): // 12 : line stipple + case A3D_DECODE_EXTRA_DATA(kA3DMarkupLineWidthMask): // 17 : line width + case 0: // polyline + case A3D_DECODE_EXTRA_DATA(kA3DMarkupTrianglesMask): // 2 : triangles + case A3D_DECODE_EXTRA_DATA(kA3DMarkupCylinderMask): // 10 : cylinder + case A3D_DECODE_EXTRA_DATA(kA3DMarkupFontMask): // 13 : font + case A3D_DECODE_EXTRA_DATA(kA3DMarkupTextMask): // 14 : text + case A3D_DECODE_EXTRA_DATA(kA3DMarkupPointsMask): // 15 : points + case A3D_DECODE_EXTRA_DATA(kA3DMarkupPolygonMask): // 16 : polygon + { + if (m_bStartToDrawSet) + { + A3DMarkupTessConnector *pNewConnector = new A3DMarkupTessConnector(*m_rvMarkupTessData[uSize - 1]); + m_rvMarkupTessData.push_back(pNewConnector); + uSize++; + m_bStartToDrawSet = false; + memcpy(&(pNewConnector->m_adWorldMatrix[0]), + &m_adCurrentWorldMatrix[0], + sizeof(double) * 16); + } + } + break; + } + if (m_bFaceViewActivated || m_bFramedrawActivated || m_bFixedSizeActivated) + bCameraDependant = true; + + + return *m_rvMarkupTessData[uSize - 1]; +} + +/******************************************************************************************************************** + + A3DMarkupTessConnector + + *********************************************************************************************************************/ +A3DMarkupTessConnector::A3DMarkupTessConnector() : m_bFaceView(false), m_bFrameDraw(false), m_bSymbol(false), m_bFixedSize(false), +m_bIsText(false), m_uiFixedSizePatternIndex(0), m_iGraphStyleIndexLinsStyle(-1), m_dLineWidth(1.0), m_iGraphVPicturePatternIndex(-1) +{ + memset(m_adViewDependantParameter, 0, sizeof(m_adViewDependantParameter)); + memset(m_adWorldMatrix, 0, sizeof(m_adWorldMatrix)); + m_adWorldMatrix[0] = m_adWorldMatrix[5] = m_adWorldMatrix[10] = m_adWorldMatrix[15] = 1.; + memcpy(&m_adModelMatrix[0], &m_adWorldMatrix[0], sizeof(double) * 16); + memcpy(&m_adProjMatrix[0], &m_adWorldMatrix[0], sizeof(double) * 16); + m_adRGB[0] = m_adRGB[1] = m_adRGB[2] = -1.0; +} + +A3DMarkupTessConnector::A3DMarkupTessConnector(A3DMarkupTessConnector& a_PreviousTessConnector) +{ + m_bFaceView = a_PreviousTessConnector.m_bFaceView; + m_bFrameDraw = a_PreviousTessConnector.m_bFrameDraw; + m_bSymbol = a_PreviousTessConnector.m_bSymbol; + m_bFixedSize = a_PreviousTessConnector.m_bFixedSize; + + m_bIsText = a_PreviousTessConnector.m_bIsText; + memcpy(m_adViewDependantParameter, a_PreviousTessConnector.m_adViewDependantParameter, sizeof(m_adViewDependantParameter)); + m_uiFixedSizePatternIndex = a_PreviousTessConnector.m_uiFixedSizePatternIndex; + + m_ucBehaviour = a_PreviousTessConnector.m_ucBehaviour; + + //Graphic + memcpy(m_adRGB, a_PreviousTessConnector.m_adRGB, sizeof(m_adRGB)); + m_dLineWidth = a_PreviousTessConnector.m_dLineWidth; + m_iGraphStyleIndexLinsStyle = a_PreviousTessConnector.m_iGraphStyleIndexLinsStyle; + m_iGraphVPicturePatternIndex = a_PreviousTessConnector.m_iGraphVPicturePatternIndex; + +} + +A3DMarkupTessConnector::~A3DMarkupTessConnector() +{ + std::vector::iterator itCur = m_apTexts.begin(); + std::vector::iterator itEnd = m_apTexts.end(); + for (; itCur < itEnd; ++itCur) + { + delete *itCur; + } +} + +#define SIZE_ARROW 15.0 +A3DStatus A3DMarkupTessConnector::GetMarkupTessellation(const A3DTessBaseData& sTessBaseData, + const A3DTessMarkupData* pTessMarkupData, + const bool bIsText, + std::vector& asMarkupTessDataConnector, + double a_dParallelToScreenPMIScale) +{ + A3DMarkupTessDataConnectorCreator sMarkupTessDataConnectorCreator(asMarkupTessDataConnector); + A3DStatus iRet = A3D_SUCCESS; + float afDefaultcolor[3]; + afDefaultcolor[0] = afDefaultcolor[1] = afDefaultcolor[2] = 0.; + + bool bIsScreenMarkupZoomable = true; + unsigned int kSize; + unsigned int uiCount = 0; + + A3DGraphRgbColorData sRgbColorData; + A3D_INITIALIZE_DATA(A3DGraphRgbColorData, sRgbColorData); + A3DGraphStyleData sGraphStyleData; + A3D_INITIALIZE_DATA(A3DGraphStyleData, sGraphStyleData); + + A3DGraphPictureData sPictureData; + A3D_INITIALIZE_DATA(A3DGraphPictureData, sPictureData); + + A3DFontKeyData sFontKeyData; + A3D_INITIALIZE_DATA(A3DFontKeyData, sFontKeyData); + + bIsScreenMarkupZoomable = (pTessMarkupData->m_cBehaviour & kA3DMarkupIsZoomable) != 0; + const A3DDouble* pData = sTessBaseData.m_pdCoords; + const A3DUns32* puiStart = &pTessMarkupData->m_puiCodes[0]; + const A3DUns32* puiEnd = &pTessMarkupData->m_puiCodes[pTessMarkupData->m_uiCodesSize - 1]; + + bool bShow = false; + if ((pData != NULL) && (puiStart != NULL) && (puiEnd != NULL)) for (; puiStart < puiEnd; puiStart++) + { + uiCount = *puiStart & kA3DMarkupIntegerMask; + bShow = true; + + if (*puiStart & kA3DMarkupIsExtraData) + { + A3DUns32 uiExtraDataValue = A3D_DECODE_EXTRA_DATA(*puiStart); + bool bCameraDependant; + A3DMarkupTessConnector& sCurMarkupTessConnector = + sMarkupTessDataConnectorCreator.GetMarkupTessConnector(uiExtraDataValue, bCameraDependant); + sCurMarkupTessConnector.m_ucBehaviour = pTessMarkupData->m_cBehaviour; + switch (uiExtraDataValue) + { + case A3D_DECODE_EXTRA_DATA(kA3DMarkupTrianglesMask): // 2 : // triangles + { + kSize = *(puiStart + 1);// number of triangles * 9 + unsigned int uI; + for (uI = 0; uI < kSize; uI++) + sCurMarkupTessConnector.m_adTriangleList.push_back(*(pData + uI)); + DEFAULT_OFFSET; + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupFaceViewMask): // 6 : // Camera Dependant - Face view + // Using by circle center/fastener/measurement point/spot welding + // geometrical symbol zoomable + { + if (*(puiStart + 1) > 0) + { + sCurMarkupTessConnector.m_bFaceView = true; + sCurMarkupTessConnector.m_adViewDependantParameter[0] = *pData; + sCurMarkupTessConnector.m_adViewDependantParameter[1] = *(pData + 1); + sCurMarkupTessConnector.m_adViewDependantParameter[2] = *(pData + 2); + MAKE_OFFSET(0, 3) + } + else + { + if (!(sMarkupTessDataConnectorCreator.HasStartToDrawSet())) + sCurMarkupTessConnector.m_bFaceView = false; + MAKE_OFFSET(0, 0); + } + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupFrameDrawMask): // 7 : // CameraDependant - Frame draw + // Usually used for non-zoomable text, but it is possible to change to zoomable (option on CatiaV5) + { + if (*(puiStart + 1) > 0) + { + sCurMarkupTessConnector.m_bFrameDraw = true; + sCurMarkupTessConnector.m_adViewDependantParameter[0] = *pData; + sCurMarkupTessConnector.m_adViewDependantParameter[1] = *(pData + 1); + sCurMarkupTessConnector.m_adViewDependantParameter[2] = /*bIsText ? 0 : */*(pData + 2); + sCurMarkupTessConnector.m_bIsText = bIsText; + MAKE_OFFSET(0, 3) + } + else + { + if (!(sMarkupTessDataConnectorCreator.HasStartToDrawSet())) + sCurMarkupTessConnector.m_bFrameDraw = false; + MAKE_OFFSET(0, 0) + } + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupFixedSizeMask): // 8 : // CameraDependant - Fixedsize + { + if (*(puiStart + 1) > 0) + { + sCurMarkupTessConnector.m_bFixedSize = true; + sCurMarkupTessConnector.m_adViewDependantParameter[0] = *pData; + sCurMarkupTessConnector.m_adViewDependantParameter[1] = *(pData + 1); + sCurMarkupTessConnector.m_adViewDependantParameter[2] = /*bIsText ? 0 : */*(pData + 2); + sCurMarkupTessConnector.m_uiFixedSizePatternIndex = *(puiStart + 2); + MAKE_OFFSET(0, 3); + } + else + { + if (!(sMarkupTessDataConnectorCreator.HasStartToDrawSet())) + sCurMarkupTessConnector.m_bFixedSize = false; + MAKE_OFFSET(0, 0) + } + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupSymbolMask): // 9 : // Camera Dependant - Symbol + { + sCurMarkupTessConnector.m_bSymbol = true; + sCurMarkupTessConnector.m_adViewDependantParameter[0] = *pData; + sCurMarkupTessConnector.m_adViewDependantParameter[1] = *(pData + 1); + sCurMarkupTessConnector.m_adViewDependantParameter[2] = /*bIsText ? 0 : */*(pData + 2); + //unsigned int uiPatternIndex = *(puiStart+2); + DEFAULT_OFFSET + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupCylinderMask): // 10 : cylinder + { + double dRadiusBase = *pData; + double dRadiusTop = *(pData + 1); + double dHeight = *(pData + 2); + sCurMarkupTessConnector.m_adCylinder.push_back(dRadiusBase); + sCurMarkupTessConnector.m_adCylinder.push_back(dRadiusTop); + sCurMarkupTessConnector.m_adCylinder.push_back(dHeight); + DEFAULT_OFFSET + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupPolygonMask): // 16 : polylines + { + if (sCurMarkupTessConnector.m_adPolylineCoords.empty() == true) + { + sCurMarkupTessConnector.m_aiPolylineIndices.push_back(0); + } + kSize = *(puiStart + 1); // number of points + int iNbIndicesBefore = 0; + if (sCurMarkupTessConnector.m_aiPolylineIndices.size() > 0) + { + iNbIndicesBefore = sCurMarkupTessConnector.m_aiPolylineIndices.back(); + } + unsigned int uI; + for (uI = 0; uI < kSize; uI++) + sCurMarkupTessConnector.m_adPolylineCoords.push_back(*(pData + uI)); + sCurMarkupTessConnector.m_aiPolylineIndices.push_back(iNbIndicesBefore + (kSize / 3)); + DEFAULT_OFFSET; + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupColorMask): // 11 : color + { + CHECK_RET_CALL_A3D_FCTION(A3DGlobalGetGraphRgbColorData,(*(puiStart+2), &sRgbColorData)); + sCurMarkupTessConnector.m_adRGB[0] = sRgbColorData.m_dRed; + sCurMarkupTessConnector.m_adRGB[1] = sRgbColorData.m_dGreen; + sCurMarkupTessConnector.m_adRGB[2] = sRgbColorData.m_dBlue; + DEFAULT_OFFSET; + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupLineStippleMask): // 12 : line stipple + { + if (uiCount > 0) + { + sCurMarkupTessConnector.m_iGraphStyleIndexLinsStyle = *(puiStart + 2); + } + else + sCurMarkupTessConnector.m_iGraphStyleIndexLinsStyle = -1; + //glDisable(GL_LINE_STIPPLE); + DEFAULT_OFFSET; + break; + } + + case A3D_DECODE_EXTRA_DATA(kA3DMarkupLineWidthMask): // 17 : line width + // Linewidth are only used on markup arrow of drawings + { + if (*(puiStart + 1) > 0) + { + sCurMarkupTessConnector.m_dLineWidth = *pData; + } + else + { + sCurMarkupTessConnector.m_dLineWidth = 1; + } + DEFAULT_OFFSET; + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupPointsMask): // 15: points + { + kSize = *(puiStart + 1); // number of points + unsigned int uI; + for (uI = 0; uI < kSize; uI++) + { + sCurMarkupTessConnector.m_adPoints.push_back(*(pData + uI)); + } + DEFAULT_OFFSET; + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupFontMask): // 13: font + { + sFontKeyData.m_iFontFamilyIndex = *(puiStart + 2); + sFontKeyData.m_iFontStyleIndex = (*(puiStart + 3) & kA3DFontKeyStyle) >> 24; + sFontKeyData.m_iFontSizeIndex = (*(puiStart + 3) & kA3DFontKeySize) >> 12; + sFontKeyData.m_cAttributes = (A3DInt8)(*(puiStart + 3) & kA3DFontKeyAttrib); + DEFAULT_OFFSET; + break; + } + case A3D_DECODE_EXTRA_DATA(kA3DMarkupTextMask): // 14: text + { + A3DDouble dTextWidth = *pData; + A3DDouble dTextHeight = *(pData + 1); + A3DUns32 uiTextIndex = *(puiStart + 2); + if (uiTextIndex < pTessMarkupData->m_uiTextsSize) + { + sCurMarkupTessConnector.m_apTexts.push_back(new A3DPMITextEntry(dTextWidth, dTextHeight, + sFontKeyData, pTessMarkupData->m_ppcTexts[uiTextIndex])); + } + DEFAULT_OFFSET; + break; + } + + default: + DEFAULT_OFFSET; + } + } + else if (*puiStart & kA3DMarkupIsMatrix) + { + if (*(puiStart + 1) > 0) // if there are floats it is the beginning of a "matrix" mode + { + A3DMarkupTessConnector& sCurMarkupTessConnector = sMarkupTessDataConnectorCreator.GetMarkupTessConnector((const double*)pData); + sCurMarkupTessConnector.m_ucBehaviour = pTessMarkupData->m_cBehaviour; + CHECK_RET(sMarkupTessDataConnectorCreator.pushMatrix((const double*)pData)); + + memcpy(&(sCurMarkupTessConnector.m_adWorldMatrix[0]), + sMarkupTessDataConnectorCreator.GetCurrentWorldMatrix(), + sizeof(double) * 16); + //dScaleText=stGetScaleText(pData); + if (sCurMarkupTessConnector.IsFrameDraw()) + { + sCurMarkupTessConnector.m_adWorldMatrix[0] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[1] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[2] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[4] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[5] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[6] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[7] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[8] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[9] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[11] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[12] *= a_dParallelToScreenPMIScale; + sCurMarkupTessConnector.m_adWorldMatrix[13] *= a_dParallelToScreenPMIScale; + } + MAKE_OFFSET(0, 16); + } + else // if there is no float, the matrix mode ends + { + sMarkupTessDataConnectorCreator.popMatrix(); + MAKE_OFFSET(0, 0); + } + } + else // It's a polyline + { + bool bCameraDependant; + A3DMarkupTessConnector& sCurMarkupTessConnector = + sMarkupTessDataConnectorCreator.GetMarkupTessConnector(0, bCameraDependant); + if (sCurMarkupTessConnector.m_adPolylineCoords.empty() == true) + { + sCurMarkupTessConnector.m_aiPolylineIndices.push_back(0); + } + kSize = *(puiStart + 1); // Number of points + unsigned int i = 0; + for (i = 0; i < kSize; i++) + { + sCurMarkupTessConnector.m_adPolylineCoords.push_back(*(pData + i)); + } + + if (sCurMarkupTessConnector.IsFrameDraw()) + { + std::vector::iterator itRescaleCur = sCurMarkupTessConnector.m_adPolylineCoords.begin(); + std::vector::iterator itRescaleEnd = sCurMarkupTessConnector.m_adPolylineCoords.end(); + for (; itRescaleCur != itRescaleEnd; ++itRescaleCur) + { + *itRescaleCur *= a_dParallelToScreenPMIScale; + } + } + + sCurMarkupTessConnector.m_aiPolylineIndices.push_back(int(sCurMarkupTessConnector.m_adPolylineCoords.size()) / 3); + DEFAULT_OFFSET; + } + } + return iRet; +} + +/// Is the order important? Like if FaceView set after Framedraw +A3DStatus A3DMarkupTessConnector::ComputeCameraDependantMatrix( + double const * pdProjMatrix, + int const * aiViewport, + long const * Rect, // TOP_LEFT(X,Y) BOTTOM_RIGHT(X,Y) + double* /*pdPerViewMatrix*/) +{ + + A3DStatus iRet = A3D_SUCCESS; + + double dScaling = 1, dFixedSize = 1.0 * 15 / dScaling; + if (m_bFaceView) // faceview + // using for circlecenter/fastener/measurementpoint/spotwelding + // geometrical symbol zoomable + { + double sO[3]; sO[0] = 0; sO[1] = 0; sO[2] = 0; + double sX[3]; sX[0] = 1; sX[1] = 0; sX[2] = 0; + double sY[3]; sY[0] = 0; sY[1] = 1; sY[2] = 0; + + double adP0[3], adP1[3], adP2[3]; + UnProject(&sO[0], m_adModelMatrix, pdProjMatrix, aiViewport, &adP0[0]); + UnProject(&sX[0], m_adModelMatrix, pdProjMatrix, aiViewport, &adP1[0]); + UnProject(&sY[0], m_adModelMatrix, pdProjMatrix, aiViewport, &adP2[0]); + + double adVectX[3]; + adVectX[0] = adP1[0] - adP0[0]; + adVectX[1] = adP1[1] - adP0[1]; + adVectX[2] = adP1[2] - adP0[2]; + + double adVectY[3]; + adVectY[0] = adP2[0] - adP0[0]; + adVectY[1] = adP2[1] - adP0[1]; + adVectY[2] = adP2[2] - adP0[2]; + double adPlaneNormal[3]; + //Cross Product + adPlaneNormal[0] = adVectX[1] * adVectY[2] - adVectX[2] * adVectY[1]; + adPlaneNormal[0] = adVectX[2] * adVectY[0] - adVectX[0] * adVectY[2]; + adPlaneNormal[0] = adVectX[0] * adVectY[1] - adVectX[1] * adVectY[0]; + double adMat[16]; + CHECK_RET(Calculate(&adVectX[0], &adVectY[0], &adPlaneNormal[0], &adMat[0])); + + adMat[12] = m_adViewDependantParameter[0]; + adMat[13] = m_adViewDependantParameter[1]; + adMat[14] = m_adViewDependantParameter[2]; + adMat[15] = 1.; + double adOldModelMatrix[16]; + memcpy(&adOldModelMatrix[0], &m_adModelMatrix[0], sizeof(double) * 16); + CHECK_RET(MultiplyMatrix(&adOldModelMatrix[0], &adMat[0], &m_adModelMatrix[0])); + + } + + if (m_bFrameDraw) // Usually used for non-zoomable text, but it is possible to change to zoomable (option on CatiaV5) + { + double dXProj, dYProj, dZProj; + if (m_bIsText) + { + dXProj = m_adViewDependantParameter[0]; + dYProj = m_adViewDependantParameter[1]; + dZProj = 0.; + } + else + { + + + // if (GetMatrixOwnerGroup(sMatGroup)) + // sMatGroup.TransformScaled(adViewDependantParameter[0], adViewDependantParameter[1], adViewDependantParameter[2]); + Project(m_adViewDependantParameter[0], m_adViewDependantParameter[1], m_adViewDependantParameter[2], + m_adModelMatrix, pdProjMatrix, aiViewport, &dXProj, &dYProj, &dZProj); + } + + double adIentity[16]; + Identity(&adIentity[0]); + double adOrthoMatrix[16]; + Ortho(&adIentity[0], + 0.0, (double)(Rect[3] - Rect[1]), // Right, Left + 0.0, (double)(Rect[0] - Rect[2]), //Top, Bottom + -1.0, 1.0, //Near, Fast + &adOrthoMatrix[0]); + + double adTranslat[16]; + Identity(&adTranslat[0]); + adTranslat[3] = dXProj; + adTranslat[7] = dYProj; + adTranslat[11] = dZProj; + + CHECK_RET(MultiplyMatrix(&adOrthoMatrix[0], &adTranslat[0], &m_adProjMatrix[0])); + + if (IsZoomable()) + { + double adScale[16]; + Identity(&adScale[0]); + adScale[0] = adScale[5] = adScale[10] = adScale[15] = dFixedSize; + double adOldModelMatrix[16]; + memcpy(&adOldModelMatrix[0], &m_adModelMatrix[0], sizeof(double) * 16); + CHECK_RET(MultiplyMatrix(&adOldModelMatrix[0], &adScale[0], &m_adModelMatrix[0])); + + } + } + + if (m_bFixedSize) + { + double adTranslat[16]; + Identity(&adTranslat[0]); + adTranslat[3] = m_adViewDependantParameter[0]; + adTranslat[7] = m_adViewDependantParameter[1]; + adTranslat[11] = m_adViewDependantParameter[2]; + + double adScale[16]; + Identity(&adScale[0]); + adScale[0] = adScale[5] = adScale[10] = adScale[15] = dFixedSize; + + double adOldModelMatrix[16]; + memcpy(&adOldModelMatrix[0], &m_adModelMatrix[0], sizeof(double) * 16); + CHECK_RET(MultiplyMatrix(&adOldModelMatrix[0], &adTranslat[0], &m_adModelMatrix[0])); + + memcpy(&adOldModelMatrix[0], &m_adModelMatrix[0], sizeof(double) * 16); + CHECK_RET(MultiplyMatrix(&adOldModelMatrix[0], &adScale[0], &m_adModelMatrix[0])); + } + + if (m_bSymbol) + { + double dXProj, dYProj, dZProj; + if (m_bIsText) + { + dXProj = m_adViewDependantParameter[0]; + dYProj = m_adViewDependantParameter[1]; + dZProj = 0.; + } + else + { + + // if (GetMatrixOwnerGroup(sMatGroup)) + // sMatGroup.TransformScaled(sPntFrame.x,sPntFrame.y,sPntFrame.z); + + CHECK_RET(Project(m_adViewDependantParameter[0], m_adViewDependantParameter[1], m_adViewDependantParameter[2], + m_adModelMatrix, pdProjMatrix, aiViewport, &dXProj, &dYProj, &dZProj)); + } + + double adIentity[16]; + Identity(&adIentity[0]); + double adOrthoMatrix[16]; + CHECK_RET(Ortho(&adIentity[0], + 0.0, (double)(Rect[3] - Rect[1]), // Right, Left + 0.0, (double)(Rect[0] - Rect[2]), //Top, Bottom + -1.0, 1.0, //Near, Fast + &adOrthoMatrix[0])); + + double adTranslat[16]; + Identity(&adTranslat[0]); + adTranslat[3] = dXProj; + adTranslat[7] = dYProj; + adTranslat[11] = dZProj; + + CHECK_RET(MultiplyMatrix(&adOrthoMatrix[0], &adTranslat[0], &m_adProjMatrix[0])); + + //Pattern not used + } + return A3D_SUCCESS; +} + + + diff --git a/exchange/exchangesource/Viewer/traverse/MarkupTraverse.cpp b/exchange/exchangesource/Viewer/traverse/MarkupTraverse.cpp new file mode 100644 index 0000000..56a6a74 --- /dev/null +++ b/exchange/exchangesource/Viewer/traverse/MarkupTraverse.cpp @@ -0,0 +1,255 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file MarkupTraverse.cpp + +This file contains functionalities to traverse a PRC Markup Tree + +***********************************************************************************************************************/ + +#include "../VisitorContainer.h" +#include "../MarkupTraverse.h" +#include +#include +#include "../MarkupTessConnector.h" + +////////////////////////////////////////////////////////////////////////////// +// Traverse Markup +////////////////////////////////////////////////////////////////////////////// +A3DStatus A3DMkpAnnotationEntityConnector::TraverseAnnotationEntity(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + + A3DEEntityType eType = kA3DTypeUnknown; + A3DStatus iRet = CALL_A3D_FCTION(A3DEntityGetType,(m_pEntity,&eType)); + CHECK_RET(iRet); + switch (eType) + { + case kA3DTypeMkpAnnotationSet: + { + A3DMkpAnnotationSetConnector sMkpAnnotationSetConnector((A3DMkpAnnotationSet*)m_pEntity); + iRet = sMkpAnnotationSetConnector.TraverseAnnotationSet(pVisitor); + break; + } + case kA3DTypeMkpAnnotationReference: + { + A3DMkpAnnotationReferenceConnector sMkpAnnotationReferenceConnector((A3DMkpAnnotationReference*)m_pEntity); + iRet = sMkpAnnotationReferenceConnector.TraverseAnnotationReference(pVisitor); + break; + } + case kA3DTypeMkpAnnotationItem: + { + A3DMkpAnnotationItemConnector sMkpAnnotationItemConnector((A3DMkpAnnotationItem*)m_pEntity); + iRet = sMkpAnnotationItemConnector.TraverseAnnotationItem(pVisitor); + break; + } + default: + iRet = A3D_ERROR; + break; + } + pVisitor->visitLeave(*this); + + return A3D_SUCCESS; +} + +A3DStatus A3DMkpAnnotationSetConnector::TraverseAnnotationSet(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + A3DUns32 uNbAnnotEntity = m_sAnnotSetData.m_uiAnnotationsSize; + for (A3DUns32 uI = 0; uI < uNbAnnotEntity; uI++) + { + A3DMkpAnnotationEntityConnector sMkpAnnotationEntityConnector(m_sAnnotSetData.m_ppAnnotations[uI]); + sMkpAnnotationEntityConnector.TraverseAnnotationEntity(pVisitor); + } + pVisitor->visitLeave(*this); + return A3D_SUCCESS; +} + +A3DStatus A3DMkpAnnotationReferenceConnector::TraverseAnnotationReference(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + pVisitor->visitLeave(*this); + return A3D_SUCCESS; +} + +A3DStatus A3DMkpAnnotationItemConnector::TraverseAnnotationItem(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + if (m_sAnnotItemData.m_pMarkup == NULL) + { + pVisitor->visitLeave(*this); + return A3D_SUCCESS; + } + + A3DMarkupConnector sMarkupConnector((A3DMkpMarkup*)m_sAnnotItemData.m_pMarkup); + + ///////////////////////////////////////////////// + // Traverse Semantic + ///////////////////////////////////////////////// + sMarkupConnector.TraverseMarkupSemantic(pVisitor); + + ///////////////////////////////////////////////// + // Traverse Graphicals information + ///////////////////////////////////////////////// + std::vector asMarkupTessConnector; + double a_dParallelToScreenPMIScale = 1; + sMarkupConnector.SplitMarkupTesselationByEntityWithSameGraphics(asMarkupTessConnector, a_dParallelToScreenPMIScale); + sMarkupConnector.TraverseMarkupTess(pVisitor, asMarkupTessConnector); + + pVisitor->visitLeave(*this); + return A3D_SUCCESS; +} + +A3DStatus A3DMarkupConnector::TraverseMarkupTess(A3DVisitorContainer* pVisitor, std::vector& asMarkupTessConnector) +{ + for (size_t ui = 0; ui < asMarkupTessConnector.size(); ui++) + asMarkupTessConnector[ui]->TraverseMarkupTessWithSameGraphicsAttributes(pVisitor); + return A3D_SUCCESS; +} + +A3DStatus A3DMarkupTessConnector::TraverseMarkupTessWithSameGraphicsAttributes(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + pVisitor->visitLeave(*this); + return A3D_SUCCESS; +} + + +A3DStatus A3DMarkupConnector::SplitMarkupTesselationByEntityWithSameGraphics(std::vector& asMarkupTessConnector, + double a_dParallelToScreenPMIScale) +{ + A3DStatus iRet = A3D_SUCCESS; + A3DTessMarkupData sMarkupTessData; + A3D_INITIALIZE_DATA(A3DTessMarkupData, sMarkupTessData); + CHECK_RET_CALL_A3D_FCTION(A3DTessMarkupGet,(m_sMarkupData.m_pTessellation, &sMarkupTessData)); + + A3DTessBaseData sTessBaseData; + A3D_INITIALIZE_DATA(A3DTessBaseData, sTessBaseData); + CHECK_RET_CALL_A3D_FCTION(A3DTessBaseGet,(m_sMarkupData.m_pTessellation, &sTessBaseData)); + + bool bIsText = m_sMarkupData.m_eType == kA3DMarkupTypeText; + + CHECK_RET(A3DMarkupTessConnector::GetMarkupTessellation(sTessBaseData, &sMarkupTessData, bIsText, + asMarkupTessConnector, a_dParallelToScreenPMIScale)); + + CHECK_RET_CALL_A3D_FCTION(A3DTessBaseGet,(NULL, &sTessBaseData)); + CHECK_RET_CALL_A3D_FCTION(A3DTessMarkupGet,(NULL, &sMarkupTessData)); + + unsigned int uI, uJ; + for (uI = 0; uI < m_sMarkupData.m_uiLeadersSize; uI++) + { + A3DMkpLeader* psLeader = m_sMarkupData.m_ppLeaders[uI]; + if (psLeader == NULL) + { + continue; + } + A3DMkpLeaderData sMarkupLeaderData; + A3D_INITIALIZE_DATA(A3DMkpLeaderData, sMarkupLeaderData); + CHECK_RET_CALL_A3D_FCTION(A3DMkpLeaderGet,(psLeader, &sMarkupLeaderData)); + + A3DTessMarkupData sMarkupLeaderTessData; + A3D_INITIALIZE_DATA(A3DTessMarkupData, sMarkupLeaderTessData); + CHECK_RET_CALL_A3D_FCTION(A3DTessMarkupGet,(sMarkupLeaderData.m_pTessellation, &sMarkupLeaderTessData)); + + A3DTessBaseData sLeaderTessBaseData; + A3D_INITIALIZE_DATA(A3DTessBaseData, sLeaderTessBaseData); + CHECK_RET_CALL_A3D_FCTION(A3DTessBaseGet,(sMarkupLeaderData.m_pTessellation, &sLeaderTessBaseData)); + + std::vector asMarkupLeaderConnector; + + CHECK_RET(A3DMarkupTessConnector::GetMarkupTessellation(sLeaderTessBaseData, &sMarkupLeaderTessData, bIsText, + asMarkupLeaderConnector, a_dParallelToScreenPMIScale)); + + for (uJ = 0; uJ < asMarkupLeaderConnector.size(); uJ++) + asMarkupTessConnector.push_back(asMarkupLeaderConnector[uJ]); + + CHECK_RET_CALL_A3D_FCTION(A3DTessBaseGet,(NULL, &sLeaderTessBaseData)); + CHECK_RET_CALL_A3D_FCTION(A3DTessMarkupGet,(NULL, &sMarkupLeaderTessData)); + CHECK_RET_CALL_A3D_FCTION(A3DMkpLeaderGet,(NULL, &sMarkupLeaderData)); + } + + return A3D_SUCCESS; +} + +A3DStatus A3DMarkupConnector::TraverseMarkupSemantic(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + + A3DEEntityType eType = kA3DTypeUnknown; + A3DStatus iRet = CALL_A3D_FCTION(A3DEntityGetType,( this->GetA3DEntity(), &eType)); + switch (eType) + { + + case kA3DTypeMarkupText: + break; + case kA3DTypeMarkupRichText: + break; + case kA3DTypeMarkupCoordinate: + break; + case kA3DTypeMarkupBalloon: + break; + case kA3DTypeMarkupDatum: + { + A3DMarkupDatumConnector sMkpDatumConnector((A3DMkpMarkup*) this->GetA3DEntity()); + iRet = sMkpDatumConnector.TraverseDatum(pVisitor); + } + break; + case kA3DTypeMarkupGDT: + { + A3DMarkupGDTConnector sMkpGDTConnector((A3DMkpMarkup*) this->GetA3DEntity()); + iRet = sMkpGDTConnector.TraverseGDT(pVisitor); + } + break; + case kA3DTypeMarkupRoughness: + break; + case kA3DTypeMarkupDimension: + { + A3DMarkupDimensionConnector sMkpDimensionConnector((A3DMkpMarkup*) this->GetA3DEntity()); + iRet = sMkpDimensionConnector.TraverseDimension(pVisitor); + } + break; + case kA3DTypeMarkupLocator: + break; + case kA3DTypeMarkupMeasurementPoint: + break; + case kA3DTypeMarkupFastener: + break; + case kA3DTypeMarkupSpotWelding: + break; + case kA3DTypeMarkupLineWelding: + break; + default: + break; + } + pVisitor->visitLeave(*this); + return A3D_SUCCESS; +} + +A3DStatus A3DMarkupDimensionConnector::TraverseDimension(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + pVisitor->visitLeave(*this); + return A3D_SUCCESS; +} +A3DStatus A3DMarkupGDTConnector::TraverseGDT(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + pVisitor->visitLeave(*this); + return A3D_SUCCESS; +} + +A3DStatus A3DMarkupDatumConnector::TraverseDatum(A3DVisitorContainer* pVisitor) +{ + pVisitor->visitEnter(*this); + pVisitor->visitLeave(*this); + return A3D_SUCCESS; +} + diff --git a/exchange/exchangesource/Viewer/traverse/TessConnector.cpp b/exchange/exchangesource/Viewer/traverse/TessConnector.cpp new file mode 100644 index 0000000..5e36dfd --- /dev/null +++ b/exchange/exchangesource/Viewer/traverse/TessConnector.cpp @@ -0,0 +1,1234 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file TessConnector.cpp +This file provide tools to get the Tessellation of Cad Models + +***********************************************************************************************************************/ + +#include "../TessConnector.h" +#include "../VisitorContainer.h" +#include + +//////////////////////////////////////// +// A3DTessDataConnector +/////////////////////////////////////// +A3DTessDataConnector::A3DTessDataConnector(const A3DTess3D* pTess3D) : A3DConnector(pTess3D) +{ + A3D_INITIALIZE_DATA(A3DTess3DData, m_sTessData); + CALL_A3D_FCTION(A3DTess3DGet,( pTess3D, &m_sTessData)); + + A3D_INITIALIZE_DATA(A3DTessBaseData, m_sBaseTessData); + CALL_A3D_FCTION(A3DTessBaseGet,((const A3DTessBase*) pTess3D,&m_sBaseTessData)); +} + +A3DTessDataConnector::~A3DTessDataConnector() +{ + CALL_A3D_FCTION(A3DTess3DGet,( NULL, &m_sTessData)); + CALL_A3D_FCTION(A3DTessBaseGet,(NULL, &m_sBaseTessData)); +} + +A3DStatus A3DTessDataConnector::Traverse(A3DVisitorContainer* psVisitor) +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned uNbFaces = FacesSize(); + + for (unsigned uFace = 0; uFace < uNbFaces; uFace++) + { + A3DFaceTessDataConnector sFaceConnector(&m_sTessData.m_psFaceTessData[uFace], uFace, this); + sFaceConnector.Traverse(psVisitor); + } + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +// Retrieve all the point of the Tess3DData +A3DStatus A3DTessDataConnector::Points(double*& pPoint, unsigned int& uSize) const +{ + pPoint = m_sBaseTessData.m_pdCoords; + uSize = m_sBaseTessData.m_uiCoordSize; + return A3D_SUCCESS; +} + +// Retrieve all the normals of the Tess3DData +A3DStatus A3DTessDataConnector::Normals(double*& pNormal, unsigned int& uSize) const +{ + pNormal = m_sTessData.m_pdNormals; + uSize = m_sTessData.m_uiNormalSize; + return A3D_SUCCESS; +} + +// Retrieve all the textures of the Tess3DData +A3DStatus A3DTessDataConnector::UV(double*& pUV, unsigned int& uSize) const +{ + pUV = m_sTessData.m_pdTextureCoords; + uSize = m_sTessData.m_uiTextureCoordSize; + return A3D_SUCCESS; +} + +#define COPY(dest,src,size_) if(size_ != 0) {\ + size_t uTempSize = dest.size();\ + dest.resize(uTempSize + size_);\ + std::copy(src ,src+ size_, dest.begin() + uTempSize);\ + src+= size_; \ + size_ = 0;\ + } + +#define COPY_(dest,src,size_) /*if(size_)*/ {\ + size_t uTempSize = dest.size();\ + dest.resize(uTempSize + size_);\ + std::copy(src,src+size_, dest.begin() + uTempSize);\ + } + + +// Retrieve the index as triangle for each Face of the Tess3DData +A3DStatus A3DTessDataConnector::IndicesAsTriangle( + std::vector& auTriangleWithPoint_Normals, + std::vector& auTriangleWithPoint_Normals_UV_Indices) const +{ + A3DStatus iRet = A3D_SUCCESS; + unsigned uFaceCount, uFaceSize = m_sTessData.m_uiFaceTessSize; + for (uFaceCount = 0; uFaceCount < uFaceSize; uFaceCount++) + { + CHECK_RET(IndicesPerFaceAsTriangle( + uFaceCount, + auTriangleWithPoint_Normals, + auTriangleWithPoint_Normals_UV_Indices)); + } + return A3D_SUCCESS; +} + +// Retrieve the index as triangle per face of the Tess3DData +A3DStatus A3DTessDataConnector::IndicesPerFaceAsTriangle( + const unsigned& uFaceIndice, + std::vector& auTriangleWithPoint_Normals_Indices, + std::vector& auTriangleWithPoint_Normals_UV_Indices) const +{ + A3DTessFaceData* pFaceTessData = &(m_sTessData.m_psFaceTessData[uFaceIndice]); + + if (!pFaceTessData->m_uiSizesTriangulatedSize) + return A3D_SUCCESS; + + A3DUns32* puiTriangulatedIndexes = m_sTessData.m_puiTriangulatedIndexes + + pFaceTessData->m_uiStartTriangulated; + unsigned uiCurrentSize = 0; + + // Triangle One Normal Per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangle) + { + unsigned uiNbIndice = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 6; + COPY(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, uiNbIndice); + } + + // Fan One Normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFan) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32* pFanPointIndice = puiTriangulatedIndexes; + puiTriangulatedIndexes += 2; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2, 2); + puiTriangulatedIndexes += 2; + } + puiTriangulatedIndexes += 2; + } + } + + // stripe One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripe) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + puiTriangulatedIndexes += 2; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 2); + if (uIPoint % 2) + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 2, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2, 2); + } + else + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 2, 2); + } + puiTriangulatedIndexes += 2; + } + puiTriangulatedIndexes += 2; + } + } + + //Triangle one Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormal) + { + A3DUns32 uNbTriangles = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]/* & kA3DTessFaceDataNormalMask*/; + for (A3DUns32 uI = 0; uI < uNbTriangles; uI++) + { + A3DUns32* pNormalIndice = puiTriangulatedIndexes; + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 2); + puiTriangulatedIndexes += 2; + COPY_(auTriangleWithPoint_Normals_Indices, pNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 1); + puiTriangulatedIndexes += 1; + COPY_(auTriangleWithPoint_Normals_Indices, pNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 1); + puiTriangulatedIndexes += 1; + } + } + + // Fan One normal per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormal) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if (bIsOneNormal == false) + { + return A3D_ERROR; + } + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32* pFanPointIndice = puiTriangulatedIndexes; + puiTriangulatedIndexes += 2; + for (A3DUns32 uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 2); + + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 1); + + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 1, 1); + puiTriangulatedIndexes += 1; + } + puiTriangulatedIndexes++; + } + } + + // Stripe One normal per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormal) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + A3DUns32* pStripeNormalIndice = puiTriangulatedIndexes; + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + puiTriangulatedIndexes += 2; + + // Is there only one normal for the entire stripe? + if (bIsOneNormal == false) + { + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 2); + if (uIPoint % 2) + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 2, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2, 2); + } + else + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 2, 2); + } + puiTriangulatedIndexes += 2; + } + puiTriangulatedIndexes += 2; + continue; + } + + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 1); + if (uIPoint % 2) + { + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 1, 1); + + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 1, 1); + } + else + { + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 1, 1); + + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 1, 1); + } + puiTriangulatedIndexes += 1; + } + puiTriangulatedIndexes += 1; + } + } + + // Textured triangle One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleTextured) + { + unsigned uiNbIndice = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * (6 + 3 * pFaceTessData->m_uiTextureCoordIndexesSize); + COPY(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, uiNbIndice); + } + + // Textured Fan One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanTextured) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32* pFanPointIndice = puiTriangulatedIndexes; + puiTriangulatedIndexes += 3; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3, 3); + puiTriangulatedIndexes += 3; + } + puiTriangulatedIndexes += 3; + } + } + + //Textured Stripe One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeTextured) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + puiTriangulatedIndexes += 3; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 3); + if (uIPoint % 2) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 3, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3, 3); + } + else + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 3, 3); + } + puiTriangulatedIndexes += 3; + } + puiTriangulatedIndexes += 3; + } + } + + // Textured One normal per Triangle + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormalTextured) + { + A3DUns32 uNbTriangles = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uI = 0; uI < uNbTriangles; uI++) + { + A3DUns32* pNormalIndice = puiTriangulatedIndexes; + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 3); + puiTriangulatedIndexes += 3; + COPY_(auTriangleWithPoint_Normals_UV_Indices, pNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 2); + puiTriangulatedIndexes += 2; + COPY_(auTriangleWithPoint_Normals_UV_Indices, pNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 2); + puiTriangulatedIndexes += 2; + } + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormalTextured) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if (bIsOneNormal == false) + { + return A3D_ERROR; + } + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32* pFanPointIndice = puiTriangulatedIndexes; + puiTriangulatedIndexes += 2; + for (A3DUns32 uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 3); + + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 1); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 2); + + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 1); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 2, 2); + puiTriangulatedIndexes += 2; + } + puiTriangulatedIndexes += 2; + } + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormalTextured) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if (bIsOneNormal == false) + { + return A3D_ERROR; + } + A3DUns32* pStripeNormalIndice = puiTriangulatedIndexes; + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + puiTriangulatedIndexes += 3; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice, 1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 2); + if (uIPoint % 2) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice, 1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 2, 2); + + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice, 1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 2, 2); + } + else + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice, 1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 2, 2); + + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice, 1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 2, 2); + + } + puiTriangulatedIndexes += 2; + } + } + } + + return A3D_SUCCESS; +} + +A3DStatus A3DTessDataConnector::IndicesPerFace( + const unsigned& uFaceIndice, + std::vector& /*auTrianglesOneNormal*/, //(normal, point, point,..., point) + std::vector& /*auFanOneNormal*/, + std::vector& /*auStripeOneNormal*/, + std::vector& auTrianglesWithNormals, //normal, point, ... , normal, point + std::vector& auFanWithNormals, + std::vector& auStripeWithNormal, + std::vector& /*auTrianglesOneNormalTexture*/, //normal,{texture...},point,{texture...},point,{texture...},point + std::vector& /*auFanOneNormalTextured*/, + std::vector& /*auStripeOneNormalTextured*/, + std::vector& /*auTrianglesWithNormalsTextured*/, //normal,{texture...},point,...,normal,{texture...},point + std::vector& /*auFanWithNormalsTextured*/, + std::vector& /*auStripeWithNormalsTextured*/) const +{ + A3DTessFaceData* pFaceTessData = &(m_sTessData.m_psFaceTessData[uFaceIndice]); + if (!pFaceTessData->m_uiSizesTriangulatedSize) + return A3D_SUCCESS; + + A3DUns32 uiCurrentSize = 0; + A3DUns32* puiTriangulatedIndexes = m_sTessData.m_puiTriangulatedIndexes + + pFaceTessData->m_uiStartTriangulated; + A3DUns32 uiNbIndice = 0; + + // One Normal Per Vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangle) + { + uiNbIndice = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 6; + COPY(auTrianglesWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFan) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + uiNbIndice += pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 2; + COPY(auFanWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripe) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + uiNbIndice += pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 2; + COPY(auStripeWithNormal, puiTriangulatedIndexes, uiNbIndice); + } + + //One Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormal) + { + uiNbIndice = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]/* & kA3DTessFaceDataNormalMask*/) * 4; + } + COPY(auTrianglesWithNormals, puiTriangulatedIndexes, uiNbIndice); + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormal) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if (bIsOneNormal == false) + { + return A3D_ERROR; + } + uiNbIndice += pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] + 1; + } + COPY(auFanWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormal) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if (bIsOneNormal == false) + { + return A3D_ERROR; + } + uiNbIndice += pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] + 1; + } + COPY(auStripeWithNormal, puiTriangulatedIndexes, uiNbIndice); + } + + // Textured + //One Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleTextured) + uiNbIndice = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 9; + COPY(auTrianglesWithNormals, puiTriangulatedIndexes, uiNbIndice); + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanTextured) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + uiNbIndice += pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 3; + COPY(auFanWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeTextured) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + uiNbIndice += pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 3; + COPY(auStripeWithNormal, puiTriangulatedIndexes, uiNbIndice); + } + + + // Textured + //One Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormalTextured) + { + uiNbIndice = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]/* & kA3DTessFaceDataNormalMask*/) * 7; + } + COPY(auTrianglesWithNormals, puiTriangulatedIndexes, uiNbIndice); + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormalTextured) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if (bIsOneNormal == false) + { + return A3D_ERROR; + } + uiNbIndice += (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask) * 2 + 1; + } + COPY(auFanWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormalTextured) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if (bIsOneNormal == false) + { + return A3D_ERROR; + } + uiNbIndice += (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask) * 2 + 1; + } + COPY(auStripeWithNormal, puiTriangulatedIndexes, uiNbIndice); + } + + return A3D_SUCCESS; +} + +A3DStatus A3DTessDataConnector::Indices( + std::vector& auTrianglesOneNormal, //(normal, point, point,..., point) + std::vector& auFanOneNormal, + std::vector& auStripeOneNormal, + std::vector& auTrianglesWithNormals, //normal, point, ... , normal, point + std::vector& auFanWithNormals, + std::vector& auStripeWithNormal, + std::vector& auTrianglesOneNormalTexture, //normal,{texture...},point,{texture...},point,{texture...},point + std::vector& auFanOneNormalTextured, + std::vector& auStripeOneNormalTextured, + std::vector& auTrianglesWithNormalsTextured, //normal,{texture...},point,...,normal,{texture...},point + std::vector& auFanWithNormalsTextured, + std::vector& auStripeWithNormalsTextured) const +{ + A3DStatus iRet = A3D_SUCCESS; + unsigned uFaceCount, uFaceSize = m_sTessData.m_uiFaceTessSize; + for (uFaceCount = 0; uFaceCount < uFaceSize; uFaceCount++) + CHECK_RET(IndicesPerFace( + uFaceCount, + auTrianglesOneNormal, + auFanOneNormal, + auStripeOneNormal, + auTrianglesWithNormals, + auFanWithNormals, + auStripeWithNormal, + auTrianglesOneNormalTexture, + auFanOneNormalTextured, + auStripeOneNormalTextured, + auTrianglesWithNormalsTextured, + auFanWithNormalsTextured, + auStripeWithNormalsTextured)); + return A3D_SUCCESS; +} + +//////////////////////////////////////// +// A3DFaceTessDataConnector +/////////////////////////////////////// +A3DFaceTessDataConnector::A3DFaceTessDataConnector(const A3DTessFaceData* pFaceTess3D, + unsigned uCurrentFaceIndex, + const A3DTessDataConnector* pTessConnector) + : A3DConnector(pFaceTess3D), + m_pTessConnector(pTessConnector), + m_uCurrentFaceIndex(uCurrentFaceIndex) +{ +} + +A3DFaceTessDataConnector::~A3DFaceTessDataConnector() +{ +} + +A3DStatus A3DFaceTessDataConnector::Traverse(A3DVisitorContainer* psVisitor) +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + + +A3DStatus A3DFaceTessDataConnector::IndicesAsTriangle( + std::vector& auTriangleWithPoint_Normals_Indices, + std::vector& auTriangleWithPoint_Normals_UV_Indices) const +{ + A3DTessFaceData* pFaceTessData = (A3DTessFaceData*)this->GetA3DEntity(); + if (!pFaceTessData->m_uiSizesTriangulatedSize) + return A3D_SUCCESS; + + A3DUns32* puiTriangulatedIndexes = m_pTessConnector->GetTess3DData()->m_puiTriangulatedIndexes + + pFaceTessData->m_uiStartTriangulated; + unsigned uiCurrentSize = 0; + + // Triangle One Normal Per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangle) + { + unsigned uiNbIndice = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]) * 6; + COPY(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, uiNbIndice); + puiTriangulatedIndexes += uiNbIndice; + } + + // Fan One Normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFan) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32* pFanPointIndice = puiTriangulatedIndexes; + puiTriangulatedIndexes += 2; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2, 2); + puiTriangulatedIndexes += 2; + } + puiTriangulatedIndexes += 2; + } + } + + // stripe One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripe) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + puiTriangulatedIndexes += 2; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 2); + if (uIPoint % 2) + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 2, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2, 2); + } + else + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 2, 2); + } + puiTriangulatedIndexes += 2; + } + puiTriangulatedIndexes += 2; + } + } + + //Triangle one Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormal) + { + A3DUns32 uNbTriangles = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]/* & kA3DTessFaceDataNormalMask*/; + for (A3DUns32 uI = 0; uI < uNbTriangles; uI++) + { + A3DUns32* pNormalIndice = puiTriangulatedIndexes; + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 2); + puiTriangulatedIndexes += 2; + COPY_(auTriangleWithPoint_Normals_Indices, pNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 1); + puiTriangulatedIndexes += 1; + COPY_(auTriangleWithPoint_Normals_Indices, pNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 1); + puiTriangulatedIndexes += 1; + } + } + + // Fan One normal per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormal) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32* pFanPointIndice = puiTriangulatedIndexes; + puiTriangulatedIndexes += 1; + + if (bIsOneNormal == false) + { + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2, 2); + puiTriangulatedIndexes += 2; + } + puiTriangulatedIndexes += 2; + continue; + } + + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 1; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 2); + + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 1); + + COPY_(auTriangleWithPoint_Normals_Indices, pFanPointIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 1, 1); + puiTriangulatedIndexes += 1; + } + puiTriangulatedIndexes += 1; + } + } + + // Stripe One normal per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormal) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + A3DUns32* pStripeNormalIndice = puiTriangulatedIndexes; + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + puiTriangulatedIndexes += 2; + + if (bIsOneNormal == false) + { + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 2); + if (uIPoint % 2) + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 2, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2, 2); + } + else + { + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 2, 2); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 2, 2); + } + puiTriangulatedIndexes += 2; + } + puiTriangulatedIndexes += 2; + continue; + } + + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes, 1); + if (uIPoint % 2) + { + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 1, 1); + + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 1, 1); + } + else + { + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes + 1, 1); + + COPY_(auTriangleWithPoint_Normals_Indices, pStripeNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_Indices, puiTriangulatedIndexes - 1, 1); + } + puiTriangulatedIndexes += 1; + } + puiTriangulatedIndexes += 1; + } + } + + // Textured triangle One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleTextured) + { + unsigned uiNbIndice = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 9; + COPY(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, uiNbIndice); + puiTriangulatedIndexes += uiNbIndice; + } + + // Textured Fan One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanTextured) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32* pFanPointIndice = puiTriangulatedIndexes; + puiTriangulatedIndexes += 3; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3, 3); + puiTriangulatedIndexes += 3; + } + puiTriangulatedIndexes += 3; + } + } + + //Textured Stripe One normal per vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeTextured) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + puiTriangulatedIndexes += 3; + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 3); + if (uIPoint % 2) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 3, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3, 3); + } + else + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 3, 3); + } + puiTriangulatedIndexes += 3; + } + puiTriangulatedIndexes += 3; + } + } + + // Textured One normal per Triangle + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormalTextured) + { + A3DUns32 uNbTriangles = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uI = 0; uI < uNbTriangles; uI++) + { + A3DUns32* pNormalIndice = puiTriangulatedIndexes; + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 3); + puiTriangulatedIndexes += 3; + COPY_(auTriangleWithPoint_Normals_UV_Indices, pNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 2); + puiTriangulatedIndexes += 2; + COPY_(auTriangleWithPoint_Normals_UV_Indices, pNormalIndice, 1); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 2); + puiTriangulatedIndexes += 2; + } + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormalTextured) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32* pFanPointIndice = puiTriangulatedIndexes; + puiTriangulatedIndexes += 2; + + if (bIsOneNormal == false) + { + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3, 3); + puiTriangulatedIndexes += 3; + } + puiTriangulatedIndexes += 3; + continue; + } + + for (A3DUns32 uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 3); + + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 1); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 2); + + COPY_(auTriangleWithPoint_Normals_UV_Indices, pFanPointIndice, 1); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 2, 2); + puiTriangulatedIndexes += 2; + } + puiTriangulatedIndexes += 2; + } + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormalTextured) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + A3DUns32* pStripeNormalIndice = puiTriangulatedIndexes; + A3DUns32 uiNbPoint = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + puiTriangulatedIndexes += 3; + + if (bIsOneNormal == false) + { + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 3); + if (uIPoint % 2) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 3, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3, 3); + } + else + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 3, 3); + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 3, 3); + } + puiTriangulatedIndexes += 3; + } + puiTriangulatedIndexes += 3; + continue; + } + + A3DUns32 uIPoint; + for (uIPoint = 0; uIPoint < uiNbPoint - 2; uIPoint++) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice, 1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes, 2); + if (uIPoint % 2) + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice, 1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 2, 2); + + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice, 1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 2, 2); + } + else + { + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice, 1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes + 2, 2); + + COPY_(auTriangleWithPoint_Normals_UV_Indices, pStripeNormalIndice, 1) + COPY_(auTriangleWithPoint_Normals_UV_Indices, puiTriangulatedIndexes - 2, 2); + + } + puiTriangulatedIndexes += 2; + } + puiTriangulatedIndexes += 2; + } + } + + return A3D_SUCCESS; +} + +A3DStatus A3DFaceTessDataConnector::Indices( + std::vector& /*auTrianglesOneNormal*/, //(normal, point, point,..., point) + std::vector& /*auFanOneNormal*/, + std::vector& /*auStripeOneNormal*/, + std::vector& auTrianglesWithNormals, //normal, point, ... , normal, point + std::vector& auFanWithNormals, + std::vector& auStripeWithNormal, + std::vector& /*auTrianglesOneNormalTexture*/, //normal,{texture...},point,{texture...},point,{texture...},point + std::vector& /*auFanOneNormalTextured*/, + std::vector& /*auStripeOneNormalTextured*/, + std::vector& /*auTrianglesWithNormalsTextured*/, //normal,{texture...},point,...,normal,{texture...},point + std::vector& /*auFanWithNormalsTextured*/, + std::vector& /*auStripeWithNormalsTextured*/) const +{ + A3DTessFaceData* pFaceTessData = (A3DTessFaceData*)this->GetA3DEntity(); + if (!pFaceTessData->m_uiSizesTriangulatedSize) + return A3D_SUCCESS; + + A3DUns32 uiCurrentSize = 0; + A3DUns32* puiTriangulatedIndexes = m_pTessConnector->GetTess3DData()->m_puiTriangulatedIndexes + + pFaceTessData->m_uiStartTriangulated; + A3DUns32 uiNbIndice = 0; + + // One Normal Per Vertex + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangle) + { + uiNbIndice = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 6; + COPY(auTrianglesWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFan) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + uiNbIndice += pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 2; + COPY(auFanWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripe) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + uiNbIndice += pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 2; + COPY(auStripeWithNormal, puiTriangulatedIndexes, uiNbIndice); + } + + //One Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormal) + { + // bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + // if(bIsOneNormal == false) + // { + // return A3D_ERROR; + // } + uiNbIndice = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]/* & kA3DTessFaceDataNormalMask*/) * 4; + } + COPY(auTrianglesWithNormals, puiTriangulatedIndexes, uiNbIndice); + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormal) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if (bIsOneNormal == false) + { + return A3D_ERROR; + } + uiNbIndice += (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask) + 1; + } + COPY(auFanWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormal) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if (bIsOneNormal == false) + { + return A3D_ERROR; + } + uiNbIndice += pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] + 1; + } + COPY(auStripeWithNormal, puiTriangulatedIndexes, uiNbIndice); + } + + // Textured + //One Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleTextured) + uiNbIndice = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 9; + COPY(auTrianglesWithNormals, puiTriangulatedIndexes, uiNbIndice); + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanTextured) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + uiNbIndice += pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 3; + COPY(auFanWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeTextured) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + uiNbIndice += pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] * 3; + COPY(auStripeWithNormal, puiTriangulatedIndexes, uiNbIndice); + } + + + // Textured + //One Normal Per entity + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleOneNormalTextured) + { + uiNbIndice = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++]/* & kA3DTessFaceDataNormalMask*/) * 7; + } + COPY(auTrianglesWithNormals, puiTriangulatedIndexes, uiNbIndice); + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleFanOneNormalTextured) + { + A3DUns32 uiNbFan = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + for (A3DUns32 uiFan = 0; uiFan < uiNbFan; uiFan++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if (bIsOneNormal == false) + { + return A3D_ERROR; + } + uiNbIndice += (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask) * 2 + 1; + } + COPY(auFanWithNormals, puiTriangulatedIndexes, uiNbIndice); + } + + if (pFaceTessData->m_usUsedEntitiesFlags & kA3DTessFaceDataTriangleStripeOneNormalTextured) + { + A3DUns32 uiNbStripe = pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask; + A3DUns32 uiStripe; + for (uiStripe = 0; uiStripe < uiNbStripe; uiStripe++) + { + bool bIsOneNormal = (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize] & kA3DTessFaceDataNormalSingle) != 0; + if (bIsOneNormal == false) + { + return A3D_ERROR; + } + uiNbIndice += (pFaceTessData->m_puiSizesTriangulated[uiCurrentSize++] & kA3DTessFaceDataNormalMask) * 2 + 1; + } + COPY(auStripeWithNormal, puiTriangulatedIndexes, uiNbIndice); + } + + return A3D_SUCCESS; +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +//A3DWireTessDataConnector +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +A3DWireTessDataConnector::A3DWireTessDataConnector(const A3DTess3DWire* psTessWire) +{ + A3D_INITIALIZE_DATA(A3DTess3DWireData, m_sWire3DTessData); + A3DTess3DWireGet(psTessWire, &m_sWire3DTessData); + A3D_INITIALIZE_DATA(A3DTessBaseData, m_sBaseTessData); + A3DTessBaseGet((const A3DTessBase*)psTessWire, &m_sBaseTessData); +} + + +A3DWireTessDataConnector::~A3DWireTessDataConnector() +{ + A3DTess3DWireGet(NULL, &m_sWire3DTessData); + A3DTessBaseGet(NULL, &m_sBaseTessData); +} + + +A3DStatus A3DWireTessDataConnector::Points(double*& pPoint, unsigned int& uSize) const +{ + pPoint = m_sBaseTessData.m_pdCoords; + uSize = m_sBaseTessData.m_uiCoordSize; + return A3D_SUCCESS; +} + +A3DStatus A3DWireTessDataConnector::Indices(std::vector& auPolylineIndices) const +{ + if (!m_sWire3DTessData.m_uiSizesWiresSize) + { + if (m_sBaseTessData.m_uiCoordSize) + { + auPolylineIndices.push_back(0); + auPolylineIndices.push_back(m_sBaseTessData.m_uiCoordSize / 3); + } + return A3D_SUCCESS; + } + + for (unsigned uI = 0; uI < m_sWire3DTessData.m_uiSizesWiresSize;uI++) + { + auPolylineIndices.push_back(m_sWire3DTessData.m_puiSizesWires[uI]); + } + return A3D_SUCCESS; +} + +A3DStatus A3DWireTessDataConnector::Traverse(A3DVisitorContainer* psVisitor) +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + + +A3DStatus A3DTessDataConnector::GetTextureCount(const unsigned& uFaceIndice, unsigned& uCount) const +{ + A3DTessFaceData* pFaceTessData = &(m_sTessData.m_psFaceTessData[uFaceIndice]); + uCount = pFaceTessData->m_uiTextureCoordIndexesSize; + return A3D_SUCCESS; +} \ No newline at end of file diff --git a/exchange/exchangesource/Viewer/traverse/TransfoConnector.cpp b/exchange/exchangesource/Viewer/traverse/TransfoConnector.cpp new file mode 100644 index 0000000..2c8fe44 --- /dev/null +++ b/exchange/exchangesource/Viewer/traverse/TransfoConnector.cpp @@ -0,0 +1,117 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "../TransfoConnector.h" +#include "../Visitors.h" +#include "../Matrix.h" + +static void stInitMatrixFromMiscTransformation(A3DMiscTransformation const * pMiscTransformation, A3DMatrix4x4 &sMatrix) +{ + if (pMiscTransformation) + { + A3DStatus iRet = A3D_SUCCESS; + A3DEEntityType eType = kA3DTypeUnknown; + CALL_A3D_FCTION(A3DEntityGetType, (pMiscTransformation, &eType)); + + switch (eType) + { + case kA3DTypeMiscCartesianTransformation: + { + A3DMiscCartesianTransformationData sData; + A3D_INITIALIZE_DATA(A3DMiscCartesianTransformationData, sData); + + iRet = CALL_A3D_FCTION(A3DMiscCartesianTransformationGet, (pMiscTransformation, &sData)); + + double dMirror = (sData.m_ucBehaviour & kA3DTransformationMirror) ? -1. : 1.; + + A3DVector3dData sZVector; + memset(sMatrix.m_adM, 0, 16 * sizeof(double)); + sZVector = CrossProduct(&(sData.m_sXVector), &(sData.m_sYVector)); + + sMatrix.m_adM[12] = sData.m_sOrigin.m_dX; + sMatrix.m_adM[13] = sData.m_sOrigin.m_dY; + sMatrix.m_adM[14] = sData.m_sOrigin.m_dZ; + + sMatrix.m_adM[0] = sData.m_sXVector.m_dX*sData.m_sScale.m_dX; + sMatrix.m_adM[1] = sData.m_sXVector.m_dY*sData.m_sScale.m_dX; + sMatrix.m_adM[2] = sData.m_sXVector.m_dZ*sData.m_sScale.m_dX; + + sMatrix.m_adM[4] = sData.m_sYVector.m_dX*sData.m_sScale.m_dY; + sMatrix.m_adM[5] = sData.m_sYVector.m_dY*sData.m_sScale.m_dY; + sMatrix.m_adM[6] = sData.m_sYVector.m_dZ*sData.m_sScale.m_dY; + + sMatrix.m_adM[8] = dMirror*sZVector.m_dX*sData.m_sScale.m_dZ; + sMatrix.m_adM[9] = dMirror*sZVector.m_dY*sData.m_sScale.m_dZ; + sMatrix.m_adM[10] = dMirror*sZVector.m_dZ*sData.m_sScale.m_dZ; + + sMatrix.m_adM[15] = 1.; + + iRet = CALL_A3D_FCTION(A3DMiscCartesianTransformationGet, (NULL, &sData)); + } + break; + + case kA3DTypeMiscGeneralTransformation: + { + A3DMiscGeneralTransformationData sData; + A3D_INITIALIZE_DATA(A3DMiscGeneralTransformationData, sData); + + iRet = CALL_A3D_FCTION(A3DMiscGeneralTransformationGet, (pMiscTransformation, &sData)); + + memcpy(&(sMatrix.m_adM[0]), sData.m_adCoeff, 16 * sizeof(double)); + + iRet = CALL_A3D_FCTION(A3DMiscGeneralTransformationGet, (NULL, &sData)); + } + break; + + default: + break; + } + } +} + +A3DTransfoConnector::A3DTransfoConnector(const A3DMiscTransformation* pMiscTransformation) + : A3DConnector(pMiscTransformation) +{ + if (pMiscTransformation) + { + stInitMatrixFromMiscTransformation(pMiscTransformation, m_sLocalMatrix); + } + else + m_sLocalMatrix = stIdentity; +} + +void A3DTransfoConnector::ComputeGlobalMatrix(A3DMatrix4x4 const& rFatherWorldMatrix) +{ + m_sWorldMatrix = rFatherWorldMatrix * m_sLocalMatrix; +} + +void A3DTransfoConnector::SetGlobalMatrix(A3DMatrix4x4 const& rWorldMatrix) +{ + m_sWorldMatrix = rWorldMatrix; +} + +void A3DTransfoConnector::SetGlobalMatrix(A3DMiscTransformation const * pMiscTransformation) +{ + stInitMatrixFromMiscTransformation(pMiscTransformation, m_sWorldMatrix); +} + +A3DStatus A3DTransfoConnector::GetLocalMatrix(A3DMatrix4x4& rsMatrix) +{ + rsMatrix = m_sLocalMatrix; + return A3D_SUCCESS; +} + +A3DStatus A3DTransfoConnector::GetGlobalTransfo(A3DMatrix4x4& rsMatrix) +{ + rsMatrix = m_sWorldMatrix; + return A3D_SUCCESS; +} + diff --git a/exchange/exchangesource/Viewer/traverse/TreeTraverse.cpp b/exchange/exchangesource/Viewer/traverse/TreeTraverse.cpp new file mode 100644 index 0000000..ff301f7 --- /dev/null +++ b/exchange/exchangesource/Viewer/traverse/TreeTraverse.cpp @@ -0,0 +1,507 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file TreeConnector.cpp + +This file contains fuctionalities to traverse a Prc Model Tree + +***********************************************************************************************************************/ + +#include "../TreeTraverse.h" +#include "../VisitorContainer.h" +#include "../callback_opengl.h" + +/************************************************************************************ + +Traverse Model File + +*************************************************************************************/ + +// Traverse all the model tree +A3DStatus A3DModelFileConnector::Traverse(A3DVisitorContainer* psVisitor, bool bVisitPrototype) +{ + unsigned int uI; + psVisitor->visitEnter(*this); + + for (uI = 0; uI < m_sModelFileData.m_uiPOccurrencesSize; uI++) + { + psVisitor->SetCurrentPoFather(NULL); + A3DProductOccurrenceConnector sTreeConnector(m_sModelFileData.m_ppPOccurrences[uI]); + if (sTreeConnector.TraversePO(m_sModelFileData.m_ppPOccurrences[uI], psVisitor, bVisitPrototype) != A3D_SUCCESS) + return A3D_ERROR; + } + psVisitor->visitLeave(*this); + return A3D_SUCCESS; +} + +// Traversing the assembly Structure +A3DStatus A3DProductOccurrenceConnector::TraversePO(const A3DAsmProductOccurrence* pOccurrence, + A3DVisitorContainer* psVisitor, + bool bVisitPrototype) +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + //Traverse AnnotationEntity + A3DUns32 uI; +#ifdef CONNECT_PMI + A3DUns32 uNbAnnotationEntity = m_sProductOccurrenceData.m_uiAnnotationsSize; + for (uI = 0; uI < uNbAnnotationEntity; uI++) + { + A3DMkpAnnotationEntityConnector sAnnotationEntityConnector(m_sProductOccurrenceData.m_ppAnnotations[uI]); + sAnnotationEntityConnector.TraverseAnnotationEntity(psVisitor); + } + if (!uNbAnnotationEntity && m_sProductOccurrenceData.m_pPrototype != NULL) + { + A3DAsmProductOccurrence* pProductPrototype = m_sProductOccurrenceData.m_pPrototype; + while (pProductPrototype) + { + A3DAsmProductOccurrenceData sProductPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductPrototypeData); + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(pProductPrototype, &sProductPrototypeData)); + uNbAnnotationEntity = sProductPrototypeData.m_uiAnnotationsSize; + for (uI = 0; uI < uNbAnnotationEntity; uI++) + { + A3DMkpAnnotationEntityConnector sAnnotationEntityConnector(sProductPrototypeData.m_ppAnnotations[uI]); + sAnnotationEntityConnector.TraverseAnnotationEntity(psVisitor); + } + + pProductPrototype = sProductPrototypeData.m_pPrototype; + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(NULL, &sProductPrototypeData)); + } + } +#endif + +#ifdef CONNECT_VIEWS + A3DUns32 uNbView = m_sProductOccurrenceData.m_uiViewsSize; + if (!uNbView && m_sProductOccurrenceData.m_pPrototype != NULL) + { + A3DAsmProductOccurrence* pProductPrototype = m_sProductOccurrenceData.m_pPrototype; + while (pProductPrototype) + { + A3DAsmProductOccurrenceData sProductPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductPrototypeData); + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(pProductPrototype, &sProductPrototypeData)); + uNbView = sProductPrototypeData.m_uiViewsSize; + for (uI = 0; uI < uNbView; uI++) + { + A3DMkpViewConnector sMkpViewConnector(sProductPrototypeData.m_ppViews[uI]); + sMkpViewConnector.TraverseView(psVisitor); + } + pProductPrototype = sProductPrototypeData.m_pPrototype; + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(NULL, &sProductPrototypeData)); + } + } + else if (uNbView) + { + for (uI = 0; uI < uNbView; uI++) + { + A3DMkpViewConnector sMkpViewConnector(m_sProductOccurrenceData.m_ppViews[uI]); + sMkpViewConnector.TraverseView(psVisitor); + } + } + +#endif + + A3DAsmPartDefinition* pPart = NULL; + if (!bVisitPrototype) + { + CHECK_RET(GetPart(pPart)); + } + else + { + pPart = m_sProductOccurrenceData.m_pPart; + } + if (pPart) + { + void * pEntityInMap = psVisitor->FindInMap(pPart); + psVisitor->SetInMap(pPart, pPart); + A3DPartConnector sPartConnector(pPart); + psVisitor->SetCurrentPoFather(pOccurrence); + sPartConnector.SetProductOccurenceFather(pOccurrence); + + // if we haven't found the part in the map or if we traverse the instance + if (pEntityInMap == NULL || psVisitor->TraverseInstances()) + { + CHECK_RET(sPartConnector.TraversePart(psVisitor)); + } + psVisitor->SetCurrentPoFather(NULL); + } + std::vector apSons; + if (!bVisitPrototype) + { + CollectSons(apSons); + } + else + { + if (m_sProductOccurrenceData.m_pPrototype) + { + if (psVisitor->FindInMap(m_sProductOccurrenceData.m_pPrototype) == NULL) + { + psVisitor->SetInMap(m_sProductOccurrenceData.m_pPrototype, m_sProductOccurrenceData.m_pPrototype); + A3DProductOccurrenceConnector sPrototypeConnector(m_sProductOccurrenceData.m_pPrototype); + sPrototypeConnector.SetPrototypeType(true); + sPrototypeConnector.TraversePO(m_sProductOccurrenceData.m_pPrototype, psVisitor, bVisitPrototype); + } + } + if (m_sProductOccurrenceData.m_pExternalData) + { + if (psVisitor->FindInMap(m_sProductOccurrenceData.m_pExternalData) == NULL) + { + psVisitor->SetInMap(m_sProductOccurrenceData.m_pExternalData, m_sProductOccurrenceData.m_pExternalData); + A3DProductOccurrenceConnector sExternalConnector(m_sProductOccurrenceData.m_pExternalData); + sExternalConnector.SetExternalType(true); + sExternalConnector.TraversePO(m_sProductOccurrenceData.m_pExternalData, psVisitor, bVisitPrototype); + } + } + + + unsigned int uSize = m_sProductOccurrenceData.m_uiPOccurrencesSize; + + for (uI = 0; uI < uSize; uI++) + { + apSons.push_back(m_sProductOccurrenceData.m_ppPOccurrences[uI]); + } + } + + for (uI = 0; uI < apSons.size(); uI++) + { + A3DProductOccurrenceConnector sPoConnector(apSons[uI]); + sPoConnector.SetProductOccurrenceFather(this->GetA3DEntity()); + psVisitor->SetCurrentPoFather(pOccurrence); + CHECK_RET(sPoConnector.TraversePO(apSons[uI], psVisitor, bVisitPrototype)); + psVisitor->SetCurrentPoFather(NULL); + } + CHECK_RET(psVisitor->visitLeave(*this)); + + return A3D_SUCCESS; +} + +A3DStatus A3DProductOccurrenceConnector::CollectSons( + std::vector& apSons) const +{ + //Get Children or children on Prototype's ....Prototype's + A3DAsmProductOccurrence* pPrototype = m_sProductOccurrenceData.m_pPrototype; + A3DAsmProductOccurrence** ppPo = m_sProductOccurrenceData.m_ppPOccurrences; + unsigned int uSize = m_sProductOccurrenceData.m_uiPOccurrencesSize; + A3DStatus iRet = A3D_SUCCESS; + + while (uSize == 0 && pPrototype) + { + A3DAsmProductOccurrenceData sPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sPrototypeData); + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(pPrototype, &sPrototypeData)); + pPrototype = sPrototypeData.m_pPrototype; + + uSize = sPrototypeData.m_uiPOccurrencesSize; + ppPo = sPrototypeData.m_ppPOccurrences; + + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(NULL, &sPrototypeData)); + } + + unsigned uI; + for (uI = 0; uI < uSize; uI++) + apSons.push_back(ppPo[uI]); + + //Get Children on Externals + if (m_sProductOccurrenceData.m_pExternalData) + { + if (apSons.size() == 0) + { + A3DProductOccurrenceConnector sExternalConnector(m_sProductOccurrenceData.m_pExternalData); + CHECK_RET(sExternalConnector.CollectSons(apSons)); + } + else + apSons.push_back(m_sProductOccurrenceData.m_pExternalData); + } + + return A3D_SUCCESS; +} + +A3DStatus A3DProductOccurrenceConnector::GetPart( + A3DAsmPartDefinition*& pPart) const +{ + pPart = NULL; + A3DStatus iRet = A3D_SUCCESS;; + if(m_sProductOccurrenceData.m_pPart) + { + pPart = m_sProductOccurrenceData.m_pPart; + return A3D_SUCCESS; + } + + // Search for first Part found, recursively + A3DAsmProductOccurrence* pProductPrototype = m_sProductOccurrenceData.m_pPrototype; + while(pProductPrototype) + { + A3DAsmProductOccurrenceData sProductPrototypeData; + A3D_INITIALIZE_DATA( A3DAsmProductOccurrenceData, sProductPrototypeData); + CHECK_RET(A3DAsmProductOccurrenceGet(pProductPrototype, &sProductPrototypeData)); + if(sProductPrototypeData.m_pPart) + { + // take current part and return it + pPart = sProductPrototypeData.m_pPart; + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sProductPrototypeData)); + return A3D_SUCCESS; + } + else if (sProductPrototypeData.m_pPrototype) + { + // recurse in prototype if exist + pProductPrototype = sProductPrototypeData.m_pPrototype; + } + else if (sProductPrototypeData.m_pExternalData) + { + // recurse in external if exist + pProductPrototype = sProductPrototypeData.m_pExternalData; + } + else + { + // end recursion + pProductPrototype = NULL; + } + + CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sProductPrototypeData)); + } + + if(m_sProductOccurrenceData.m_uiPOccurrencesSize == 0) + { + if(m_sProductOccurrenceData.m_pExternalData) + { + A3DProductOccurrenceConnector sExternalconnector(m_sProductOccurrenceData.m_pExternalData); + CHECK_RET(sExternalconnector.GetPart(pPart)); + } + } + return A3D_SUCCESS; +} + +A3DStatus A3DPartConnector::TraversePart(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + + CHECK_RET(psVisitor->visitEnter(*this)); + + //Traverse AnnotationEntity + A3DUns32 uI; +#ifdef CONNECT_PMI + A3DUns32 uNbAnnotationEntity = m_sPartData.m_uiAnnotationsSize; + for (uI = 0; uI < uNbAnnotationEntity; uI++) + { + A3DMkpAnnotationEntityConnector sAnnotationEntityConnector(m_sPartData.m_ppAnnotations[uI]); + sAnnotationEntityConnector.TraverseAnnotationEntity(psVisitor); + } +#endif + +#ifdef CONNECT_VIEWS + A3DUns32 uNbView = m_sPartData.m_uiViewsSize; + for (uI = 0; uI < uNbView; uI++) + { + A3DMkpViewConnector sMkpViewConnector(m_sPartData.m_ppViews[uI]); + sMkpViewConnector.TraverseView(psVisitor); + } +#endif + + //Traverse RI + for (uI = 0; uI < m_sPartData.m_uiRepItemsSize; uI++) + { + A3DRiConnector sRiConnector(m_sPartData.m_ppRepItems[uI]); + sRiConnector.TraverseRi(psVisitor); + } + + CHECK_RET(psVisitor->visitLeave(*this)); + return A3D_SUCCESS; +} + +A3DStatus A3DRiConnector::TraverseRi(A3DVisitorContainer* psVisitor) +{ + A3DStatus iRet = A3D_SUCCESS; + psVisitor->visitEnter(*this); + + const A3DEntity* pRi = GetA3DEntity(); + A3DEEntityType eType = kA3DTypeUnknown; + CALL_A3D_FCTION(A3DEntityGetType,(pRi,&eType)); + + if (iRet == A3D_SUCCESS) + { + switch (eType) + { + case kA3DTypeRiBrepModel: + { + A3DRiBrepModelConnector sConnector((A3DRiBrepModel*)pRi); + CHECK_RET(sConnector.TraverseRiBrepModel(psVisitor)); + break; + } + case kA3DTypeRiSet: + { + + A3DRiSetConnector sConnector((A3DRiSet*)pRi); + CHECK_RET(sConnector.TraverseRiSet(psVisitor)); + break; + } + + case kA3DTypeRiCurve: + { + A3DRiCurveConnector sConnector((A3DRiCurve*)pRi); + CHECK_RET(sConnector.TraverseRiCurve(psVisitor)); + break; + } + case kA3DTypeRiPointSet: + case kA3DTypeRiDirection: + case kA3DTypeRiCoordinateSystem: + case kA3DTypeRiPlane: + break; + case kA3DTypeRiPolyBrepModel: + { + A3DPolyRiBrepModelConnector sConnector((A3DRiPolyBrepModel*)pRi); + CHECK_RET(sConnector.TraverseRiPolyBrepModel(psVisitor)); + break; + } + case kA3DTypeRiPolyWire: + { + A3DRiPolyWireConnector sConnector((A3DRiPolyWire*)pRi); + CHECK_RET(sConnector.TraverseRiPolyWire(psVisitor)); + break; + } + default: + iRet = A3D_NOT_IMPLEMENTED; + break; + } + } + psVisitor->visitLeave(*this); + + return A3D_SUCCESS; +} + +// RiBrepModel +A3DStatus A3DRiBrepModelConnector::TraverseRiBrepModel(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + //Traverse Mesh +#ifdef CONNECT_MESH + A3DRiRepresentationItemData sRidata; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, sRidata); + CHECK_RET_CALL_A3D_FCTION(A3DRiRepresentationItemGet,(this->GetA3DEntity(), &sRidata)); + A3DTessDataConnector sTessConnector((A3DTess3D*)sRidata.m_pTessBase); + if (!sRidata.m_pTessBase) + { + CHECK_RET(A3DRiRepresentationItemGet(NULL, &sRidata)); + A3DRWParamsTessellationData sTessParams; + A3D_INITIALIZE_DATA(A3DRWParamsTessellationData, sTessParams); + sTessParams.m_eTessellationLevelOfDetail = kA3DTessLODMedium; + A3DRiRepresentationItemComputeTessellation((A3DRiRepresentationItem*)this->GetA3DEntity(), &sTessParams); + CHECK_RET(A3DRiRepresentationItemGet(this->GetA3DEntity(), &sRidata)); + } + CHECK_RET(sTessConnector.Traverse(psVisitor)); + CHECK_RET_CALL_A3D_FCTION(A3DRiRepresentationItemGet,(NULL, &sRidata)); +#endif + + //Traverse Brep Data +#ifdef CONNECT_BREP + A3DBrepDataConnector sTopoConnector(m_sRiBrepModelData.m_pBrepData); + CHECK_RET(sTopoConnector.Traverse(psVisitor)); + +#endif + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} + +// RiSet +A3DStatus A3DRiSetConnector::TraverseRiSet(A3DVisitorContainer* psVisitor) +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + unsigned uI; + for (uI = 0; uI < m_sRiSetData.m_uiRepItemsSize; uI++) + { + A3DRiConnector sRiConnector(m_sRiSetData.m_ppRepItems[uI]); + sRiConnector.TraverseRi(psVisitor); + } + + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} + +// RiPolyBrepModel +A3DStatus A3DPolyRiBrepModelConnector::TraverseRiPolyBrepModel(A3DVisitorContainer* psVisitor) const +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + + A3DRiRepresentationItemData sRiData; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, sRiData); + CHECK_RET_CALL_A3D_FCTION(A3DRiRepresentationItemGet,(this->GetA3DEntity(), &sRiData)); + A3DTessDataConnector sTessConnector((A3DTess3D*)sRiData.m_pTessBase); + CHECK_RET(sTessConnector.Traverse(psVisitor)); + CHECK_RET_CALL_A3D_FCTION(A3DRiRepresentationItemGet,(NULL, &sRiData)); + + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} + +/////////////////////////////////////////////////////////////////////////////////////// +// RiCurve +/////////////////////////////////////////////////////////////////////////////////////// +A3DStatus A3DRiCurveConnector::TraverseRiCurve(A3DVisitorContainer* psVisitor) +{ + + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + +#ifdef CONNECT_MESH + A3DRiRepresentationItemData sRidata; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, sRidata); + CHECK_RET(A3DRiRepresentationItemGet(this->GetA3DEntity(), &sRidata)); + if (!sRidata.m_pTessBase) + { + CHECK_RET(A3DRiRepresentationItemGet(NULL, &sRidata)); + A3DRWParamsTessellationData sTessParams; + A3D_INITIALIZE_DATA(A3DRWParamsTessellationData, sTessParams); + sTessParams.m_eTessellationLevelOfDetail = kA3DTessLODMedium; + A3DRiRepresentationItemComputeTessellation((A3DRiRepresentationItem*)this->GetA3DEntity(), &sTessParams); + CHECK_RET(A3DRiRepresentationItemGet(this->GetA3DEntity(), &sRidata)); + } + + A3DWireTessDataConnector sWireTessConnector((A3DTess3DWire*)sRidata.m_pTessBase); + CHECK_RET(sWireTessConnector.Traverse(psVisitor)); + + + CHECK_RET(A3DRiRepresentationItemGet(NULL, &sRidata)); +#endif + + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} + +/////////////////////////////////////////////////////////////////////////////////////// +// RiPolyWire +/////////////////////////////////////////////////////////////////////////////////////// +A3DStatus A3DRiPolyWireConnector::TraverseRiPolyWire(A3DVisitorContainer* psVisitor) +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(psVisitor->visitEnter(*this)); + +#ifdef CONNECT_MESH + A3DRiRepresentationItemData sRidata; + A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, sRidata); + CHECK_RET(A3DRiRepresentationItemGet(this->GetA3DEntity(), &sRidata)); + A3DWireTessDataConnector sWireTessConnector((A3DTess3DWire*)sRidata.m_pTessBase); + CHECK_RET(sWireTessConnector.Traverse(psVisitor)); + CHECK_RET(A3DRiRepresentationItemGet(NULL, &sRidata)); +#endif + + CHECK_RET(psVisitor->visitLeave(*this)); + + return iRet; +} \ No newline at end of file diff --git a/exchange/exchangesource/Viewer/traverse/ViewTraverse.cpp b/exchange/exchangesource/Viewer/traverse/ViewTraverse.cpp new file mode 100644 index 0000000..16f4642 --- /dev/null +++ b/exchange/exchangesource/Viewer/traverse/ViewTraverse.cpp @@ -0,0 +1,38 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file ViewTraverse.cpp + +This file contains functionalities to traverse a PRC View + +***********************************************************************************************************************/ + +#include "../VisitorContainer.h" +#include "../ViewTraverse.h" + +class A3DVisitorContainer; + +A3DStatus A3DMkpViewConnector::TraverseView(A3DVisitorContainer* pVisitor) +{ + A3DStatus iRet = A3D_SUCCESS; + CHECK_RET(pVisitor->visitEnter(*this)); + + A3DUns32 uiI; + for (uiI = 0; uiIvisitLeave(*this)); + + return A3D_SUCCESS; +} \ No newline at end of file diff --git a/exchange/exchangesource/Viewer/traverse/VisitorCascadedAttribute.cpp b/exchange/exchangesource/Viewer/traverse/VisitorCascadedAttribute.cpp new file mode 100644 index 0000000..facfeb3 --- /dev/null +++ b/exchange/exchangesource/Viewer/traverse/VisitorCascadedAttribute.cpp @@ -0,0 +1,289 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "../VisitorCascadedAttribute.h" +#include "../CascadedAttributeConnector.h" +#include "../VisitorTree.h" +#include "../VisitorContainer.h" +#include "../TransfoConnector.h" + +#include "../callback_opengl.h" + +A3DVisitorColorMaterials::A3DVisitorColorMaterials(A3DVisitorContainer* psContainer) +: A3DVisitor("CascadedAttribute", psContainer), + m_pCurrentRi(NULL) +{ +} + +A3DVisitorColorMaterials::~A3DVisitorColorMaterials() +{ + std::vector::iterator itCur = m_apsCascadedAttribute.begin(); + std::vector::iterator itEnd = m_apsCascadedAttribute.end(); + for(; itCur < itEnd; ++itCur) + { + CALL_A3D_FCTION(A3DMiscCascadedAttributesDelete,(*itCur)); + } +} + +A3DStatus A3DVisitorColorMaterials::pushCascadedAttribute(const A3DConnector& sEntity) +{ + unsigned int uSize = (unsigned int)m_apsCascadedAttribute.size(); + if(!uSize) + { + A3DMiscCascadedAttributes* pAttr; + CALL_A3D_FCTION(A3DMiscCascadedAttributesCreate,(&pAttr)); + m_apsCascadedAttribute.push_back(pAttr); + uSize++; + } + + A3DMiscCascadedAttributes* pAttr; + CALL_A3D_FCTION(A3DMiscCascadedAttributesCreate,(&pAttr)); + CALL_A3D_FCTION(A3DMiscCascadedAttributesPush,(pAttr, sEntity.GetA3DEntity(), m_apsCascadedAttribute[uSize-1])); + m_apsCascadedAttribute.push_back(pAttr); + + return A3D_SUCCESS; +} + + +A3DStatus A3DVisitorColorMaterials::popCascadedAttribute(/*const A3DConnector& sEntity*/) +{ + if(m_apsCascadedAttribute.size() > 0) + { + CALL_A3D_FCTION(A3DMiscCascadedAttributesDelete,(m_apsCascadedAttribute[m_apsCascadedAttribute.size() - 1])); + m_apsCascadedAttribute.pop_back(); + } + + return A3D_SUCCESS; +} + +// Visit Product Occurrence +A3DStatus A3DVisitorColorMaterials::visitEnter(const A3DProductOccurrenceConnector& sEntity) +{ + pushCascadedAttribute( (const A3DConnector&) sEntity); + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorColorMaterials::visitLeave(const A3DProductOccurrenceConnector& /*sEntity*/) +{ + popCascadedAttribute(); + return A3D_SUCCESS; +} + +// Visit PartDefintion +A3DStatus A3DVisitorColorMaterials::visitEnter(const A3DPartConnector& sEntity) +{ + pushCascadedAttribute((const A3DConnector& ) sEntity); + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorColorMaterials::visitLeave(const A3DPartConnector& /*sEntity*/) +{ + popCascadedAttribute(); + return A3D_SUCCESS; +} + +// Visit Representation Item +A3DStatus A3DVisitorColorMaterials::visitEnter(const A3DRiConnector& sRi) +{ + A3DStatus iRet = A3D_SUCCESS; + m_pCurrentRi = (A3DRiRepresentationItem*)sRi.GetA3DEntity(); + CHECK_RET(pushCascadedAttribute((const A3DConnector&) sRi)); + CHECK_RET(SetGlobalAttributeOnLeaf(m_apsCascadedAttribute[ m_apsCascadedAttribute.size() - 1])); + return iRet; +} + +A3DStatus A3DVisitorColorMaterials::visitLeave(const A3DRiConnector& /*sRi*/) +{ + A3DStatus iRet = A3D_SUCCESS; + m_pCurrentRi = NULL; + CHECK_RET(popCascadedAttribute()); + return A3D_SUCCESS; +} + +// Visit Face Tess Data +A3DStatus A3DVisitorColorMaterials::visitEnter(const A3DFaceTessDataConnector& sFaceTess) +{ + A3DStatus iRet = A3D_SUCCESS; + A3DTessFaceData* pFaceTessData = (A3DTessFaceData*)sFaceTess.GetA3DEntity(); + + if(m_pCurrentRi && !pFaceTessData->m_bIsRGBA && pFaceTessData->m_uiStyleIndexesSize == 1) + { + // Push the Face Tess data + A3DMiscCascadedAttributes* pAttr; + CALL_A3D_FCTION(A3DMiscCascadedAttributesCreate,(&pAttr)); + CALL_A3D_FCTION(A3DMiscCascadedAttributesPushTessFace,(pAttr, + m_pCurrentRi, + (A3DTess3D*)sFaceTess.GetTessDataConnector()->GetA3DEntity(), + (A3DTessFaceData*)sFaceTess.GetA3DEntity(), + sFaceTess.GetFaceIndex(), + m_apsCascadedAttribute[m_apsCascadedAttribute.size()-1])); + m_apsCascadedAttribute.push_back(pAttr); + + CHECK_RET(SetGlobalAttributeOnLeaf(m_apsCascadedAttribute[ m_apsCascadedAttribute.size() - 1])); + } + + ////////////////////////////////////////////////////////////// + // Get Colors / Materials - PLEASE, ADD your sources HERE + ////////////////////////////////////////////////////////////// + + if(GetstbUseCallbacks()) + { + A3DVisitorColorMaterials* pVisitorColorAndMaterials = (A3DVisitorColorMaterials *)m_psContainer->GetVisitor()[1]; + ColorMaterialsConnector sColorMaterialConnec(pVisitorColorAndMaterials->GetLastCascadedAttributes()); + pVisitorColorAndMaterials->GetColorMaterialConnector(sColorMaterialConnec, false); + + if (sColorMaterialConnec.IsShow()) + { + if(sColorMaterialConnec.IsRGBColor()) + { + double adRGB[3]; + sColorMaterialConnec.GetRGB(adRGB); + OpenGL_Material(kA3DDrawMaterialDiffuse, adRGB, 3); + } + else + { + double adEmisive[4], adDiffuse[4], adAmbient[4], adSpecular[4], dShininess; + sColorMaterialConnec.GetMaterial(adEmisive, adDiffuse, adAmbient, adSpecular, dShininess ); + OpenGL_Material(kA3DDrawMaterialDiffuse, adDiffuse, 4); + OpenGL_Material(kA3DDrawMaterialAmbient, adAmbient, 4); + OpenGL_Material(kA3DDrawMaterialEmission, adEmisive, 4); + OpenGL_Material(kA3DDrawMaterialSpecular, adSpecular, 4); + OpenGL_Material(kA3DDrawMaterialShininess, &dShininess, 1); + } + } + + } + + /////////////////////////////////////////////////////////////////////////////// + + return iRet; +} + +A3DStatus A3DVisitorColorMaterials::visitLeave(const A3DFaceTessDataConnector& sFaceTess) +{ + A3DStatus iRet = A3D_SUCCESS; + A3DTessFaceData* pFaceTessData = (A3DTessFaceData*)sFaceTess.GetA3DEntity(); + if(!pFaceTessData->m_bIsRGBA && pFaceTessData->m_uiStyleIndexesSize == 1) + { + CHECK_RET(popCascadedAttribute()); + } + return A3D_SUCCESS; +} + +A3DMiscCascadedAttributes* A3DVisitorColorMaterials::GetLastCascadedAttributes() const +{ + size_t iSize = m_apsCascadedAttribute.size(); + if(iSize == 0) + return NULL; + return m_apsCascadedAttribute[iSize-1]; +} + +A3DStatus A3DVisitorColorMaterials::GetColorMaterialConnector( ColorMaterialsConnector& rsColorConnector, + bool bUseInstances /*= false*/ ) +{ + A3DStatus iErr = A3D_SUCCESS; + size_t iSize = m_apsCascadedAttribute.size(); + if(iSize == 0) + return A3D_ERROR; + A3DMiscCascadedAttributes* pCurrent = m_apsCascadedAttribute[iSize-1]; + + if(!bUseInstances) + { + A3DMiscEntityReference* pMER = NULL; + A3DStepEntityRefManager const * pSERM = m_psContainer->GetActiveStepEntityRefManager(NULL); + if (pSERM) + { + pMER = pSERM->m_pStepEntityRef; + } + + A3DViewLinkedItemManager const* pVLIM = m_psContainer->GetActiveViewLinkedItemManager(NULL); + if (pVLIM) + { + pMER = pVLIM->m_pMarkupLinkedItem; + } + + if (pMER) + { + A3DMiscEntityReferenceData sSERData; + A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sSERData); + iErr = CALL_A3D_FCTION(A3DMiscEntityReferenceGet,(pMER, &sSERData)); + if(iErr == A3D_SUCCESS) + { + A3DEEntityType eType; + CALL_A3D_FCTION(A3DEntityGetType,( pMER, &eType)); + if(eType == kA3DTypeMiscEntityReference || eType==kA3DTypeMiscMarkupLinkedItem) + { + A3DMiscReferenceOnTopologyData sTopoRefData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnTopologyData,sTopoRefData); + iErr = CALL_A3D_FCTION(A3DMiscReferenceOnTopologyGet,(pMER, &sTopoRefData)); + if(iErr == A3D_SUCCESS) // topo + { + switch(sTopoRefData.m_eTopoItemType) + { + case kA3DTypeTopoMultipleVertex: + case kA3DTypeTopoUniqueVertex: + case kA3DTypeTopoWireEdge: + case kA3DTypeTopoEdge: + case kA3DTypeTopoLoop: + break; + case kA3DTypeTopoFace: + { + A3DTopoBrepData* pBrepData = sTopoRefData.m_pBrepData; + A3DTopoBrepDataData sTopoBrepDataData; + A3D_INITIALIZE_DATA( A3DTopoBrepDataData,sTopoBrepDataData); + CALL_A3D_FCTION(A3DTopoBrepDataGet,(pBrepData,&sTopoBrepDataData)); + + CALL_A3D_FCTION(A3DTopoBrepDataGet,(NULL,&sTopoBrepDataData)); + + break; + } + case kA3DTypeTopoShell: + { + break; + } + case kA3DTypeTopoConnex: + { + break; + } + default: + { + break; + } + } + } + else // no topo -> global PO/Part/RI/RIBrepModel + { + A3DEEntityType eEType; + CALL_A3D_FCTION(A3DEntityGetType,( sSERData.m_pEntity, &eEType)); + + //A3DGraphStyleData + A3DMiscCascadedAttributes* pAttr = NULL; + CALL_A3D_FCTION(A3DMiscCascadedAttributesCreate,(&pAttr)); + iErr = CALL_A3D_FCTION(A3DMiscCascadedAttributesPush,(pAttr, pMER, pCurrent)); + A3DMiscCascadedAttributesData sCAData; + A3D_INITIALIZE_DATA(A3DMiscCascadedAttributesData, sCAData); + iErr = CALL_A3D_FCTION(A3DMiscCascadedAttributesGet,(pAttr, &sCAData)); + rsColorConnector = ColorMaterialsConnector(pAttr); + } + + CALL_A3D_FCTION(A3DMiscReferenceOnTopologyGet,(NULL, + &sTopoRefData)); + } + CALL_A3D_FCTION(A3DMiscEntityReferenceGet,( NULL, &sSERData)); + } + } + else + rsColorConnector = ColorMaterialsConnector(pCurrent); + } + + return A3D_SUCCESS; +} diff --git a/exchange/exchangesource/Viewer/traverse/VisitorContainer.cpp b/exchange/exchangesource/Viewer/traverse/VisitorContainer.cpp new file mode 100644 index 0000000..c53d0df --- /dev/null +++ b/exchange/exchangesource/Viewer/traverse/VisitorContainer.cpp @@ -0,0 +1,610 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "../VisitorContainer.h" +#include "../Visitors.h" + + +#ifdef CONNECT_BREP +#include "../VisitorBrep.h" +#endif +#ifdef CONNECT_TRANSFO +#include "../VisitorTransfo.h" +#endif +#ifdef CONNECT_COLORS +#include "../VisitorCascadedAttribute.h" +#endif +#ifdef CONNECT_ASSEMBLY_TREE +#include "../VisitorTree.h" +#endif +#ifdef CONNECT_MESH +#include "../VisitorTessellation.h" +#endif +#ifdef CONNECT_PMI +#include "../ViewTraverse.h" +#endif + +#include +#include + +using namespace std; + +#define VISITENTER \ +{\ + ActivateEntityReference(sConnector.GetA3DEntity()); \ + for(unsigned uI = 0; uI < m_apVisitor.size(); uI++)\ + m_apVisitor[uI]->visitEnter(sConnector);\ + return A3D_SUCCESS;\ +} + +#define VISITLEAVE \ +{\ + DeactivateEntityReference(sConnector.GetA3DEntity()); \ + for(unsigned uI = 0; uI < m_apVisitor.size(); uI++)\ + m_apVisitor[uI]->visitLeave(sConnector);\ + return A3D_SUCCESS;\ +} + +//Tree +#ifdef CONNECT_ASSEMBLY_TREE + +static A3DStatus stCreateAndPushCascadedAttributes( const A3DRootBaseWithGraphics* pBase, + const A3DMiscCascadedAttributes* pFatherAttr, + A3DMiscCascadedAttributes** ppAttr, + A3DMiscCascadedAttributesData* psAttrData) +{ + A3DStatus iRet = A3D_SUCCESS; + + CHECK_RET(A3DMiscCascadedAttributesCreate(ppAttr)); + CHECK_RET(A3DMiscCascadedAttributesPush(*ppAttr, pBase, pFatherAttr)); + + A3D_INITIALIZE_DATA(A3DMiscCascadedAttributesData, (*psAttrData)); + CHECK_RET(A3DMiscCascadedAttributesGet(*ppAttr, psAttrData)); + + return iRet; +} + +A3DStatus A3DVisitorContainer::visitEnter(const A3DModelFileConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitEnter(const A3DProductOccurrenceConnector& sConnector) +{ + m_uiCurrentLevel++; + + // Entity Reference + unsigned int uI, uNbRefEntity = sConnector.m_sProductOccurrenceData.m_uiEntityReferenceSize; + for(uI = 0; uI < uNbRefEntity; uI++) + { + A3DMiscEntityReferenceData sMiscRefData; + A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sMiscRefData); + A3DMiscEntityReference* pEntityRef = sConnector.m_sProductOccurrenceData.m_ppEntityReferences[uI]; + A3DMiscEntityReferenceGet(pEntityRef, &sMiscRefData); + A3DStepEntityRefManager sEntityManager; + sEntityManager.m_pStepEntityRef = pEntityRef; + sEntityManager.m_uiPOLevel = m_uiCurrentLevel; + + A3DEEntityType sType; + A3DEntityGetType(sMiscRefData.m_pEntity, &sType); + if(sType == kA3DTypeMiscReferenceOnTopology) + { + A3DMiscReferenceOnTopologyData sTopoRefData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnTopologyData,sTopoRefData); + A3DMiscReferenceOnTopologyGet(pEntityRef, &sTopoRefData); + sEntityManager.m_pA3DEntityRef = sTopoRefData.m_pBrepData; + sEntityManager.m_bRefOnTopoItem = true; + A3DMiscReferenceOnTopologyGet(NULL, &sTopoRefData); + } + else if(sType == kA3DTypeMiscReferenceOnCsysItem) + { + A3DMiscReferenceOnCsysItemData sA3DMiscReferenceOnCSYSITemData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnCsysItemData, sA3DMiscReferenceOnCSYSITemData); + A3DMiscReferenceOnCsysItemGet(pEntityRef, &sA3DMiscReferenceOnCSYSITemData); + sEntityManager.m_pA3DEntityRef = sA3DMiscReferenceOnCSYSITemData.m_pCoordinateSystem; + A3DMiscReferenceOnCsysItemGet(NULL, &sA3DMiscReferenceOnCSYSITemData); + } + else + sEntityManager.m_pA3DEntityRef = sMiscRefData.m_pEntity; + + A3DMiscEntityReferenceGet(NULL, &sMiscRefData); + + m_asStepEntityRefManager.push_back(sEntityManager); + } + + A3DStatus iRet = A3D_SUCCESS; + + // Active View ... + if (m_psActivatedView) + { + A3DUns32 uNbView = sConnector.m_sProductOccurrenceData.m_uiViewsSize; + for (uI = 0; uI < uNbView; uI++) + { + if (sConnector.m_sProductOccurrenceData.m_ppViews[uI] != m_psActivatedView) + continue; + + A3DMkpViewConnector sMkpViewConnector(sConnector.m_sProductOccurrenceData.m_ppViews[uI]); + sMkpViewConnector.TraverseView(this); + } + } + + ActivateEntityReference(sConnector.GetA3DEntity()); + for( uI = 0; uI < m_apVisitor.size(); uI++) + { + m_apVisitor[uI]->visitEnter(sConnector); + } + + return iRet; +} + +A3DStatus A3DVisitorContainer::visitEnter(const A3DPartConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DRiConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DRiBrepModelConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DRiSetConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DPolyRiBrepModelConnector& sConnector) +VISITENTER + + +A3DStatus A3DVisitorContainer::visitLeave(const A3DModelFileConnector& sConnector) +VISITLEAVE + +A3DStatus A3DVisitorContainer::visitLeave(const A3DProductOccurrenceConnector& sConnector) +{ + for(unsigned uI = 0; uI < m_apVisitor.size(); uI++) + { + m_apVisitor[uI]->visitLeave(sConnector); + } + + unsigned int uI, uNbRefEntity = sConnector.m_sProductOccurrenceData.m_uiEntityReferenceSize; + for (uI = 0; uI < uNbRefEntity; uI++) + { + m_asStepEntityRefManager.pop_back(); + } + + if (m_psActivatedView != NULL) + { + A3DUns32 uNbView = sConnector.m_sProductOccurrenceData.m_uiViewsSize; + for (uI = 0; uI < uNbView; uI++) + { + if (sConnector.m_sProductOccurrenceData.m_ppViews[uI]!=m_psActivatedView) + continue; + + A3DMkpViewConnector sViewConnector(m_psActivatedView); + unsigned int uJ; + uNbRefEntity = sViewConnector.GetViewData().m_uiLinkedItemsSize; + for (uJ = 0; uJ < uNbRefEntity; uJ++) + { + m_asViewLinkedItemManager.pop_back(); + } + } + } + + DeactivateEntityReference(sConnector.GetA3DEntity()); + + m_uiCurrentLevel--; + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorContainer::visitLeave(const A3DPartConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DRiConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DRiBrepModelConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DRiSetConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DPolyRiBrepModelConnector& sConnector) +VISITLEAVE +#endif + +//Markup +#ifdef CONNECT_PMI +A3DStatus A3DVisitorContainer::visitEnter(const A3DMkpAnnotationEntityConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMkpAnnotationSetConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMkpAnnotationItemConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMarkupConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMarkupDimensionConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMarkupGDTConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMarkupDatumConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMarkupTessConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitLeave(const A3DMkpAnnotationEntityConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMkpAnnotationSetConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMkpAnnotationItemConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMarkupDimensionConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMarkupConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMarkupGDTConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMarkupDatumConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMarkupTessConnector& sConnector) +VISITLEAVE + +#endif + +//Brep +#ifdef CONNECT_BREP +A3DStatus A3DVisitorContainer::visitEnter(const A3DBrepDataConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DConnexConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DShellConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DFaceConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DLoopConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DCoEdgeConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DEdgeConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DUniqueVertexConnector& sConnector) +VISITENTER +A3DStatus A3DVisitorContainer::visitEnter(const A3DMultipleVertexConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitLeave(const A3DBrepDataConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DConnexConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DShellConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DFaceConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DLoopConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DCoEdgeConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DEdgeConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DUniqueVertexConnector& sConnector) +VISITLEAVE +A3DStatus A3DVisitorContainer::visitLeave(const A3DMultipleVertexConnector& sConnector) +VISITLEAVE +#endif + +//Mesh +#ifdef CONNECT_MESH +A3DStatus A3DVisitorContainer::visitEnter(const A3DTessDataConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitLeave(const A3DTessDataConnector& sConnector) +VISITLEAVE + +A3DStatus A3DVisitorContainer::visitEnter(const A3DFaceTessDataConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitLeave(const A3DFaceTessDataConnector& sConnector) +VISITLEAVE + +A3DStatus A3DVisitorContainer::visitEnter(const A3DWireTessDataConnector& sConnector) +VISITENTER + +A3DStatus A3DVisitorContainer::visitLeave(const A3DWireTessDataConnector& sConnector) +VISITLEAVE + +//VISIT(const A3DTessDataConnector&) +#endif + +A3DVisitorContainer::A3DVisitorContainer(unsigned int uFlagElementToconnect) +: A3DVisitor("Container"), + m_pTreeVisitor(NULL), + m_pCurrentPOFather(NULL), + m_psActivatedView(NULL), + m_bTraverseActivatedViewOnly(true), + m_uiCurrentLevel(0) +{ +#ifdef CONNECT_TRANSFO + if(uFlagElementToconnect&CONNECT_TRANSFO) + { + A3DVisitorTransfo* psVisistorTransfo = new A3DVisitorTransfo(this); + this->push( psVisistorTransfo); + } +#endif +#ifdef CONNECT_COLORS + if(uFlagElementToconnect&CONNECT_COLORS) + { + A3DVisitorColorMaterials* psVisitorcascadedAttribute = new A3DVisitorColorMaterials(this); + this->push( psVisitorcascadedAttribute); + } +#endif +#ifdef CONNECT_MESH + if(uFlagElementToconnect&CONNECT_MESH) + { + A3DVisitorTessellation* psVisitorTessellation = new A3DVisitorTessellation(this); + this->push( psVisitorTessellation); + } +#endif +#ifdef CONNECT_BREP + if(uFlagElementToconnect&CONNECT_BREP) + { + A3DVisitorBrep* psVisitorBrep = new A3DVisitorBrep(this); + this->push( psVisitorBrep); + } +#endif +#ifdef CONNECT_ASSEMBLY_TREE + if(uFlagElementToconnect&CONNECT_ASSEMBLY_TREE) + { + A3DTreeVisitor* psVisitorTree= new A3DTreeVisitor(this); + this->push( psVisitorTree); + } +#endif +#ifdef CONNECT_PMI + if(uFlagElementToconnect&CONNECT_PMI) + { + //A3DVisitorPMI* psVisitorPMI = new A3DVisitorPMI(this); + //this->push( psVisitorPMI ); + } +#endif +#ifdef CONNECT_VIEWS + if(uFlagElementToconnect&CONNECT_VIEWS) + { + // Not yet Implemented + // A3DVisitorview* psVisitorViews = new A3DVisitorview(this); + // this->push( psVisitorViews); + } + m_bTraverseInstance = true; +#endif +} + +#ifdef CONNECT_VIEWS + +A3DStatus A3DVisitorContainer::visitEnter(const A3DMkpViewConnector& sConnector) +{ + if ((m_psActivatedView == NULL) || (m_psActivatedView != sConnector.GetA3DEntity())) + { + if (!m_bTraverseActivatedViewOnly) + { + VISITENTER; + } + + return A3D_SUCCESS; + } + + // VISITENTER + ActivateEntityReference(sConnector.GetA3DEntity()); + for (unsigned uI = 0; uI < m_apVisitor.size(); uI++) + { + m_apVisitor[uI]->visitEnter(sConnector); + } + + unsigned int uI, uNbRefEntity = sConnector.GetViewData().m_uiLinkedItemsSize; + for (uI = 0; uI < uNbRefEntity; uI++) + { + A3DMiscMarkupLinkedItemData sMkpLinkedItemData; + A3D_INITIALIZE_DATA(A3DMiscMarkupLinkedItemData, sMkpLinkedItemData); + A3DMiscMarkupLinkedItem* pMkpLinkedItemEntityRef = sConnector.GetViewData().m_ppLinkedItems[uI]; + A3DMiscMarkupLinkedItemGet(pMkpLinkedItemEntityRef, &sMkpLinkedItemData); + A3DViewLinkedItemManager sViewLinkedItemManager; + + A3DMiscEntityReferenceData sMiscRefData; + A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sMiscRefData); + A3DMiscEntityReferenceGet(pMkpLinkedItemEntityRef, &sMiscRefData); + + sViewLinkedItemManager.m_pA3DEntityRef = sMiscRefData.m_pEntity; + sViewLinkedItemManager.m_POOwner = sMkpLinkedItemData.m_pTargetProductOccurrence; + sViewLinkedItemManager.m_pMarkupLinkedItem = pMkpLinkedItemEntityRef; + sViewLinkedItemManager.m_uiPOLevel = m_uiCurrentLevel; + + A3DEEntityType sType; + A3DEntityGetType(sMiscRefData.m_pEntity, &sType); + if (sType == kA3DTypeMiscReferenceOnTopology) + { + A3DMiscReferenceOnTopologyData sTopoRefData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnTopologyData, sTopoRefData); + A3DMiscReferenceOnTopologyGet(sMiscRefData.m_pEntity, &sTopoRefData); + sViewLinkedItemManager.m_pA3DEntityRef = sTopoRefData.m_pBrepData; + sViewLinkedItemManager.m_bRefOnTopoItem = true; + A3DMiscReferenceOnTopologyGet(NULL, &sTopoRefData); + } + else if (sType == kA3DTypeMiscReferenceOnCsysItem) + { + A3DMiscReferenceOnCsysItemData sA3DMiscReferenceOnCSYSITemData; + A3D_INITIALIZE_DATA(A3DMiscReferenceOnCsysItemData, sA3DMiscReferenceOnCSYSITemData); + A3DMiscReferenceOnCsysItemGet(sMiscRefData.m_pEntity, &sA3DMiscReferenceOnCSYSITemData); + sViewLinkedItemManager.m_pA3DEntityRef = sA3DMiscReferenceOnCSYSITemData.m_pCoordinateSystem; + A3DMiscReferenceOnCsysItemGet(NULL, &sA3DMiscReferenceOnCSYSITemData); + } + else + sViewLinkedItemManager.m_pA3DEntityRef = sMiscRefData.m_pEntity; + + A3DMiscEntityReferenceGet(NULL, &sMiscRefData); + + m_asViewLinkedItemManager.push_back(sViewLinkedItemManager); + } + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorContainer::visitLeave(const A3DMkpViewConnector& sConnector) +{ + if ((m_psActivatedView == NULL) || (m_psActivatedView != sConnector.GetA3DEntity())) + { + if (!m_bTraverseActivatedViewOnly) + VISITLEAVE; + + return A3D_SUCCESS; + } + + VISITLEAVE; +} + +#endif + +void A3DVisitorContainer::push( A3DVisitor* psVisitor ) +{ +// vector::iterator iter = +// search(m_apVisitor.begin(), m_apVisitor.end(), &psVisitor, &psVisitor+1); +// if(iter == m_apVisitor.end()) +// { +// m_apVisitorExcludedForDelete.push_back(psVisitor); +// } + m_apVisitor.push_back(psVisitor); + if(!m_pTreeVisitor) + m_pTreeVisitor = (A3DVisitor*)dynamic_cast(psVisitor);//dynamic_cast return null if failed. +} + + +A3DVisitorContainer::~A3DVisitorContainer() +{ + size_t uI, uNbVisitor = m_apVisitor.size(); +// vector::iterator iter; + for(uI = 0; uI < uNbVisitor; uI++) +// { +// iter = search( m_apVisitorExcludedForDelete.begin(), +// m_apVisitorExcludedForDelete.end(), +// &m_apVisitor[uI], +// &m_apVisitor[uI]+1); +// if(iter == m_apVisitorExcludedForDelete.end()) + delete m_apVisitor[uI]; +// } +} + + +void* A3DVisitorContainer::FindInMap(const A3DEntity* pA3DEntity) +{ + map::iterator my_mapIter; + my_mapIter = m_apA3DEntityYourEntityMap.find(pA3DEntity); + if(my_mapIter == m_apA3DEntityYourEntityMap.end()) + return NULL; + return my_mapIter->second; +} + +void A3DVisitorContainer::SetInMap(const A3DEntity* pA3DEntity, void* pYourEntity) +{ + m_apA3DEntityYourEntityMap.insert(std::pair(pA3DEntity, pYourEntity)); +} + +A3DVisitor* A3DVisitorContainer::GetVisitorByName( std::string strName ) +{ + vector::iterator iter = m_apVisitor.begin(); + for( ; iter != m_apVisitor.end(); ++iter) + if(strName.compare((*iter)->GetName()) == 0) + return *iter; + return NULL; +} + +A3DVisitor* A3DVisitorContainer::GetTreeVisitor() const +{ + return m_pTreeVisitor; +} + +void A3DVisitorContainer::ActivateEntityReference( A3DEntity const* pEntity ) +{ + // StepEntityReference + size_t uI, uNbPushStepEntityRef = m_asStepEntityRefManager.size(); + for(uI = 0; uI < uNbPushStepEntityRef; uI++) + { + if(m_asStepEntityRefManager[uI].m_pA3DEntityRef == pEntity) + { + m_asStepEntityRefManager[uI].m_uiPushLevel = m_uiCurrentLevel; + } + } + + // ViewLinkedItem + size_t uNbPushViewLMkpLinkedItem = m_asViewLinkedItemManager.size(); + for (uI = 0; uI < uNbPushViewLMkpLinkedItem; uI++) + { + A3DViewLinkedItemManager *pCurManager = &m_asViewLinkedItemManager[uI]; + if (pCurManager->m_pA3DEntityRef == pEntity && + ( pCurManager->m_POOwner == NULL || + pCurManager->m_POOwner == pEntity || + pCurManager->m_POOwner == m_pCurrentPOFather + ) + ) + { + pCurManager->m_uiPushLevel = m_uiCurrentLevel; + } + } +} + +void A3DVisitorContainer::DeactivateEntityReference( A3DEntity const* pEntity ) +{ + // StepEntityReference + size_t uI, uNbPushStepEntityRef = m_asStepEntityRefManager.size(); + for(uI = 0; uI < uNbPushStepEntityRef; uI++) + { + if(m_asStepEntityRefManager[uI].m_pA3DEntityRef == pEntity) + { + m_asStepEntityRefManager[uI].m_uiPushLevel = ~0U; + } + } + + // ViewLinkedItem + size_t uNbPushViewLMkpLinkedItem = m_asViewLinkedItemManager.size(); + for (uI = 0; uI < uNbPushViewLMkpLinkedItem; uI++) + { + A3DViewLinkedItemManager *pCurManager = &m_asViewLinkedItemManager[uI]; + if (pCurManager->m_pA3DEntityRef == pEntity && + ( pCurManager->m_POOwner == NULL || + pCurManager->m_POOwner == pEntity || + pCurManager->m_POOwner == m_pCurrentPOFather + ) + ) + { + pCurManager->m_uiPushLevel = ~0U; + } + } +} + +A3DStepEntityRefManager const* A3DVisitorContainer::GetActiveStepEntityRefManager(A3DEntity const * pEntity) const +{ + A3DStepEntityRefManager const * psActivated = NULL; + size_t uI, uNbPushStepEntityRef = m_asStepEntityRefManager.size(); + for(uI = 0; uI < uNbPushStepEntityRef; uI++) + { + A3DStepEntityRefManager const * psCurManager = &m_asStepEntityRefManager[uI]; + if (psCurManager->m_uiPushLevel!=~0U && (pEntity==NULL || psCurManager->m_pA3DEntityRef==pEntity)) + { + if (!psActivated) + psActivated = psCurManager; + else if (psCurManager->IsFirst(*psActivated)) + psActivated = psCurManager; + } + } + return psActivated; +} + +A3DViewLinkedItemManager const* A3DVisitorContainer::GetActiveViewLinkedItemManager(A3DEntity const * pEntity) const +{ + A3DViewLinkedItemManager const * psActivated = NULL; + + size_t uI, uNbPushViewMarkupLinkedItem = m_asViewLinkedItemManager.size(); + for (uI = 0; uI < uNbPushViewMarkupLinkedItem; uI++) + { + A3DViewLinkedItemManager const * psCurManager = &m_asViewLinkedItemManager[uI]; + if (psCurManager->m_uiPushLevel!=~0U && (pEntity==NULL || psCurManager->m_pA3DEntityRef==pEntity)) + { + if (!psActivated) + psActivated = psCurManager; + else if (psCurManager->IsFirst(*psActivated)) + psActivated = psCurManager; + } + } + + return psActivated; +} \ No newline at end of file diff --git a/exchange/exchangesource/Viewer/traverse/VisitorTessellation.cpp b/exchange/exchangesource/Viewer/traverse/VisitorTessellation.cpp new file mode 100644 index 0000000..015704c --- /dev/null +++ b/exchange/exchangesource/Viewer/traverse/VisitorTessellation.cpp @@ -0,0 +1,321 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "../VisitorTessellation.h" +#include "../TessConnector.h" +#include "../VisitorCascadedAttribute.h" +#include "../VisitorTransfo.h" +#include "../VisitorContainer.h" +#include "../TransfoConnector.h" +#include "../CascadedAttributeConnector.h" +#include "../MarkupTessConnector.h" + +#include "../callback_opengl.h" + +A3DStatus A3DVisitorTessellation::visitEnter(const A3DFaceTessDataConnector& sFaceTessConnector) +{ + const A3DTessDataConnector * psTessDataConnector = sFaceTessConnector.GetTessDataConnector(); + + A3DStatus iRet = A3D_SUCCESS; + unsigned int uPointSize, uNormalSize, uUVSize; + double* pdPoint, *pdNormal, *pdUV; + + CHECK_RET(psTessDataConnector->Points(pdPoint, uPointSize)); + CHECK_RET(psTessDataConnector->Normals(pdNormal, uNormalSize)); + CHECK_RET(psTessDataConnector->UV(pdUV, uUVSize)); + + std::vector auTriangleWithPointNormalindices; + std::vector auTriangleWithPointNormalUVindices; + unsigned uTextureCount = 0; + CHECK_RET(psTessDataConnector->GetTextureCount(sFaceTessConnector.GetFaceIndex(), uTextureCount)); + CHECK_RET(psTessDataConnector->IndicesPerFaceAsTriangle(sFaceTessConnector.GetFaceIndex(), + auTriangleWithPointNormalindices, + auTriangleWithPointNormalUVindices)); + + /////////////////////////////////////////////////////////////// + // Draw the tessellation - PLEASE, ADD your sources HERE + /////////////////////////////////////////////////////////////// + //manage the visibility of the items + + if (m_bShow) + { + // Draw all the triangles of the model (we're not reading the UV for now) + if (auTriangleWithPointNormalindices.size() != 0) + OpenGL_Triangle(pdNormal, uNormalSize, pdPoint, uPointSize, auTriangleWithPointNormalindices, uTextureCount); + if (auTriangleWithPointNormalUVindices.size() != 0) + OpenGL_Triangle(pdNormal, uNormalSize, pdPoint, uPointSize, auTriangleWithPointNormalUVindices, uTextureCount); + } + /////////////////////////////////////////////////////////////// + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTessellation::visitLeave(const A3DFaceTessDataConnector& /*sTessConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTessellation::visitEnter(const A3DTessDataConnector& sTessConnector) +{ + /////////////////////////////////////////////////////////////// + // Get the bounding box - PLEASE, ADD your sources HERE + /////////////////////////////////////////////////////////////// + A3DStatus iRet = A3D_SUCCESS; + unsigned int uPointSize, uNormalSize, uUVSize, uFaceSize; + double* pdPoint, *pdNormal, *pdUV; + CHECK_RET(sTessConnector.Points(pdPoint, uPointSize)); + CHECK_RET(sTessConnector.Normals(pdNormal, uNormalSize)); + CHECK_RET(sTessConnector.UV(pdUV, uUVSize)); + uFaceSize = sTessConnector.FacesSize(); + + /////////////////////////////////////////////////////////////// + // Get the Bounding Box - PLEASE, ADD your sources HERE + /////////////////////////////////////////////////////////////// + if(!GetstbUseCallbacks()) + { + if (m_bShow) + { + A3DVisitorTransfo* psVisitorTransfo = (A3DVisitorTransfo*) m_psContainer->GetVisitor()[0]; + A3DTransfoConnector* pConnector = psVisitorTransfo->GetTransfoConnector(); + A3DMatrix4x4 sGlobalTransfo; + A3DMatrix4x4 sLocalTransfo; + pConnector->GetGlobalTransfo(sGlobalTransfo); + //pConnector->GetLocalMatrix(sLocalTransfo); + delete pConnector; + + A3DVector3d sCurrentPt; + for(unsigned int uI = 0; uI < uPointSize/3; uI++) + { + sCurrentPt.set(pdPoint[uI*3], pdPoint[uI*3 + 1], pdPoint[uI*3+2]); + sCurrentPt = sGlobalTransfo * sCurrentPt; + stBoundingBoxAddPoint(GetstpsBoundingBox(), sCurrentPt.x, sCurrentPt.y, sCurrentPt.z); + } + } + } + else + { + A3DVisitorTransfo* psVisitorTransfo = (A3DVisitorTransfo*) m_psContainer->GetVisitor()[0]; + A3DTransfoConnector* pConnector = psVisitorTransfo->GetTransfoConnector(); + A3DMatrix4x4 sGlobalTransfo; + pConnector->GetGlobalTransfo(sGlobalTransfo); + delete pConnector; + + OpenGL_PushMatrix(); + OpenGL_MultMatrix(sGlobalTransfo.m_adM); + } + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTessellation::visitLeave(const A3DTessDataConnector& /*sTessConnector*/) +{ + if(GetstbUseCallbacks()) + OpenGL_PopMatrix(); + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTessellation::visitEnter(const A3DRiConnector& /*sTessConnector*/) +{ + A3DVisitorColorMaterials* pVisitorColorAndMaterials = (A3DVisitorColorMaterials *)m_psContainer->GetVisitor()[1]; + ColorMaterialsConnector sColorMaterialConnec(pVisitorColorAndMaterials->GetLastCascadedAttributes()); + if (sColorMaterialConnec.IsShow() && !sColorMaterialConnec.IsRemoved()) + m_bShow = true; + else + m_bShow = false; + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTessellation::visitLeave(const A3DRiConnector& /*sTessConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTessellation::visitEnter(const A3DMarkupTessConnector& sMarkupTessConnector) +{ + A3DVisitorColorMaterials* pVisitorColorAndMaterials = (A3DVisitorColorMaterials *)m_psContainer->GetVisitor()[1]; + ColorMaterialsConnector sColorMaterialConnec(pVisitorColorAndMaterials->GetLastCascadedAttributes()); + if (sColorMaterialConnec.IsShow() && !sColorMaterialConnec.IsRemoved()) + m_bShow = true; + else + m_bShow = false; + + if (GetstbDrawMarkups()) + { + // Get the bounding box + if(!GetstbUseCallbacks()) + { + A3DVisitorTransfo* psVisitorTransfo = (A3DVisitorTransfo*) m_psContainer->GetVisitor()[0]; + A3DTransfoConnector* pConnector = psVisitorTransfo->GetTransfoConnector(); + A3DMatrix4x4 sGlobalTransfo; + A3DMatrix4x4 sLocalTransfo; + pConnector->GetGlobalTransfo(sGlobalTransfo); + delete pConnector; + + std::vector adPolyline = sMarkupTessConnector.GetPolyLineCoords(); // Copy + + A3DVector3d sCurrentPt; + size_t uI, uPolylineSize = adPolyline.size(); + for(uI = 0; uI < uPolylineSize/3; uI++) + { + sCurrentPt.set(adPolyline[uI*3], adPolyline[uI*3 + 1], adPolyline[uI*3+2]); + sCurrentPt = sGlobalTransfo * sCurrentPt; + stBoundingBoxAddPoint(GetstpsBoundingBox(), sCurrentPt.x, sCurrentPt.y, sCurrentPt.z); + } + + } + // Draw the markups + else + { + OpenGL_Begin(kA3DDrawBeginEndMarkup, NULL, 0); + + if (m_bShow) + { + // Draw the global matrix + OpenGL_PushMatrix(); + OpenGL_MultMatrix(sMarkupTessConnector.GetWorldMatrix()); + + // *** Draw the colors + double a_adRGB[3] = {0, 0, 0}; + sMarkupTessConnector.GetColor(a_adRGB); + OpenGL_Color(a_adRGB); + + // *** Draw the triangles + std::vector triangles = sMarkupTessConnector.GetTriangles(); + size_t uTrianglesSize = triangles.size(); + double* adTriangle = new double[uTrianglesSize]; + + for (size_t ui=0; ui const& textEntries = sMarkupTessConnector.GetTextEntries(); + for (size_t ui = 0; ui < textEntries.size(); ++ui) + { + A3DPMITextEntry mTextEntries = *textEntries[ui]; + + A3DFontKeyData sFontKeyData = mTextEntries.GetFontKeyData(); + OpenGL_Font(&sFontKeyData); + + A3DUTF8Char * m_ppcTexts = mTextEntries.GetText(); + + // Draw Text + A3DRiSet *pSet = NULL; + A3DDouble dLength = 0.; + + if(A3DGlobalFontTextTessellationGet(&sFontKeyData, m_ppcTexts, &pSet, &dLength) == A3D_SUCCESS) + { + A3DRiConnector sRiSet(pSet); + sRiSet.TraverseRi(this->m_psContainer); + } + } + + // *** Draw the polylines + std::vector polylineindex = sMarkupTessConnector.GetPolyLineIndices(); + std::vector polylines = sMarkupTessConnector.GetPolyLineCoords(); + double* adPolyline = new double[polylines.size()]; + for (size_t ui=0; ui auPolylineIndices; + + // manage the visibility of the items + A3DVisitorColorMaterials* pVisitorColorAndMaterials = (A3DVisitorColorMaterials *)m_psContainer->GetVisitor()[1]; + ColorMaterialsConnector sColorMaterialConnec(pVisitorColorAndMaterials->GetLastCascadedAttributes()); + pVisitorColorAndMaterials->GetColorMaterialConnector(sColorMaterialConnec, false); + + A3DVisitorTransfo* psVisitorTransfo = (A3DVisitorTransfo*)m_psContainer->GetVisitor()[0]; + A3DTransfoConnector* pConnector = psVisitorTransfo->GetTransfoConnector(); + A3DMatrix4x4 sGlobalTransfo; + pConnector->GetGlobalTransfo(sGlobalTransfo); + delete pConnector; + + OpenGL_PushMatrix(); + OpenGL_MultMatrix(sGlobalTransfo.m_adM); + + if (sColorMaterialConnec.IsShow() && !sColorMaterialConnec.IsRemoved()) + { + CHECK_RET(sWireTessConnector.Points(pPoint, uSize)); + CHECK_RET(sWireTessConnector.Indices(auPolylineIndices)); + size_t uI, uPolylineIndicesSize = auPolylineIndices.size(); + // section case: + if (auPolylineIndices[0] > 0) + { + for (uI = 0; uI < uPolylineIndicesSize; uI++) + { + std::vector aPoints; + // kA3DTess3DWireDataIsContinuous && kA3DTess3DWireDataIsClosing to be treated + unsigned int uPolyLineSize = auPolylineIndices[uI] & ~(kA3DTess3DWireDataIsContinuous | kA3DTess3DWireDataIsClosing); + for (size_t uJ = uI + 1; uJ < uI + uPolyLineSize + 1; uJ++) + { + aPoints.push_back(pPoint[auPolylineIndices[uJ]]); + aPoints.push_back(pPoint[auPolylineIndices[uJ] + 1]); + aPoints.push_back(pPoint[auPolylineIndices[uJ] + 2]); + } + OpenGL_PolyLine(aPoints.data(), uPolyLineSize); + uI += uPolyLineSize; + } + } + else + { + for (uI = 0; uI + 1 < uPolylineIndicesSize; ++uI) + { + // manage the case of polywire + int test = auPolylineIndices[uI + 1] - auPolylineIndices[uI]; + if (test > 0) + OpenGL_PolyLine(&pPoint[auPolylineIndices[uI] * 3], auPolylineIndices[uI + 1] - auPolylineIndices[uI]); + } + } + } + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTessellation::visitLeave(const A3DWireTessDataConnector& /*sWireTessConnector*/) +{ + OpenGL_PopMatrix(); + return A3D_SUCCESS; +} diff --git a/exchange/exchangesource/Viewer/traverse/VisitorTransfo.cpp b/exchange/exchangesource/Viewer/traverse/VisitorTransfo.cpp new file mode 100644 index 0000000..71fcf95 --- /dev/null +++ b/exchange/exchangesource/Viewer/traverse/VisitorTransfo.cpp @@ -0,0 +1,321 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "../VisitorTransfo.h" +#include "../VisitorContainer.h" +#include "../TransfoConnector.h" + +A3DVisitorTransfo::A3DVisitorTransfo( bool bModelFileUnitFormCAD, + double dUnitModelFile, + A3DVisitorContainer* psContainer /*= NULL*/ ) +: A3DVisitor("Transformation", psContainer), + m_dUnit(dUnitModelFile), + m_bUnitFormCad(bModelFileUnitFormCAD) +{ +} + +A3DVisitorTransfo::A3DVisitorTransfo( A3DVisitorContainer* psContainer /*= NULL*/ ) +: A3DVisitor("Transformation", psContainer), + m_dUnit(-1), + m_bUnitFormCad(false) +{ +} + +A3DVisitorTransfo::~A3DVisitorTransfo() +{ +} + +A3DTransfoConnector* A3DVisitorTransfo::GetTransfoConnectorFromManager(A3DEntity const * pEntity) +{ + if(m_psContainer) + { + A3DViewLinkedItemManager const* pVLIM = m_psContainer->GetActiveViewLinkedItemManager(pEntity); + if (pVLIM) + { + A3DMiscEntityReferenceData sSERData; + A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sSERData); + A3DStatus iErr = A3DMiscEntityReferenceGet(pVLIM->m_pMarkupLinkedItem, &sSERData); + if (iErr == A3D_SUCCESS && sSERData.m_pCoordinateSystem) + { + A3DRiCoordinateSystemData sCSysData; + A3D_INITIALIZE_DATA(A3DRiCoordinateSystemData, sCSysData); + iErr = A3DRiCoordinateSystemGet(sSERData.m_pCoordinateSystem, &sCSysData); + A3DTransfoConnector* pConnector = new A3DTransfoConnector(NULL); + pConnector->SetGlobalMatrix(sCSysData.m_pTransformation); + return pConnector; + } + A3DMiscEntityReferenceGet(NULL, &sSERData); + } + + A3DStepEntityRefManager const* pSERM = m_psContainer->GetActiveStepEntityRefManager(pEntity); + if(pSERM) + { + A3DMiscEntityReferenceData sSERData; + A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sSERData); + A3DStatus iErr = A3DMiscEntityReferenceGet(pSERM->m_pStepEntityRef, &sSERData); + if(iErr == A3D_SUCCESS && sSERData.m_pCoordinateSystem) + { + A3DRiCoordinateSystemData sCSysData; + A3D_INITIALIZE_DATA(A3DRiCoordinateSystemData, sCSysData); + iErr = A3DRiCoordinateSystemGet(sSERData.m_pCoordinateSystem, &sCSysData); + A3DTransfoConnector* pConnector = new A3DTransfoConnector(NULL); + + pConnector->SetGlobalMatrix(sCSysData.m_pTransformation); + return pConnector; + } + A3DMiscEntityReferenceGet(NULL, &sSERData); + } + } + + return NULL; +} + +A3DStatus A3DVisitorTransfo::visitEnter(const A3DRiConnector& sConnector) +{ + A3DStatus iRet = A3D_SUCCESS; + + A3DMatrix4x4 sTransfo; + size_t uSize = m_adPushTransfo.size(); + + // Use ItemReference transformation instead of local transformation + A3DTransfoConnector *pConnectorFromRef = this->GetTransfoConnectorFromManager(sConnector.GetA3DEntity()); + if (pConnectorFromRef) + { + pConnectorFromRef->GetGlobalTransfo(sTransfo); + m_adPushTransfo.push_back(sTransfo); + delete pConnectorFromRef; + + } + else if(sConnector.m_sRiData.m_pCoordinateSystem) + { + A3DRiCoordinateSystemData sA3DRiCoordinateSystemData; + A3D_INITIALIZE_DATA(A3DRiCoordinateSystemData, sA3DRiCoordinateSystemData); + CHECK_RET_CALL_A3D_FCTION(A3DRiCoordinateSystemGet,(sConnector.m_sRiData.m_pCoordinateSystem,&sA3DRiCoordinateSystemData)); + + A3DTransfoConnector sTransfoConnector(sA3DRiCoordinateSystemData.m_pTransformation); + sTransfoConnector.ComputeGlobalMatrix(uSize!= 0 ? m_adPushTransfo[uSize-1] : stIdentity); + //Local Matrix + A3DMatrix4x4 sThisMatrix; + CHECK_RET(sTransfoConnector.GetLocalMatrix(sThisMatrix)); + CHECK_RET(SetLocalTransfo(sThisMatrix)); + //GlobalMatrix + sTransfoConnector.GetGlobalTransfo(sTransfo); + m_adPushTransfo.push_back(sTransfo); + CHECK_RET_CALL_A3D_FCTION(A3DRiCoordinateSystemGet,(NULL, &sA3DRiCoordinateSystemData)); + } + else + { + m_adPushTransfo.push_back(uSize!= 0 ? m_adPushTransfo[uSize-1] : stIdentity); + CHECK_RET(SetLocalTransfo(stIdentity)); + } + + CHECK_RET(SetGlobalTransfo(m_adPushTransfo[m_adPushTransfo.size() - 1])); + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTransfo::visitLeave(const A3DRiConnector& /*sConnector*/) +{ + // End drawing the Representation Items + m_adPushTransfo.pop_back(); + + return A3D_SUCCESS; +} + +static A3DStatus stProductOccurrenceGetLocation(const A3DAsmProductOccurrenceData* psPOccData, + A3DMiscCartesianTransformation** ppLocation) +{ + if (psPOccData == NULL) + return A3D_ERROR; + + A3DStatus iRet = A3D_SUCCESS; + A3DAsmProductOccurrence* pExternal = psPOccData->m_pExternalData; + + if (pExternal != NULL) + { + A3DAsmProductOccurrenceData sExternalDataData; + A3D_INITIALIZE_DATA( A3DAsmProductOccurrenceData, sExternalDataData); + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(pExternal, &sExternalDataData)); + + CHECK_RET(stProductOccurrenceGetLocation( &sExternalDataData , ppLocation)); + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(NULL, &sExternalDataData)); + if(*ppLocation) + return A3D_SUCCESS; + } + + if (psPOccData->m_pLocation == NULL && psPOccData->m_pPrototype != NULL) + { + A3DAsmProductOccurrenceData sPrototypeData; + A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sPrototypeData); + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(psPOccData->m_pPrototype, &sPrototypeData)); + + CHECK_RET(stProductOccurrenceGetLocation(&sPrototypeData, ppLocation)); + CHECK_RET_CALL_A3D_FCTION(A3DAsmProductOccurrenceGet,(NULL, &sPrototypeData)); + return A3D_SUCCESS; + } + + *ppLocation = psPOccData->m_pLocation; + + return iRet; +} + +A3DStatus A3DVisitorTransfo::visitEnter(const A3DProductOccurrenceConnector& sConnector) +{ + A3DStatus iRet = A3D_SUCCESS; + + if(sConnector.m_sProductOccurrenceData.m_bUnitFromCAD && !m_bUnitFormCad) + { + m_bUnitFormCad = true; + m_dUnit = sConnector.m_sProductOccurrenceData.m_dUnit; + } + + // Use ItemReference transformation instead of local transformation + A3DTransfoConnector *pConnectorFromRef = this->GetTransfoConnectorFromManager(sConnector.GetA3DEntity()); + if (pConnectorFromRef) + { + A3DMatrix4x4 sTransfo; + pConnectorFromRef->GetGlobalTransfo(sTransfo); + m_adPushTransfo.push_back(sTransfo); + delete pConnectorFromRef; + } + else + { + A3DMiscCartesianTransformation* pLocation = NULL; + stProductOccurrenceGetLocation(&(sConnector.m_sProductOccurrenceData), &pLocation); + + A3DMatrix4x4 sTransfo; + size_t uSize = m_adPushTransfo.size(); + + if(pLocation) + { + A3DTransfoConnector sTransfoConnector(pLocation); + + //Local Transfo + A3DMatrix4x4 sThisMatrix; + CHECK_RET(sTransfoConnector.GetLocalMatrix(sThisMatrix)); + CHECK_RET(SetLocalTransfo(sThisMatrix)); + + //Global Transfo + sTransfoConnector.ComputeGlobalMatrix( uSize != 0 ? m_adPushTransfo[uSize - 1]: stIdentity); + sTransfoConnector.GetGlobalTransfo(sTransfo); + m_adPushTransfo.push_back(sTransfo); + } + else + { + m_adPushTransfo.push_back(uSize != 0 ? m_adPushTransfo[uSize - 1] : stIdentity); + CHECK_RET(SetLocalTransfo(stIdentity)); + } + } + + CHECK_RET(SetGlobalTransfo(m_adPushTransfo[m_adPushTransfo.size() - 1])); + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTransfo::visitLeave(const A3DProductOccurrenceConnector& /*sConnector*/) +{ + // End drawing the Product Occurrences + m_adPushTransfo.pop_back(); + + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTransfo::visitEnter(const A3DModelFileConnector& sConnector) +{ + if(sConnector.m_sModelFileData.m_bUnitFromCAD && !m_bUnitFormCad) + { + m_bUnitFormCad = true; + m_dUnit = sConnector.m_sModelFileData.m_dUnit; + } + return A3D_SUCCESS; +} + +A3DStatus A3DVisitorTransfo::visitLeave(const A3DModelFileConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DTransfoConnector* A3DVisitorTransfo::GetTransfoConnector(bool bUseInstance /*= false*/ ) +{ + if(bUseInstance) + { + size_t iSize = m_adPushTransfo.size(); + A3DMatrix4x4 rLastMatrix = iSize != 0 ? m_adPushTransfo[iSize-1] : stIdentity; + A3DMiscCartesianTransformation* pTransfo = CreateTransfo(m_adLocalMatrix); + A3DTransfoConnector* pConnector = new A3DTransfoConnector(pTransfo); + pConnector->SetGlobalMatrix(rLastMatrix); + CALL_A3D_FCTION(A3DEntityDelete,(pTransfo)); + return pConnector; + } + else + { + //if(m_psContainer) + //{ + // A3DTreeVisitor* pTreeVisitor = (A3DTreeVisitor*)m_psContainer->GetTreeVisitor(); + // if(pTreeVisitor) + // { + // A3DStepEntityRefManager const* pSERM = pTreeVisitor->GetActiveStepEntityRefManager(); + // if(pSERM) + // { + // A3DMiscEntityReferenceData sSERData; + // A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sSERData); + // A3DStatus iErr = CALL_A3D_FCTION(A3DMiscEntityReferenceGet,(pSERM->m_pStepEntityRef, &sSERData)); + // if(iErr == A3D_SUCCESS && sSERData.m_pCoordinateSystem) + // { + // A3DRiCoordinateSystemData sCSysData; + // A3D_INITIALIZE_DATA(A3DRiCoordinateSystemData, sCSysData); + // iErr = CALL_A3D_FCTION(A3DRiCoordinateSystemGet,(sSERData.m_pCoordinateSystem, &sCSysData)); + // A3DTransfoConnector* pConnector = new A3DTransfoConnector(NULL); + // pConnector->SetGlobalMatrix(sCSysData.m_pTransformation); + // return pConnector; + // } + // CALL_A3D_FCTION(A3DMiscEntityReferenceGet,(NULL, &sSERData)); + // } + // + // A3DViewLinkedItemManager const* pVLIM = pTreeVisitor->GetActiveViewLinkedItemManager(); + // if (pVLIM) + // { + // A3DMiscEntityReferenceData sSERData; + // A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sSERData); + // A3DStatus iErr = CALL_A3D_FCTION(A3DMiscEntityReferenceGet, (pVLIM->m_pMarkupLinkedItem, &sSERData)); + // if (iErr == A3D_SUCCESS && sSERData.m_pCoordinateSystem) + // { + // A3DRiCoordinateSystemData sCSysData; + // A3D_INITIALIZE_DATA(A3DRiCoordinateSystemData, sCSysData); + // iErr = CALL_A3D_FCTION(A3DRiCoordinateSystemGet, (sSERData.m_pCoordinateSystem, &sCSysData)); + // A3DTransfoConnector* pConnector = new A3DTransfoConnector(NULL); + // pConnector->SetGlobalMatrix(sCSysData.m_pTransformation); + // return pConnector; + // } + // CALL_A3D_FCTION(A3DMiscEntityReferenceGet, (NULL, &sSERData)); + // } + // } + //} + size_t iSize = m_adPushTransfo.size(); + A3DMatrix4x4 rLastMatrix = iSize != 0 ? m_adPushTransfo[iSize-1] : stIdentity; + A3DMiscCartesianTransformation* pTransfo = CreateTransfo(m_adLocalMatrix); + A3DTransfoConnector* pConnector = new A3DTransfoConnector(pTransfo); + pConnector->SetGlobalMatrix(rLastMatrix); + CALL_A3D_FCTION(A3DEntityDelete,(pTransfo)); + return pConnector; + } +} + +A3DMiscTransformation* A3DVisitorTransfo::CreateTransfo( A3DMatrix4x4 const & rMatrix ) +{ + + A3DMiscGeneralTransformationData sData; + A3D_INITIALIZE_DATA( A3DMiscGeneralTransformationData, sData); + memcpy( sData.m_adCoeff ,rMatrix.m_adM, 16*sizeof(double)); + A3DMiscGeneralTransformation* pTransfo = NULL; + CALL_A3D_FCTION(A3DMiscGeneralTransformationCreate,(&sData, &pTransfo)); + return (A3DMiscTransformation*)pTransfo; +} diff --git a/exchange/exchangesource/Viewer/traverse/VisitorTree.cpp b/exchange/exchangesource/Viewer/traverse/VisitorTree.cpp new file mode 100644 index 0000000..1823f75 --- /dev/null +++ b/exchange/exchangesource/Viewer/traverse/VisitorTree.cpp @@ -0,0 +1,97 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ + +#include "../VisitorTree.h" + +A3DStatus A3DTreeVisitor::visitEnter(const A3DRiBrepModelConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DRiBrepModelConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitEnter(const A3DRiSetConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DRiSetConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitEnter(const A3DRiConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DRiConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitEnter(const A3DPartConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DPartConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitEnter(const A3DProductOccurrenceConnector& sConnector) +{ + if(m_uOption&NODE_INSTANCES) + { + m_pYourEntity = m_psContainer->FindInMap(sConnector.GetA3DEntity()); + if(m_pYourEntity) + { + ((A3DProductOccurrenceConnector*) &sConnector)->SetIsInstanciated(true); + } + } + + m_psContainer->SetInMap(sConnector.GetA3DEntity(),(void*) sConnector.GetA3DEntity() ); + + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DProductOccurrenceConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitEnter(const A3DMkpViewConnector& sConnector) +{ + m_psContainer->SetInMap(sConnector.GetA3DEntity(), (void*)sConnector.GetA3DEntity());//m_pYourEntity); + + return A3D_SUCCESS; +} + +A3DStatus A3DTreeVisitor::visitLeave(const A3DMkpViewConnector& /*sConnector*/) +{ + return A3D_SUCCESS; +} + +void A3DTreeVisitor::SetYourEntity(void* /*pYourEnity*/) +{ + //std::vector::iterator sIter; + //for(sIter = m_asStepEntityRefManager.begin(); sIter != m_asStepEntityRefManager.end(); ++sIter) + //{ + // if(sIter->m_bPushChildren == true) + // sIter->m_apYourEntity.push_back(pYourEnity); + //} + // + //return; +} diff --git a/exchange/exchangesource/Viewer/traverse/visitor.cpp b/exchange/exchangesource/Viewer/traverse/visitor.cpp new file mode 100644 index 0000000..21d238a --- /dev/null +++ b/exchange/exchangesource/Viewer/traverse/visitor.cpp @@ -0,0 +1,11 @@ +#include "VisitorsContainer.h" + +void* A3DVisitorContainer::FindInMap(const A3DEntity* pA3DEntity) +{ + return m_psContainer->FindInMap(pA3DEntity); +} + +void A3DVisitorContainer::SetInMap(const A3DEntity* pA3DEntity, void* pYourEntity) +{ + return SetInMap(pA3DEntity, pYourEntity); +} \ No newline at end of file diff --git a/exchange/exchangesource/common.hpp b/exchange/exchangesource/common.hpp new file mode 100644 index 0000000..e3d7db2 --- /dev/null +++ b/exchange/exchangesource/common.hpp @@ -0,0 +1,268 @@ +/*********************************************************************************************************************** +* +* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc. +* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret +* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event +* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized +* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the +* scope and manner of such use. +* +***********************************************************************************************************************/ +/** +\file common.hpp + +Definitions of macros, data and functions common to Exchange samples. + +This header requires prior inclusion of . + +**/ + +#ifndef EXCHANGE_SAMPLES_COMMON_HPP +#define EXCHANGE_SAMPLES_COMMON_HPP + +#ifdef _MSC_VER +# pragma warning(disable: 4505) // "unreferenced local function has been removed" +# pragma warning(disable: 4996) // "this function or variable may be unsafe" +#endif + +#include +#include +#include + + +# include + +//###################################################################################################################### +#define CHECK_RET(FunctionCall)\ +{\ + const A3DStatus iRet__ = FunctionCall;\ + if (iRet__ != A3D_SUCCESS)\ + {\ + if (A3DMiscGetErrorMsg)\ + fprintf(stderr, #FunctionCall " returned error %d = %s\n", iRet__ , A3DMiscGetErrorMsg(iRet__) ); \ + else\ + fprintf(stderr, #FunctionCall " returned error %d\n", iRet__ ); \ + return iRet__;\ + }\ +} + +//###################################################################################################################### +#define TEST_RET(FunctionCall)\ +{\ + const A3DStatus iRet__ = FunctionCall;\ + if (iRet__ != A3D_SUCCESS)\ + {\ + if (A3DMiscGetErrorMsg)\ + fprintf(stderr, #FunctionCall " returned error %d = %s\n", iRet__ , A3DMiscGetErrorMsg(iRet__) ); \ + else\ + fprintf(stderr, #FunctionCall " returned error %d\n", iRet__ ); \ + }\ +} + +//###################################################################################################################### +#ifdef _MSC_VER +# define MY_CHAR A3DUniChar +# define MY_MAIN wmain +#else +# define MY_CHAR A3DUTF8Char +# define MY_MAIN main +# define _T(_x) _x +#endif + +//###################################################################################################################### +#if defined _UNICODE || defined UNICODE +# define MY_STRCMP(X,Y) wcscmp(X,_T(Y)) +# define MY_STRICMP(X,Y) _wcsicmp(X,_T(Y)) +# define MY_STRLEN wcslen +# define MY_ATOI _wtoi +# define MY_ATOF _wtof +# define MY_FOPEN(X,Y) _wfopen(X,_T(Y)) +# define MY_STRCPY(X,Y) wcscpy(X,Y) +# define MY_STRCAT(X,Y) wcscat(X,Y) +# define MY_STRCAT2 wcscat +# define MY_FPRINTF(X,Y,Z) fwprintf(X,_T(Y),Z) +# define MY_PRINTF(X) wprintf(_T(X)) +# define MY_PRINTF2(X,Y) wprintf(_T(X),Y) +# define MY_SPRINTF(X,Y,Z) wsprintf(X,_T(Y),Z) +# define MY_SPRINTF2(W,X,Y,Z) wsprintf(W,_T(X),Y,Z) +# define MY_SSCANF(X,Y,Z) swscanf(X,_T(Y),Z) +#else +# define MY_STRCMP strcmp +# define MY_STRICMP stricmp +# define MY_STRLEN strlen +# define MY_ATOI atoi +# define MY_ATOF atof +# define MY_FOPEN fopen +# define MY_STRCPY strcpy +# define MY_STRCAT strcat +# define MY_STRCAT2 strcat +# define MY_FPRINTF fprintf +# define MY_PRINTF(X) printf(X) +# define MY_PRINTF2(X,Y) printf(X,Y) +# define MY_SPRINTF(X,Y,Z) sprintf(X,Y,Z) +# define MY_SPRINTF2(W,X,Y,Z) sprintf(W,X,Y,Z) +# define MY_SSCANF sscanf +#endif + +#define PRINTLOGMESSAGEVALUE(format, value) fprintf(GetLogFile(), format, value); + +//###################################################################################################################### +#ifdef _MSC_VER +# define DEFAULT_INPUT_CAD _T(SAMPLES_DATA_DIRECTORY"\\catiaV5\\CV5_Aquo_Bottle\\_Aquo Bottle.CATProduct") +# define DEFAULT_INPUT_DRAWING _T(SAMPLES_DATA_DIRECTORY"\\drawing\\Carter.CATDrawing") +#else +# define DEFAULT_INPUT_CAD SAMPLES_DATA_DIRECTORY"/catiaV5/CV5_Aquo_Bottle/_Aquo Bottle.CATProduct" +# define DEFAULT_INPUT_DRAWING SAMPLES_DATA_DIRECTORY"/drawing/Carter.CATDrawing" +#endif + +//###################################################################################################################### +// single point of access to the static log file pointer from all translation units; avoids to add a .cpp file or face +// multiple definitions error at link time +// call with a non-null file name to create the log file +// default return value is stdout +inline FILE* GetLogFile(const MY_CHAR* pFileName = NULL) +{ + // fflush does not work correctly on stdout and stderr if redirected to a file with freopen, so I need a dedicated FILE + static FILE* pLogFile = NULL; + if (pFileName) + { + if (pLogFile) + { + fclose(pLogFile); + pLogFile = NULL; + } + pLogFile = MY_FOPEN(pFileName, "w"); + } + return pLogFile ? pLogFile : stdout; +} + +//###################################################################################################################### +inline A3DInt32 PrintLogMessage(A3DUTF8Char* pMsg) +{ + return fprintf(GetLogFile(), "%s", pMsg ? pMsg : ""); +} + +//###################################################################################################################### +inline A3DInt32 PrintLogWarning(A3DUTF8Char* pKod, A3DUTF8Char* pMsg) +{ + return fprintf(GetLogFile(), "WAR %s - %s", pKod ? pKod : "", pMsg ? pMsg : ""); +} + +//###################################################################################################################### +inline A3DInt32 PrintLogError(A3DUTF8Char* pKod, A3DUTF8Char* pMsg) +{ + FILE* pLogFile = GetLogFile(); + if (pLogFile == stdout) + pLogFile = stderr; + fprintf(pLogFile, "ERR %s - %s", pKod ? pKod : "", pMsg ? pMsg : ""); + return fflush(pLogFile); +} + +//###################################################################################################################### +// These functions exist just to show that you can do your own memory management. + + + +static std::unordered_map stvalloc; + +inline A3DPtr CheckMalloc(size_t uiByteSize) +{ + static A3DInt32 siCheckMalloc = 0; + if (!uiByteSize) + return nullptr; + siCheckMalloc++; + + + A3DPtr Ptr = calloc(1, uiByteSize); + + stvalloc[Ptr] = siCheckMalloc; + + return Ptr; +} + +inline A3DVoid CheckFree(A3DPtr ptr) +{ + if (!ptr) + return; + + auto it = stvalloc.find(ptr); + if (it == stvalloc.end()) + { + printf("Memory error on free!\n"); + } + else + { + stvalloc.erase(it); + } + free(ptr); + +} + +inline size_t ListLeaks() +{ + for (const auto& key_value : stvalloc) + { + printf("Leak at alloc %d\n", key_value.second); + } + return stvalloc.size(); +} + +template +T* CheckMallocT(const size_t uiObjectCount) +{ + return static_cast(CheckMalloc(uiObjectCount * sizeof(T))); +} + +//###################################################################################################################### +// Automatically free memory allocated with malloc and calloc. +class MemoryGuard +{ +public: + explicit MemoryGuard(void* ptr) : m_ptr(ptr) {} + ~MemoryGuard() + { + free(m_ptr); + m_ptr = NULL; + } + +private: + void* m_ptr; + + // non-copyable class: prevent use of copy constructor and operator. + // (in C++11 and later it would be better to disable them with "= delete") + MemoryGuard(const MemoryGuard& other); + MemoryGuard& operator=(const MemoryGuard& other); +}; + +//###################################################################################################################### +// Automatically free A3D data. +template +class DataGuard +{ +public: + typedef A3DStatus(*FunctionType)(const T*, D*); + + DataGuard(D& data, FunctionType& function) : + data_(data), + function_(function) + {} + + ~DataGuard() + { + TEST_RET(function_(NULL, &data_)) + } + +private: + D& data_; + const FunctionType function_; + + // non-copyable class: prevent use of copy constructor and operator. + // (in C++11 and later it would be better to disable them with "= delete") + DataGuard(const DataGuard& other); + DataGuard& operator=(const DataGuard& other); +}; + +#define DATAGUARD(Type) DataGuard + +//###################################################################################################################### +#endif // EXCHANGE_SAMPLES_COMMON_HPP diff --git a/publishadvanced.sln b/publishadvanced.sln new file mode 100644 index 0000000..9989bdd --- /dev/null +++ b/publishadvanced.sln @@ -0,0 +1,107 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32901.82 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "manufacturing_mbe", "publish\publishsource\manufacturing_mbe\manufacturing_mbe.vcxproj", "{6B2D05AE-AD0E-4C22-B166-729D0C80BCAE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PDFWithBOMAndCarousel", "publish\publishsource\PDFWithBOMAndCarousel\PDFWithBOMAndCarousel.vcxproj", "{4D98FED4-BB63-48E5-8F7C-06911D2AEBAC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DemoFunctionalitiesAdv", "publish\publishsource\DemoFunctionalitiesAdv\DemoFunctionalitiesAdv.vcxproj", "{E9E9773A-DA87-4C56-A36B-070D53F5EFE1}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AnimWorkinstruction", "publish\publishsource\AnimWorkinstruction\AnimWorkinstruction.vcxproj", "{87A4D020-D1B4-11E2-8B8B-0800200C9A66}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DemoDataModel", "publish\publishsource\DemoDataModel\DemoDataModel.vcxproj", "{0729E0A2-3863-11E6-AC61-9E71128CAE77}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DemoLayers", "publish\publishsource\DemoLayers\DemoLayers.vcxproj", "{25FD54F8-3AE3-4B07-B918-D1F3232D7C59}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Export3DToHtml", "publish\publishsource\Export3DToHtml\Export3DToHtml.vcxproj", "{26FC13DB-2678-42BD-926C-8865669AF1B3}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UpdateData", "publish\publishsource\UpdateData\UpdateData.vcxproj", "{3FC16F11-56B6-47DA-A8D1-385FFE2E3107}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ExportPDFToHtml", "publish\publishsource\ExportPDFToHtml\ExportPDFToHtml.vcxproj", "{26FC13DC-2678-42BE-926C-8865669AF123}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6B2D05AE-AD0E-4C22-B166-729D0C80BCAE}.Debug|Win32.ActiveCfg = Debug|Win32 + {6B2D05AE-AD0E-4C22-B166-729D0C80BCAE}.Debug|Win32.Build.0 = Debug|Win32 + {6B2D05AE-AD0E-4C22-B166-729D0C80BCAE}.Debug|x64.ActiveCfg = Debug|x64 + {6B2D05AE-AD0E-4C22-B166-729D0C80BCAE}.Debug|x64.Build.0 = Debug|x64 + {6B2D05AE-AD0E-4C22-B166-729D0C80BCAE}.Release|Win32.ActiveCfg = Release|Win32 + {6B2D05AE-AD0E-4C22-B166-729D0C80BCAE}.Release|Win32.Build.0 = Release|Win32 + {6B2D05AE-AD0E-4C22-B166-729D0C80BCAE}.Release|x64.ActiveCfg = Release|x64 + {6B2D05AE-AD0E-4C22-B166-729D0C80BCAE}.Release|x64.Build.0 = Release|x64 + {4D98FED4-BB63-48E5-8F7C-06911D2AEBAC}.Debug|Win32.ActiveCfg = Debug|Win32 + {4D98FED4-BB63-48E5-8F7C-06911D2AEBAC}.Debug|Win32.Build.0 = Debug|Win32 + {4D98FED4-BB63-48E5-8F7C-06911D2AEBAC}.Debug|x64.ActiveCfg = Debug|x64 + {4D98FED4-BB63-48E5-8F7C-06911D2AEBAC}.Debug|x64.Build.0 = Debug|x64 + {4D98FED4-BB63-48E5-8F7C-06911D2AEBAC}.Release|Win32.ActiveCfg = Release|Win32 + {4D98FED4-BB63-48E5-8F7C-06911D2AEBAC}.Release|Win32.Build.0 = Release|Win32 + {4D98FED4-BB63-48E5-8F7C-06911D2AEBAC}.Release|x64.ActiveCfg = Release|x64 + {4D98FED4-BB63-48E5-8F7C-06911D2AEBAC}.Release|x64.Build.0 = Release|x64 + {E9E9773A-DA87-4C56-A36B-070D53F5EFE1}.Debug|Win32.ActiveCfg = Debug|Win32 + {E9E9773A-DA87-4C56-A36B-070D53F5EFE1}.Debug|Win32.Build.0 = Debug|Win32 + {E9E9773A-DA87-4C56-A36B-070D53F5EFE1}.Debug|x64.ActiveCfg = Debug|x64 + {E9E9773A-DA87-4C56-A36B-070D53F5EFE1}.Debug|x64.Build.0 = Debug|x64 + {E9E9773A-DA87-4C56-A36B-070D53F5EFE1}.Release|Win32.ActiveCfg = Release|Win32 + {E9E9773A-DA87-4C56-A36B-070D53F5EFE1}.Release|Win32.Build.0 = Release|Win32 + {E9E9773A-DA87-4C56-A36B-070D53F5EFE1}.Release|x64.ActiveCfg = Release|x64 + {E9E9773A-DA87-4C56-A36B-070D53F5EFE1}.Release|x64.Build.0 = Release|x64 + {87A4D020-D1B4-11E2-8B8B-0800200C9A66}.Debug|Win32.ActiveCfg = Debug|Win32 + {87A4D020-D1B4-11E2-8B8B-0800200C9A66}.Debug|Win32.Build.0 = Debug|Win32 + {87A4D020-D1B4-11E2-8B8B-0800200C9A66}.Debug|x64.ActiveCfg = Debug|x64 + {87A4D020-D1B4-11E2-8B8B-0800200C9A66}.Debug|x64.Build.0 = Debug|x64 + {87A4D020-D1B4-11E2-8B8B-0800200C9A66}.Release|Win32.ActiveCfg = Release|Win32 + {87A4D020-D1B4-11E2-8B8B-0800200C9A66}.Release|Win32.Build.0 = Release|Win32 + {87A4D020-D1B4-11E2-8B8B-0800200C9A66}.Release|x64.ActiveCfg = Release|x64 + {87A4D020-D1B4-11E2-8B8B-0800200C9A66}.Release|x64.Build.0 = Release|x64 + {0729E0A2-3863-11E6-AC61-9E71128CAE77}.Debug|Win32.ActiveCfg = Debug|Win32 + {0729E0A2-3863-11E6-AC61-9E71128CAE77}.Debug|Win32.Build.0 = Debug|Win32 + {0729E0A2-3863-11E6-AC61-9E71128CAE77}.Debug|x64.ActiveCfg = Debug|x64 + {0729E0A2-3863-11E6-AC61-9E71128CAE77}.Debug|x64.Build.0 = Debug|x64 + {0729E0A2-3863-11E6-AC61-9E71128CAE77}.Release|Win32.ActiveCfg = Release|Win32 + {0729E0A2-3863-11E6-AC61-9E71128CAE77}.Release|Win32.Build.0 = Release|Win32 + {0729E0A2-3863-11E6-AC61-9E71128CAE77}.Release|x64.ActiveCfg = Release|x64 + {0729E0A2-3863-11E6-AC61-9E71128CAE77}.Release|x64.Build.0 = Release|x64 + {25FD54F8-3AE3-4B07-B918-D1F3232D7C59}.Debug|Win32.ActiveCfg = Debug|Win32 + {25FD54F8-3AE3-4B07-B918-D1F3232D7C59}.Debug|Win32.Build.0 = Debug|Win32 + {25FD54F8-3AE3-4B07-B918-D1F3232D7C59}.Debug|x64.ActiveCfg = Debug|x64 + {25FD54F8-3AE3-4B07-B918-D1F3232D7C59}.Debug|x64.Build.0 = Debug|x64 + {25FD54F8-3AE3-4B07-B918-D1F3232D7C59}.Release|Win32.ActiveCfg = Release|Win32 + {25FD54F8-3AE3-4B07-B918-D1F3232D7C59}.Release|Win32.Build.0 = Release|Win32 + {25FD54F8-3AE3-4B07-B918-D1F3232D7C59}.Release|x64.ActiveCfg = Release|x64 + {25FD54F8-3AE3-4B07-B918-D1F3232D7C59}.Release|x64.Build.0 = Release|x64 + {26FC13DB-2678-42BD-926C-8865669AF1B3}.Debug|Win32.ActiveCfg = Debug|x64 + {26FC13DB-2678-42BD-926C-8865669AF1B3}.Debug|x64.ActiveCfg = Debug|x64 + {26FC13DB-2678-42BD-926C-8865669AF1B3}.Debug|x64.Build.0 = Debug|x64 + {26FC13DB-2678-42BD-926C-8865669AF1B3}.Release|Win32.ActiveCfg = Release|x64 + {26FC13DB-2678-42BD-926C-8865669AF1B3}.Release|x64.ActiveCfg = Release|x64 + {26FC13DB-2678-42BD-926C-8865669AF1B3}.Release|x64.Build.0 = Release|x64 + {3FC16F11-56B6-47DA-A8D1-385FFE2E3107}.Debug|Win32.ActiveCfg = Debug|Win32 + {3FC16F11-56B6-47DA-A8D1-385FFE2E3107}.Debug|Win32.Build.0 = Debug|Win32 + {3FC16F11-56B6-47DA-A8D1-385FFE2E3107}.Debug|x64.ActiveCfg = Debug|x64 + {3FC16F11-56B6-47DA-A8D1-385FFE2E3107}.Debug|x64.Build.0 = Debug|x64 + {3FC16F11-56B6-47DA-A8D1-385FFE2E3107}.Release|Win32.ActiveCfg = Release|Win32 + {3FC16F11-56B6-47DA-A8D1-385FFE2E3107}.Release|Win32.Build.0 = Release|Win32 + {3FC16F11-56B6-47DA-A8D1-385FFE2E3107}.Release|x64.ActiveCfg = Release|x64 + {3FC16F11-56B6-47DA-A8D1-385FFE2E3107}.Release|x64.Build.0 = Release|x64 + {26FC13DC-2678-42BE-926C-8865669AF123}.Debug|Win32.ActiveCfg = Debug|x64 + {26FC13DC-2678-42BE-926C-8865669AF123}.Debug|x64.ActiveCfg = Debug|x64 + {26FC13DC-2678-42BE-926C-8865669AF123}.Debug|x64.Build.0 = Debug|x64 + {26FC13DC-2678-42BE-926C-8865669AF123}.Release|Win32.ActiveCfg = Release|x64 + {26FC13DC-2678-42BE-926C-8865669AF123}.Release|x64.ActiveCfg = Release|x64 + {26FC13DC-2678-42BE-926C-8865669AF123}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {37137C76-5789-41FA-8415-FF99A1D053A8} + EndGlobalSection +EndGlobal diff --git a/publishstandard.sln b/publishstandard.sln new file mode 100644 index 0000000..88ed7f2 --- /dev/null +++ b/publishstandard.sln @@ -0,0 +1,81 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32901.82 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PublishImportExport", "publish\publishsource\PublishImportExport\PublishImportExport.vcxproj", "{B1CD4867-403B-4F32-BA7E-5AECABDFCC46}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloWorld", "publish\publishsource\HelloWorld\HelloWorld.vcxproj", "{EF0EFB44-A604-46FE-B266-2B56608A0D1F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CreatePRCCubes", "publish\publishsource\CreatePRCCubes\CreatePRCCubes.vcxproj", "{BC2C5960-4AC4-4E68-BB85-FF62927EDCDB}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "U3DWithAnimation", "publish\publishsource\U3DWithAnimation\U3DWithAnimation.vcxproj", "{AC0D7DD3-B31E-4A67-8B52-20E4E3F304FB}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UserDefinedViews", "publish\publishsource\UserDefinedViews\UserDefinedViews.vcxproj", "{B651630E-CF57-4CD2-93DC-7F2B56BA5D90}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DemoFunctionalities", "publish\publishsource\DemoFunctionalities\DemoFunctionalities.vcxproj", "{D2BFF3A0-3BB5-11E1-B86C-0800200C9A66}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B1CD4867-403B-4F32-BA7E-5AECABDFCC46}.Debug|Win32.ActiveCfg = Debug|Win32 + {B1CD4867-403B-4F32-BA7E-5AECABDFCC46}.Debug|Win32.Build.0 = Debug|Win32 + {B1CD4867-403B-4F32-BA7E-5AECABDFCC46}.Debug|x64.ActiveCfg = Debug|x64 + {B1CD4867-403B-4F32-BA7E-5AECABDFCC46}.Debug|x64.Build.0 = Debug|x64 + {B1CD4867-403B-4F32-BA7E-5AECABDFCC46}.Release|Win32.ActiveCfg = Release|Win32 + {B1CD4867-403B-4F32-BA7E-5AECABDFCC46}.Release|Win32.Build.0 = Release|Win32 + {B1CD4867-403B-4F32-BA7E-5AECABDFCC46}.Release|x64.ActiveCfg = Release|x64 + {B1CD4867-403B-4F32-BA7E-5AECABDFCC46}.Release|x64.Build.0 = Release|x64 + {EF0EFB44-A604-46FE-B266-2B56608A0D1F}.Debug|Win32.ActiveCfg = Debug|Win32 + {EF0EFB44-A604-46FE-B266-2B56608A0D1F}.Debug|Win32.Build.0 = Debug|Win32 + {EF0EFB44-A604-46FE-B266-2B56608A0D1F}.Debug|x64.ActiveCfg = Debug|x64 + {EF0EFB44-A604-46FE-B266-2B56608A0D1F}.Debug|x64.Build.0 = Debug|x64 + {EF0EFB44-A604-46FE-B266-2B56608A0D1F}.Release|Win32.ActiveCfg = Release|Win32 + {EF0EFB44-A604-46FE-B266-2B56608A0D1F}.Release|Win32.Build.0 = Release|Win32 + {EF0EFB44-A604-46FE-B266-2B56608A0D1F}.Release|x64.ActiveCfg = Release|x64 + {EF0EFB44-A604-46FE-B266-2B56608A0D1F}.Release|x64.Build.0 = Release|x64 + {BC2C5960-4AC4-4E68-BB85-FF62927EDCDB}.Debug|Win32.ActiveCfg = Debug|Win32 + {BC2C5960-4AC4-4E68-BB85-FF62927EDCDB}.Debug|Win32.Build.0 = Debug|Win32 + {BC2C5960-4AC4-4E68-BB85-FF62927EDCDB}.Debug|x64.ActiveCfg = Debug|x64 + {BC2C5960-4AC4-4E68-BB85-FF62927EDCDB}.Debug|x64.Build.0 = Debug|x64 + {BC2C5960-4AC4-4E68-BB85-FF62927EDCDB}.Release|Win32.ActiveCfg = Release|Win32 + {BC2C5960-4AC4-4E68-BB85-FF62927EDCDB}.Release|Win32.Build.0 = Release|Win32 + {BC2C5960-4AC4-4E68-BB85-FF62927EDCDB}.Release|x64.ActiveCfg = Release|x64 + {BC2C5960-4AC4-4E68-BB85-FF62927EDCDB}.Release|x64.Build.0 = Release|x64 + {AC0D7DD3-B31E-4A67-8B52-20E4E3F304FB}.Debug|Win32.ActiveCfg = Debug|Win32 + {AC0D7DD3-B31E-4A67-8B52-20E4E3F304FB}.Debug|Win32.Build.0 = Debug|Win32 + {AC0D7DD3-B31E-4A67-8B52-20E4E3F304FB}.Debug|x64.ActiveCfg = Debug|x64 + {AC0D7DD3-B31E-4A67-8B52-20E4E3F304FB}.Debug|x64.Build.0 = Debug|x64 + {AC0D7DD3-B31E-4A67-8B52-20E4E3F304FB}.Release|Win32.ActiveCfg = Release|Win32 + {AC0D7DD3-B31E-4A67-8B52-20E4E3F304FB}.Release|Win32.Build.0 = Release|Win32 + {AC0D7DD3-B31E-4A67-8B52-20E4E3F304FB}.Release|x64.ActiveCfg = Release|x64 + {AC0D7DD3-B31E-4A67-8B52-20E4E3F304FB}.Release|x64.Build.0 = Release|x64 + {B651630E-CF57-4CD2-93DC-7F2B56BA5D90}.Debug|Win32.ActiveCfg = Debug|Win32 + {B651630E-CF57-4CD2-93DC-7F2B56BA5D90}.Debug|Win32.Build.0 = Debug|Win32 + {B651630E-CF57-4CD2-93DC-7F2B56BA5D90}.Debug|x64.ActiveCfg = Debug|x64 + {B651630E-CF57-4CD2-93DC-7F2B56BA5D90}.Debug|x64.Build.0 = Debug|x64 + {B651630E-CF57-4CD2-93DC-7F2B56BA5D90}.Release|Win32.ActiveCfg = Release|Win32 + {B651630E-CF57-4CD2-93DC-7F2B56BA5D90}.Release|Win32.Build.0 = Release|Win32 + {B651630E-CF57-4CD2-93DC-7F2B56BA5D90}.Release|x64.ActiveCfg = Release|x64 + {B651630E-CF57-4CD2-93DC-7F2B56BA5D90}.Release|x64.Build.0 = Release|x64 + {D2BFF3A0-3BB5-11E1-B86C-0800200C9A66}.Debug|Win32.ActiveCfg = Debug|Win32 + {D2BFF3A0-3BB5-11E1-B86C-0800200C9A66}.Debug|Win32.Build.0 = Debug|Win32 + {D2BFF3A0-3BB5-11E1-B86C-0800200C9A66}.Debug|x64.ActiveCfg = Debug|x64 + {D2BFF3A0-3BB5-11E1-B86C-0800200C9A66}.Debug|x64.Build.0 = Debug|x64 + {D2BFF3A0-3BB5-11E1-B86C-0800200C9A66}.Release|Win32.ActiveCfg = Release|Win32 + {D2BFF3A0-3BB5-11E1-B86C-0800200C9A66}.Release|Win32.Build.0 = Release|Win32 + {D2BFF3A0-3BB5-11E1-B86C-0800200C9A66}.Release|x64.ActiveCfg = Release|x64 + {D2BFF3A0-3BB5-11E1-B86C-0800200C9A66}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {75FCEF91-34DE-4F7B-B9B4-04D32D8A1E7A} + EndGlobalSection +EndGlobal