Skip to content

Commit

Permalink
+mirror, +ruler, +adjoin cylinders/COMs
Browse files Browse the repository at this point in the history
  • Loading branch information
fel88 committed Sep 5, 2023
1 parent 53e47b2 commit 8575363
Show file tree
Hide file tree
Showing 15 changed files with 405 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*.7z
*.patch
*.zip
packages/
.vs/
*.user
Expand Down
8 changes: 8 additions & 0 deletions CascadeDesktop/CascadeDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<Compile Include="RibbonMenuWPF.xaml.cs">
<DependentUpon>RibbonMenuWPF.xaml</DependentUpon>
</Compile>
<Compile Include="Tools\AdjoinCOMsTool.cs" />
<Compile Include="Tools\AdjoinTool.cs" />
<Compile Include="ArcElement.cs" />
<Compile Include="Contour.cs" />
Expand Down Expand Up @@ -127,6 +128,7 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tools\BoolTool.cs" />
<Compile Include="Tools\RulerTool.cs" />
<Compile Include="Tools\SelectionTool.cs" />
<Compile Include="StaticHelpers.cs" />
<Compile Include="SvgPoint.cs" />
Expand Down Expand Up @@ -235,5 +237,11 @@
<ItemGroup>
<Resource Include="Icons\infocard.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Icons\ruler-triangle.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Icons\layer-shape-round.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
98 changes: 87 additions & 11 deletions CascadeDesktop/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Windows.Forms;
using AutoDialog;
using CascadeDesktop.Tools;
using System.Windows;

namespace CascadeDesktop
{
Expand All @@ -29,9 +30,28 @@ public Form1()
panel1.MouseUp += Panel1_MouseUp;

toolStripStatusLabel3.Alignment = ToolStripItemAlignment.Right;
toolStripStatusLabel3.Click += ToolStripStatusLabel3_Click;
toolStripStatusLabel3.MouseEnter += ToolStripStatusLabel3_MouseEnter;
toolStripStatusLabel3.MouseLeave += ToolStripStatusLabel3_MouseLeave;

_currentTool = new SelectionTool(this);
}

private void ToolStripStatusLabel3_MouseLeave(object sender, EventArgs e)
{
statusStrip1.Cursor = Cursors.Default;
}

private void ToolStripStatusLabel3_MouseEnter(object sender, EventArgs e)
{
statusStrip1.Cursor = Cursors.Hand;
}

private void ToolStripStatusLabel3_Click(object sender, EventArgs e)
{
shortStatusOutputFormat = !shortStatusOutputFormat;
}

RibbonMenu menu;
public static Form1 Form;

Expand All @@ -43,7 +63,7 @@ private void Form1_Load(object sender, EventArgs e)
menu.Dock = DockStyle.Top;

mf = new MessageFilter();
Application.AddMessageFilter(mf);
System.Windows.Forms.Application.AddMessageFilter(mf);

toolStrip1.Visible = false;
}
Expand All @@ -61,7 +81,7 @@ private void Panel1_MouseUp(object sender, MouseEventArgs e)
}
}

