Files
Hoops_Exchange/exchange/exchangesource/NetWrapper/ConsoleApplication/Program.cs
2025-12-15 23:22:33 +08:00

197 lines
7.8 KiB
C#

/***********************************************************************************************************************
*
* Copyright (c) 2010 - 2023 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<string, string> sOptions = new Dictionary<string, string>();
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 + " <input CAD file> <output XT file> [-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");
}
}
}
}