Move MatterControl source code into a subdirectory

This commit is contained in:
Nettika 2026-01-28 21:30:58 -08:00
parent 2c6e34243a
commit 70af2d9ae8
Signed by: nettika
SSH key fingerprint: SHA256:f+PJrfIq49zrQ6dQrHj18b+PJKmAldeAMiGdj8IzXCA
2007 changed files with 13 additions and 8 deletions

View file

@ -0,0 +1,88 @@
/*
Copyright (c) 2017, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System.Collections.Generic;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class ChangeColor : IUndoRedoCommand
{
private List<PrintOutputTypes> itemsPrintOutputType = new List<PrintOutputTypes>();
private List<Color> itemsColor = new List<Color>();
private List<IObject3D> itemsToChange = new List<IObject3D>();
private Color color;
private PrintOutputTypes outputTypeToSet;
public ChangeColor(IObject3D selectedItem, Color color, PrintOutputTypes outputType)
{
this.color = color;
this.outputTypeToSet = outputType;
if (selectedItem is SelectionGroupObject3D)
{
SetData(selectedItem.Children.ToList());
}
else
{
SetData(new List<IObject3D> { selectedItem });
}
}
void SetData(List<IObject3D> itemsToChange)
{
foreach (var item in itemsToChange)
{
this.itemsToChange.Add(item);
this.itemsColor.Add(item.Color);
this.itemsPrintOutputType.Add(item.OutputType);
}
}
void IUndoRedoCommand.Do()
{
foreach(var item in this.itemsToChange)
{
item.OutputType = outputTypeToSet;
item.Color = color;
}
}
void IUndoRedoCommand.Undo()
{
for(int i=0; i< this.itemsToChange.Count; i++)
{
itemsToChange[i].OutputType = itemsPrintOutputType[i];
itemsToChange[i].Color = itemsColor[i];
}
}
}
}

View file

@ -0,0 +1,86 @@
/*
Copyright (c) 2017, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System.Collections.Generic;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class ChangeMaterial : IUndoRedoCommand
{
List<PrintOutputTypes> itemsPrintOutputType = new List<PrintOutputTypes>();
List<int> itemsMaterialIndex = new List<int>();
List<IObject3D> itemsToChange = new List<IObject3D>();
int materialIndex;
public ChangeMaterial(IObject3D selectedItem, int materialIndex)
{
this.materialIndex = materialIndex;
if (selectedItem is SelectionGroupObject3D)
{
SetData(selectedItem.Children.ToList());
}
else
{
SetData(new List<IObject3D> { selectedItem });
}
}
void SetData(List<IObject3D> itemsToChange)
{
foreach (var item in itemsToChange)
{
this.itemsToChange.Add(item);
this.itemsMaterialIndex.Add(item.MaterialIndex);
this.itemsPrintOutputType.Add(item.OutputType);
}
}
void IUndoRedoCommand.Do()
{
foreach(var item in this.itemsToChange)
{
item.OutputType = PrintOutputTypes.Solid;
item.MaterialIndex = materialIndex;
}
}
void IUndoRedoCommand.Undo()
{
for(int i=0; i< this.itemsToChange.Count; i++)
{
itemsToChange[i].OutputType = itemsPrintOutputType[i];
itemsToChange[i].MaterialIndex = itemsMaterialIndex[i];
}
}
}
}

View file

@ -0,0 +1,93 @@
/*
Copyright (c) 2016, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System.Collections.Generic;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.MeshVisualizer;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class DeleteCommand : IUndoRedoCommand
{
private List<(IObject3D parent, IObject3D item)> items = new List<(IObject3D parent, IObject3D item)>();
private InteractiveScene scene;
public DeleteCommand(InteractiveScene scene, IObject3D deletingItem)
{
if (deletingItem is SelectionGroupObject3D)
{
SetDeletionObjects(scene, deletingItem.Children);
}
else
{
SetDeletionObjects(scene, new IObject3D[] { deletingItem });
}
}
public DeleteCommand(InteractiveScene scene, IEnumerable<IObject3D> deletingItems)
{
SetDeletionObjects(scene, deletingItems);
}
private void SetDeletionObjects(InteractiveScene scene, IEnumerable<IObject3D> deletingItems)
{
this.scene = scene;
scene.ClearSelection();
// save them in our list
foreach (var item in deletingItems)
{
items.Add((item.Parent, item));
}
}
public void Do()
{
using (new DataConverters3D.SelectionMaintainer(scene))
{
foreach(var item in items)
{
item.parent.Children.Remove(item.item);
}
}
}
public void Undo()
{
using (new DataConverters3D.SelectionMaintainer(scene))
{
foreach (var item in items)
{
item.parent.Children.Add(item.item);
}
}
}
}
}

View file

@ -0,0 +1,101 @@
/*
Copyright (c) 2016, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.VectorMath;
using System.Collections.Generic;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class InsertCommand : IUndoRedoCommand
{
private IEnumerable<IObject3D> items;
private InteractiveScene scene;
private bool selectAfterInsert;
bool firstPass = true;
public InsertCommand(InteractiveScene scene, IObject3D insertingItem, bool selectAfterInsert = true)
: this(scene, new IObject3D[] { insertingItem }, selectAfterInsert)
{
}
public InsertCommand(InteractiveScene scene, IEnumerable<IObject3D> insertingItem, bool selectAfterInsert = true)
{
this.scene = scene;
this.items = insertingItem;
this.selectAfterInsert = selectAfterInsert;
}
public void Do()
{
if (!firstPass)
{
firstPass = false;
}
scene.Children.Modify(list => list.AddRange(items));
scene.SelectedItem = null;
if (selectAfterInsert)
{
foreach (var item in items)
{
scene.AddToSelection(item);
}
}
if (scene.SelectedItem is SelectionGroupObject3D selectionGroup)
{
selectionGroup.Expanded = true;
}
scene.Invalidate(new InvalidateArgs(null, InvalidateType.Children));
}
public void Undo()
{
bool clearSelection = scene.SelectedItem == items;
scene.Children.Modify(list =>
{
foreach (var item in items)
{
list.Remove(item);
}
});
if(clearSelection)
{
scene.SelectedItem = null;
}
scene.Invalidate(new InvalidateArgs(null, InvalidateType.Children));
}
}
}

View file

@ -0,0 +1,79 @@
/*
Copyright (c) 2022, Lars Brubaker
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System.Collections.Generic;
using System.Linq;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class MakeHole : IUndoRedoCommand
{
private List<PrintOutputTypes> itemsPrintOutputType = new List<PrintOutputTypes>();
private List<IObject3D> itemsToChange = new List<IObject3D>();
public MakeHole(IObject3D selectedItem)
{
if (selectedItem is SelectionGroupObject3D)
{
SetData(selectedItem.Children.ToList());
}
else
{
SetData(new List<IObject3D> { selectedItem });
}
}
void SetData(List<IObject3D> itemsToChange)
{
foreach (var item in itemsToChange)
{
this.itemsToChange.Add(item);
this.itemsPrintOutputType.Add(item.OutputType);
}
}
void IUndoRedoCommand.Do()
{
foreach (var item in this.itemsToChange)
{
item.OutputType = PrintOutputTypes.Hole;
}
}
void IUndoRedoCommand.Undo()
{
for (int i = 0; i < this.itemsToChange.Count; i++)
{
itemsToChange[i].OutputType = itemsPrintOutputType[i];
}
}
}
}

View file

@ -0,0 +1,82 @@
/*
Copyright (c) 2017, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System.Collections.Generic;
using System.Linq;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class SetOutputType : IUndoRedoCommand
{
List<PrintOutputTypes> startingOutputType = new List<PrintOutputTypes>();
List<IObject3D> itemsToChange = new List<IObject3D>();
PrintOutputTypes outputType;
public SetOutputType(IObject3D selectedItem, PrintOutputTypes outputType)
{
this.outputType = outputType;
if (selectedItem is SelectionGroupObject3D)
{
SetData(selectedItem.Children.ToList());
}
else
{
SetData(new List<IObject3D> { selectedItem });
}
}
void SetData(List<IObject3D> itemsToChange)
{
foreach (var item in itemsToChange)
{
this.itemsToChange.Add(item);
this.startingOutputType.Add(item.OutputType);
}
}
void IUndoRedoCommand.Do()
{
for (int i = 0; i < this.itemsToChange.Count; i++)
{
itemsToChange[i].OutputType = outputType;
}
}
void IUndoRedoCommand.Undo()
{
for(int i=0; i< this.itemsToChange.Count; i++)
{
itemsToChange[i].OutputType = startingOutputType[i];
}
}
}
}

View file

@ -0,0 +1,102 @@
/*
Copyright (c) 2016, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System.Collections.Generic;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.PolygonMesh;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
internal class TransformData
{
public IObject3D TransformedObject { get; set; }
public Matrix4X4 RedoTransform { get; set; }
public Matrix4X4 UndoTransform { get; set; }
}
internal class TransformCommand : IUndoRedoCommand
{
private List<TransformData> transformDatas = new List<TransformData>();
public TransformCommand(List<TransformData> transformDatas)
{
this.transformDatas = transformDatas;
}
public TransformCommand(IObject3D transformedObject, Matrix4X4 undoTransform, Matrix4X4 redoTransform)
{
if (transformedObject is SelectionGroupObject3D)
{
// move the group transform into the items
foreach (var child in transformedObject.Children)
{
var itemUndo = new TransformData()
{
TransformedObject = child,
UndoTransform = child.Matrix,
RedoTransform = child.Matrix * transformedObject.Matrix
};
this.transformDatas.Add(itemUndo);
child.Matrix = itemUndo.RedoTransform;
}
// clear the group transform
transformedObject.Matrix = Matrix4X4.Identity;
}
else
{
this.transformDatas.Add(new TransformData()
{
TransformedObject = transformedObject,
UndoTransform = undoTransform,
RedoTransform = redoTransform
});
}
}
public void Do()
{
foreach(var transformData in transformDatas)
{
transformData.TransformedObject.Matrix = transformData.RedoTransform;
}
}
public void Undo()
{
foreach (var transformData in transformDatas)
{
transformData.TransformedObject.Matrix = transformData.UndoTransform;
}
}
}
}

View file

@ -0,0 +1,99 @@
/*
Copyright (c) 2016, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.MeshVisualizer;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class UngroupCommand : IUndoRedoCommand
{
private IObject3D originalItem;
private InteractiveScene scene;
public UngroupCommand(InteractiveScene scene, IObject3D ungroupingItem)
{
this.originalItem = ungroupingItem;
this.scene = scene;
}
public void Do()
{
if (!scene.Children.Contains(originalItem))
{
return;
}
scene.Children.Modify(list =>
{
// Remove the group
list.Remove(originalItem);
// Apply transform
foreach(var child in originalItem.Children)
{
child.Matrix *= originalItem.Matrix;
}
// Add all children from the group
list.AddRange(originalItem.Children);
});
scene.SelectLastChild();
scene.Invalidate(new InvalidateArgs(null, InvalidateType.Children));
}
public void Undo()
{
// Remove the children from the Scene root, add the original item back into the root
scene.Children.Modify(list =>
{
foreach(var child in originalItem.Children)
{
if (list.Contains(child))
{
list.Remove(child);
}
Matrix4X4 inverseMatrix = originalItem.Matrix;
inverseMatrix.Invert();
child.Matrix = inverseMatrix * child.Matrix;
}
list.Add(originalItem);
});
scene.SelectLastChild();
scene.Invalidate(new InvalidateArgs(null, InvalidateType.Children));
}
}
}