Point startDrag;
System.Drawing.Point startDrag;
private void Panel1_MouseDown(object sender, MouseEventArgs e)
{
startDrag = e.Location;
Expand Down Expand Up @@ -98,7 +118,10 @@ public void SelectionChanged()
if (face is PlaneSurfInfo p)
{
var nrm = p.Normal.ToVector3d();
SetStatus3($"plane: {vect.X} {vect.Y} {vect.Z} normal: {nrm.X} {nrm.Y} {nrm.Z}");
SetStatus3(string.Empty);
AppendStatusVector(vect, "plane");
AppendStatusVector(nrm, "normal");
AppendStatusVector(p.COM.ToVector3d(), "com");
}
else if (face is CylinderSurfInfo c)
SetStatus3($"cylinder: {vect.X} {vect.Y} {vect.Z} radius: {c.Radius}");
Expand Down Expand Up @@ -231,7 +254,7 @@ public void SetStatus(string text, InfoType type = InfoType.Info)
{
toolStripStatusLabel1.Text = text;
toolStripStatusLabel1.ForeColor = Color.Black;
toolStripStatusLabel1.BackColor = SystemColors.Control;
toolStripStatusLabel1.BackColor = System.Drawing.SystemColors.Control;
switch (type)
{
case InfoType.Warning:
Expand All @@ -249,6 +272,18 @@ public void SetStatus3(string text)
{
toolStripStatusLabel3.Text = text;
}
bool shortStatusOutputFormat = false;
public void AppendStatus3(string text)
{
toolStripStatusLabel3.Text += text;
}
public void AppendStatusVector(Vector3d v, string caption)
{
if (shortStatusOutputFormat)
AppendStatus3($"{caption}: {v.X} {v.Y} {v.Z} ");
else
AppendStatus3($"{caption}: {v.X:0.##} {v.Y:0.##} {v.Z:0.##} ");
}

List<ManagedObjHandle> objs = new List<ManagedObjHandle>();
private void boxToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -281,7 +316,7 @@ private void panel1_MouseMove(object sender, MouseEventArgs e)
}
if (e.Button == MouseButtons.Left && isDrag)
{
var delta = new Point(e.Location.X - startDrag.X, startDrag.Y - e.Location.Y);
var delta = new System.Drawing.Point(e.Location.X - startDrag.X, startDrag.Y - e.Location.Y);
proxy.Pan(delta.X, delta.Y);
startDrag = e.Location;
}
Expand Down Expand Up @@ -369,7 +404,7 @@ private void diffToolStripMenuItem_Click(object sender, EventArgs e)
public void Fuse()
{
//todo: refactor to separate tool
proxy.MakeFuse(obj1, obj2, true);
proxy.MakeFuse(obj1, obj2);
proxy.Erase(obj1);
proxy.Erase(obj2);
}
Expand Down Expand Up @@ -519,6 +554,37 @@ public void RotateSelected()
proxy.RotateObject(proxy.GetSelectedObject(), x, y, z, ang * Math.PI / 180f, true);
}

public void MirrorSelected()
{
if (!CheckObjectSelectedUI())
return;

var d = DialogHelpers.StartDialog();
d.Text = "Mirror object";

d.AddNumericField("x", "Pivot X", 0);
d.AddNumericField("y", "Pivot Y", 0);
d.AddNumericField("z", "Pivot Z", 0);

d.AddNumericField("dx", "Dir X", 0);
d.AddNumericField("dy", "Dir Y", 0);
d.AddNumericField("dz", "Dir Z", 1);

if (!d.ShowDialog())
return;


var x = d.GetNumericField("x");
var y = d.GetNumericField("y");
var z = d.GetNumericField("z");

var dx = d.GetNumericField("dx");
var dy = d.GetNumericField("dy");
var dz = d.GetNumericField("dz");

proxy.MirrorObject(proxy.GetSelectedObject(), new Vector3(dx, dy, dz), new Vector3(dx, dy, dz), true, true);
}

private void toolStripButton7_Click(object sender, EventArgs e)
{

Expand Down Expand Up @@ -854,7 +920,7 @@ private void coneToolStripMenuItem_Click(object sender, EventArgs e)
{
AddCone();
}

private void facesInfoToolStripMenuItem_Click(object sender, EventArgs e)
{
FacesInfo();
Expand All @@ -873,12 +939,17 @@ public void SetTool(ITool tool)
}
private void adjointToolStripMenuItem_Click(object sender, EventArgs e)
{
AdjoinTool();
AdjoinTool(false);
}

public void AdjoinTool()
public void AdjoinTool(bool withDistance)
{
SetTool(new AdjoinTool(this, withDistance));

}
public void AdjoinCOMsTool()
{
SetTool(new AdjoinTool(this));
SetTool(new AdjoinCOMsTool(this));

}
public void FuseTool()
Expand Down Expand Up @@ -962,11 +1033,16 @@ internal void FacesInfo()
if (info is PlaneSurfInfo p)
r.AppendText($"PLANE {p.Position.X} {p.Position.Y} {p.Position.Z} normal: {p.Normal.X} {p.Normal.Y} {p.Normal.Z} {Environment.NewLine}");
else if (info is CylinderSurfInfo c)
r.AppendText($"CYLINDER {c.Position.X} {c.Position.Y} {c.Position.Z} radius: {c.Radius} {Environment.NewLine}");
r.AppendText($"CYLINDER {c.Position.X} {c.Position.Y} {c.Position.Z} axis: {c.Axis.X} {c.Axis.Y} {c.Axis.Z} radius: {c.Radius} {Environment.NewLine}");
else
r.AppendText($"{info.GetType().Name}{info.Position.X} {info.Position.Y} {info.Position.Z} {Environment.NewLine}");
}
ff.Show();
}

