Skip to content

Commit

Permalink
finish face to brep translate
Browse files Browse the repository at this point in the history
  • Loading branch information
zcstkhk committed Oct 11, 2021
1 parent 60d9402 commit c69aee0
Show file tree
Hide file tree
Showing 28 changed files with 1,153 additions and 1,032 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ The program offered is signed with NX 1872, that means if you use 1847 or other
# 编译方法
>1. 安装 NX 时将安装目录设置为如下形式,XXX\Siemens\NXVER,其中 XXX 为任意文件夹,注意最好不要有空格,否则可能会引发其它问题,NXVER 为 NX 的版本号,比如 NX1872、NX1953,注意 NX 和 版本号之间不要有空格。
>2. 创建环境变量 SPLM_ROOT_DIR,指向第一步安装路径中的 XXX\Siemens。
>3. 创建环境变量 RHINO_ROOT_DIR,指向 RHINO 的安装目录,比如 C:\Programs\Rhino\7。
>3. 创建环境变量 RHINO_ROOT_DIR,指向 RHINO 的安装目录,比如 C:\Programs\Rhino\7。
#已知问题
>1. 不能修改 Grasshopper 中组件的描述(名称),否则会卡死,原因暂时未知。
>2. 无法正确创建被平面修剪后断面为椭圆的圆锥/圆锥面,提示 ON_Brep.m_T[1] 2d curve is not inside surface domain。
2 changes: 1 addition & 1 deletion RhinoInside.NX Starter/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:RhinoInside_Starter"
mc:Ignorable="d"
Title="RhinoInside 启动器" Height="400" Width="750" WindowStyle="ToolWindow" ResizeMode="NoResize">
Title="RhinoInside 启动器" Height="400" Width="750" ResizeMode="NoResize">
<Window.Resources>
<Style TargetType="Button">
<Setter Property="Margin" Value="2" />
Expand Down
34 changes: 24 additions & 10 deletions RhinoInside.NX Starter/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public MainWindow()
{
string[] configContent = System.IO.File.ReadAllLines(configPath);

comboBoxSelectLanguage.SelectedIndex = Convert.ToInt32(configContent[0]);
NxInstallPath.SelectedPath = configContent[1];
RhinoInsidePath.SelectedPath = configContent[2];
RhinoPath.SelectedPath = configContent[3];
comboBoxSelectLanguage.SelectedIndex = Convert.ToInt32(configContent[0].Substring(2));
NxInstallPath.SelectedPath = configContent[1].Substring(2);
RhinoInsidePath.SelectedPath = configContent[2].Substring(2);
RhinoPath.SelectedPath = configContent[3].Substring(2);
}
else
{
Expand Down Expand Up @@ -105,10 +105,10 @@ private void buttonStart_Click(object sender, RoutedEventArgs e)

using (var stream = System.IO.File.CreateText(configFilePath))
{
stream.WriteLine(comboBoxSelectLanguage.SelectedIndex.ToString());
stream.WriteLine(textBoxNxInstallPath.Text);
stream.WriteLine(textBoxRhinoInsidePath.Text);
stream.WriteLine(textBoxRhinoPath.Text);
stream.WriteLine("# " + comboBoxSelectLanguage.SelectedIndex.ToString());
stream.WriteLine("# " + textBoxNxInstallPath.Text);
stream.WriteLine("# " + textBoxRhinoInsidePath.Text);
stream.WriteLine("# " + textBoxRhinoPath.Text);
}

Process nxProcess = new Process();
Expand All @@ -118,9 +118,23 @@ private void buttonStart_Click(object sender, RoutedEventArgs e)
else
Environment.SetEnvironmentVariable("UGII_LANG", "english");

Environment.SetEnvironmentVariable("UGII_CUSTOM_DIRECTORY_FILE", "");
if (System.IO.Directory.Exists(@"E:\Documents\Programming\Repos\NXOpen Debug Utilities\00~Program"))
{
using (var writer = System.IO.File.AppendText(configFilePath))
{
writer.WriteLine(System.IO.Path.Combine( @"E:\Documents\Programming\Repos\NXOpen Debug Utilities\00~Program", textBoxNxInstallPath.Text.Split('\\').Last()));

writer.WriteLine(textBoxRhinoInsidePath.Text);
}

Environment.SetEnvironmentVariable("UGII_CUSTOM_DIRECTORY_FILE", configFilePath);
}
else
{
Environment.SetEnvironmentVariable("UGII_CUSTOM_DIRECTORY_FILE", "");

Environment.SetEnvironmentVariable("UGII_USER_DIR", textBoxRhinoInsidePath.Text);
Environment.SetEnvironmentVariable("UGII_USER_DIR", textBoxRhinoInsidePath.Text);
}

Environment.SetEnvironmentVariable("UGII_RhinoInside_Dir", textBoxRhinoInsidePath.Text);

Expand Down
82 changes: 82 additions & 0 deletions RhinoInside.NX.Core/NX/GH_Object.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NXOpen.UserDefinedObjects;
using static NXOpen.Extensions.Globals;
using NXOpen.Extensions;
using NXOpen;

namespace RhinoInside.NX.Core
{
public class GH_UserDefinedObject
{
static UserDefinedClass GHFeatureClass;

static GH_UserDefinedObject()
{
try
{
Console.WriteLine("注册");

// Define your custom UDO class
GHFeatureClass = TheSession.UserDefinedClassManager.CreateUserDefinedObjectClass
("GHFeature", "Object Created From Grasshopper");
// Setup properties on the custom UDO class
GHFeatureClass.AllowQueryClassFromName = UserDefinedClass.AllowQueryClass.On;
// Register callbacks for the UDO class
// GHFeature.AddDisplayHandler(new UserDefinedClass.DisplayCallback(Program.myDisplayCB));
// GHFeature.AddAttentionPointHandler(new UserDefinedClass.DisplayCallback(Program.myDisplayCB));
// GHFeature.AddFitHandler(new UserDefinedClass.DisplayCallback
//(Program.myDisplayCB));
// GHFeature.AddSelectionHandler(new
//UserDefinedClass.DisplayCallback(Program.myDisplayCB));
// GHFeature.AddEditHandler(new UserDefinedClass.GenericCallback(Program.myEditCB));
// GHFeature.AddInformationHandler(new
//UserDefinedClass.GenericCallback(Program.myInfoCB));
// Add this class to the list of object types available for selection in NX.
// If you skip this step you won't be able to select UDO's of this class,
// even though you registered a selection callback.
TheUI.SelectionManager.SetSelectionStatusOfUserDefinedClass(GHFeatureClass, true);
}
catch (NXOpen.NXException ex)
{
// ---- Enter your exception handling code here -----
TheUI.NXMessageBox.Show("Caught exception", NXMessageBox.DialogType.Error, ex.Message);
throw ex;
}
}

public static UserDefinedObject CreateGHFeatureObject()
{
var ghFeatureObj = WorkPart.UserDefinedObjectManager.CreateUserDefinedObject(GHFeatureClass);

ghFeatureObj.Color = 36;

View myView = null;
Point3d myCursor;
myCursor.X = 0;
myCursor.Y = 0;
myCursor.Z = 0;
// ask the user to select an origin for this UDO
Selection.DialogResponse myResponse =
TheUI.SelectionManager.SelectScreenPosition("Select Origin of C# UDO", out myView, out myCursor);

double[] myUDOdoubles = new double[3];
myUDOdoubles[0] = myCursor.X;
myUDOdoubles[1] = myCursor.Y;
myUDOdoubles[2] = myCursor.Z;
ghFeatureObj.SetDoubles(myUDOdoubles);

TheUfSession.Disp.AddItemToDisplay(ghFeatureObj.Tag);

NXOpen.Features.UserDefinedObjectFeatureBuilder fb = WorkPart.Features.CreateUserDefinedObjectFeatureBuilder(null);
fb.UserDefinedObject = ghFeatureObj;
fb.Commit();
fb.Destroy();

return ghFeatureObj;
}
}
}
1 change: 1 addition & 0 deletions RhinoInside.NX.Core/RhinoInside.NX.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<Compile Include="GH\GrasshopperCommands.cs" />
<Compile Include="GH\GrasshopperPlayerCommand.cs" />
<Compile Include="ImageBuilder.cs" />
<Compile Include="NX\GH_Object.cs" />
<Compile Include="ObjectTypes.cs" />
<Compile Include="Rhino\Import.cs" />
<Compile Include="Rhino\RhinoCommands.cs" />
Expand Down
2 changes: 1 addition & 1 deletion RhinoInside.NX.GH.Loader/RhinoInside.NX.GH.Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal static Assembly AssemblyResolveHandler(object sender, ResolveEventArgs
{
return Assembly.LoadFrom(Path.Combine(NXBinPath, assemblyName + ".dll"));
}
else if (assemblyName == "NXOpen.Extensions" || assemblyName == "RhinoInside.NX.Core")
else if (assemblyName == "NXOpen.Extensions" || assemblyName == "RhinoInside.NX.Core" || assemblyName == "RhinoInside.NX.Translator")
{
return Assembly.LoadFrom(Path.Combine(RhinoInsideDirectory, "Startup", assemblyName + ".dll"));
}
Expand Down
30 changes: 28 additions & 2 deletions RhinoInside.NX.GH/Parameters/DisplayableObject/Param_NXBody.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Grasshopper.Kernel;
using Grasshopper.Kernel.Parameters;
using NXOpen.Extensions;
using RhinoInside.NX.GH.Properties;
using RhinoInside.NX.GH.Types;
using System;
Expand All @@ -24,12 +25,37 @@ public Param_NXBody() : base(Languages.GetString("NXBodyParamName"), Languages.G

protected override GH_GetterResult Prompt_Plural(ref List<NX_Body> values)
{
throw new NotImplementedException();
SelectionPreparation();

var selectedObjects = Select_Plural(MaskTripleEx.Body);
if (selectedObjects != null)
{
values = new List<NX_Body>();
for (int i = 0; i < selectedObjects.Length; i++)
{
values.Add(new NX_Body(selectedObjects[i].Tag, Attributes.Selected));
}

return GH_GetterResult.success;
}

return GH_GetterResult.cancel;
}

protected override GH_GetterResult Prompt_Singular(ref NX_Body value)
{
throw new NotImplementedException();
SelectionPreparation();

var selectedObject = Select_Singular(MaskTripleEx.Body);

if (selectedObject != null)
{
value = new NX_Body(selectedObject.Tag, Attributes.Selected);

return GH_GetterResult.success;
}

return GH_GetterResult.cancel;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions RhinoInside.NX.GH/RhinoInside.NX.GH.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="TestComponents\UDOTest.cs" />
<Compile Include="TestComponents\TestComponent.cs" />
<Compile Include="Utilities\CSharpScriptComponent.cs" />
<Compile Include="Parameters\DisplayableObject\Param_NXCurve.cs" />
<Compile Include="Parameters\DisplayableObject\Param_NXDisplayableObject.cs" />
Expand All @@ -105,6 +107,7 @@
<Compile Include="Types\NX_Plane.cs" />
<Compile Include="Types\NX_Point.cs" />
<Compile Include="Types\NX_SmartObject.cs" />
<Compile Include="Utilities\GetBrepLogComponent.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RhinoInside.NX.Core\RhinoInside.NX.Core.csproj">
Expand Down
22 changes: 22 additions & 0 deletions RhinoInside.NX.GH/TestComponents/TestComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Grasshopper.Kernel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RhinoInside.NX.GH.TestComponents
{
public abstract class TestComponent : GH_Component
{
public override Guid ComponentGuid
{
get { return Guid.NewGuid(); }
}

public TestComponent(string name) : base(name, name, name, "NX", "Test")
{

}
}
}
44 changes: 44 additions & 0 deletions RhinoInside.NX.GH/TestComponents/UDOTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Grasshopper.Kernel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RhinoInside.NX.Core;

namespace RhinoInside.NX.GH.TestComponents
{
public class UDOTest : TestComponent
{
public UDOTest() : base("UDO Test")
{

}

/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddGenericParameter("Geometry", "G", "Geometry that want to Created In NX", GH_ParamAccess.item);
}

/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("NX Geonetry", "G", "Geometry Created In NX", GH_ParamAccess.item);
}

/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object can be used to retrieve data from input parameters and
/// to store data in output parameters.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{
GH_UserDefinedObject.CreateGHFeatureObject();
}
}
}
8 changes: 4 additions & 4 deletions RhinoInside.NX.GH/Types/BaseCurve/NX_Edge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public override bool CastTo<Q>(ref Q target)
{
if (typeof(Q) == typeof(GH_Curve))
{
Globals.TheUfSession.Modl.CreateCurveFromEdge(Tag, out var curveTag);
var edge = Tag.GetTaggedObject() as NXOpen.Edge;

target = (Q)(object)new GH_Curve((curveTag.GetTaggedObject() as NXOpen.Curve).ToRhino());
var rhinoCurve = edge.ToRhinoCurve();

target = (Q)(object)new GH_Curve(rhinoCurve);

Globals.TheUfSession.Obj.DeleteObject(curveTag);

return true;
}
else
Expand Down
16 changes: 16 additions & 0 deletions RhinoInside.NX.GH/Types/NX_Body.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Grasshopper.Kernel.Parameters;
using Grasshopper.Kernel.Types;
using RhinoInside.NX.Translator.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -32,6 +34,20 @@ public NX_Body(NXOpen.Tag tag, bool highlight) : base(tag, highlight)

}

public override bool CastTo<Q>(ref Q target)
{
if (typeof(Q) == typeof(GH_Brep))
{
target = (Q)(object)new GH_Brep(Value.ToBrep());
return true;
}
else
{
Console.WriteLine(typeof(Q));
return base.CastTo(ref target);
}
}

public override string ToString()
{
if (Value != null)
Expand Down
5 changes: 5 additions & 0 deletions RhinoInside.NX.GH/Types/NX_Face.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public override bool CastTo<Q>(ref Q target)
target = (Q)(object)new GH_Brep(Value.ToBrep());
return true;
}
else if (typeof(Q) == typeof(GH_Surface))
{
target = (Q)(object)new GH_Surface(Value.ToRhinoSurface());
return true;
}
else
{
Console.WriteLine(typeof(Q));
Expand Down
2 changes: 2 additions & 0 deletions RhinoInside.NX.GH/Utilities/CSharpScriptComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ protected override string CreateSourceForEdit(ScriptSource script)
//originalSource = originalSource.Insert(0, "using RhinoInside.NX.GH.Types;\r\n");

originalSource = originalSource.Insert(0, "using NXOpen;\r\n");
//originalSource = originalSource.Insert(0, "using RhinoInside.NX.Translator.Geometry;\r\n");
//originalSource = originalSource.Insert(0, "using NXOpen.Extensions;\r\n");

return originalSource;
}
Expand Down
Loading

0 comments on commit c69aee0

Please sign in to comment.