internal void RulerTool()
{
SetTool(new RulerTool(this));
}
}
}
22 changes: 18 additions & 4 deletions CascadeDesktop/GeomHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,24 @@ public class GeomHelpers
var temp = new Plane() { Location = plane2.Position.ToVector3d(), Normal = plane2.Normal.ToVector3d() };
var proj = temp.GetProjPoint(plane1.Position.ToVector3d());
proj = proj - plane1.Position.ToVector3d();//shift
if (proj.Length > eps)
{
return proj;
}
return proj;

}
return null;
}

public static Vector3d? GetAdjointFacesShift(CylinderSurfInfo cylinder1, CylinderSurfInfo cylinder2, float eps = 1e-8f)
{
var cross1 = Vector3d.Cross(cylinder1.Axis.ToVector3d(), cylinder2.Axis.ToVector3d());
if (Math.Abs(cross1.Length) < eps)
{//colinear
//just translate

var temp = new Plane() { Location = cylinder1.Position.ToVector3d(), Normal = cylinder1.Axis.ToVector3d() };
var proj = temp.GetProjPoint(cylinder2.COM.ToVector3d());
var proj2 = temp.GetProjPoint(cylinder1.COM.ToVector3d());
proj -= proj2;//shift
return proj;
}
return null;
}
Expand Down
1 change: 1 addition & 0 deletions CascadeDesktop/IEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public interface IEditor
{
OCCTProxy Proxy { get; }
void ResetTool();
void SetStatus(string text, InfoType type = InfoType.Info);
}
}
Binary file added CascadeDesktop/Icons/layer-shape-round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CascadeDesktop/Icons/ruler-triangle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 12 additions & 5 deletions CascadeDesktop/RibbonMenuWPF.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@
<!--<RibbonButton Label="Format Painter" KeyTip="FP" />-->
</RibbonGroup>
<RibbonGroup x:Name="model" Header="Model">
<RibbonButton x:Name="import" Click="Import_Click" Label="Import" KeyTip="X" SmallImageSource="Icons/fill-270.png" />
<RibbonMenuButton Label="Export as" SmallImageSource="Icons/blue-document-export.png" KeyTip="V">
<RibbonButton x:Name="import" Click="Import_Click" Label="Import" KeyTip="X" SmallImageSource="Icons/fill-270.png" />
<RibbonMenuButton Label="Export as" SmallImageSource="Icons/blue-document-export.png" KeyTip="V">
<RibbonMenuItem Header="Step" Click="StepExport_Click" KeyTip="T"/>
<RibbonMenuItem Header="Mesh" Click="ObjExport_Click" KeyTip="T"/>
</RibbonMenuButton>
<RibbonButton x:Name="delete" Click="Delete_Click" Label="Delete" SmallImageSource="Icons/eraser.ico" KeyTip="X" />
<RibbonButton x:Name="clone" Click="Clone_Click" Label="Clone" KeyTip="X" SmallImageSource="Icons/blue-document-view.png" />
<RibbonButton x:Name="facesInfo" Click="FacesInfo_Click" SmallImageSource="Icons/infocard.png" Label="Info" />
<RibbonButton x:Name="facesInfo" Click="FacesInfo_Click" SmallImageSource="Icons/infocard.png" Label="Info" />
<RibbonButton x:Name="ruler" Click="Ruler_Click" SmallImageSource="Icons/ruler-triangle.png" Label="Ruler" />

</RibbonGroup>
<RibbonGroup x:Name="add" Header="Add">
Expand All @@ -76,17 +77,23 @@
<RibbonGroup x:Name="transformations" Header="Transformations">
<RibbonButton x:Name="move" Click="Move_Click" Label="Move" SmallImageSource="Icons/arrow-move.png" KeyTip="X" />
<RibbonButton x:Name="rotate" Click="Rotate_Click" Label="Rotate" SmallImageSource="Icons/arrow-circle-315.png" KeyTip="X" />
<RibbonButton x:Name="mirror" Click="Mirror_Click" Label="Mirror" SmallImageSource="Icons/layer-flip.png" KeyTip="M" />

</RibbonGroup>
<!-- Employee And Payroll group-->


<RibbonGroup x:Name="operators" Header="Operators ">
<RibbonButton Label="Extrude" KeyTip="X" Click="Extrude_Click" SmallImageSource="Icons/fill-090.png"/>
<RibbonToggleButton x:Name="adjoinButton" Click="Adjoin_Click" Label="Adjoin" KeyTip="X" SmallImageSource="Icons/magnet.ico" />
<RibbonSplitButton Click="Adjoin_Click" Label="Adjoin" SmallImageSource="Icons/magnet.ico" >
<RibbonButton Label="With distance" Click="AdjoinWithDistance_Click"></RibbonButton>
<RibbonButton Label="COMs only" Click="AdjoinCOMs_Click"></RibbonButton>
</RibbonSplitButton>


<!--<RibbonButton Label="Merge" KeyTip="M" SmallImageSource="Icons/plug-connect.png"/>-->
<RibbonButton Label="Revolution" KeyTip="M" />
<RibbonButton Click="Fillet_Click" Label="Fillet" KeyTip="M" />
<RibbonButton Click="Fillet_Click" Label="Fillet" SmallImageSource="Icons/layer-shape-round.png" KeyTip="M" />
<RibbonButton Label="Chamfer" Click="Chamfer_Click" KeyTip="M" />
</RibbonGroup>
<RibbonGroup x:Name="bool" Header="Bool">
Expand Down
23 changes: 22 additions & 1 deletion CascadeDesktop/RibbonMenuWPF.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void Box_Click(object sender, RoutedEventArgs e)

private void Adjoin_Click(object sender, RoutedEventArgs e)
{
Form.AdjoinTool();
Form.AdjoinTool(false);
}

private void Grid_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -235,5 +235,26 @@ private void FacesInfo_Click(object sender, RoutedEventArgs e)
{
Form.FacesInfo();
}

private void Mirror_Click(object sender, RoutedEventArgs e)
{
Form.MirrorSelected();
}

private void AdjoinWithDistance_Click(object sender, RoutedEventArgs e)
{
Form.AdjoinTool(true);
}

private void Ruler_Click(object sender, RoutedEventArgs e)
{
Form.RulerTool();

}

private void AdjoinCOMs_Click(object sender, RoutedEventArgs e)
{
Form.AdjoinCOMsTool();
}
}
}
1 change: 1 addition & 0 deletions CascadeDesktop/StaticHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public static OpenTK.Vector3 ToVector3(this Vector3d v)
return new OpenTK.Vector3((float)v.X, (float)v.Y, (float)v.Z);
}


public static OpenTK.Vector2d ToVector2d(this DxfPoint v)
{
return new OpenTK.Vector2d(v.X, v.Y);
Expand Down
Loading

0 comments on commit 8575363

Please sign in to comment.