void ResetColors() { var undoMultiAction = new UndoMultiAction(); var groupsOfObjectToUpdate = new ESet <Component_GroupOfObjects>(); foreach (var elementSurface in GetObjects <Component_GroupOfObjectsElement>()) { var groupOfObjects = elementSurface.Parent as Component_GroupOfObjects; if (groupOfObjects != null) { elementSurface.ResetColors(undoMultiAction); groupsOfObjectToUpdate.AddWithCheckAlreadyContained(groupOfObjects); } } foreach (var groupOfObjects in groupsOfObjectToUpdate) { groupOfObjects.CreateSectors(); } if (undoMultiAction.Actions.Count != 0) { Provider.DocumentWindow.Document.CommitUndoAction(undoMultiAction); } }
private void ButtonClearObjects_Click(ProcedureUI.Button obj) { if (EditorMessageBox.ShowQuestion(Translate("Delete all objects of the element?"), MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } var undoMultiAction = new UndoMultiAction(); foreach (var element in GetObjects <Component_GroupOfObjectsElement>()) { var groupOfObjects = element.Parent as Component_GroupOfObjects; if (groupOfObjects != null) { var indexes = element.GetObjectsOfElement(); if (indexes.Count != 0) { var action = new Component_GroupOfObjects_Editor.UndoActionCreateDelete(groupOfObjects, indexes.ToArray(), false, true); undoMultiAction.AddAction(action); } } } if (undoMultiAction.Actions.Count != 0) { Provider.DocumentWindow.Document.CommitUndoAction(undoMultiAction); } }
private void ButtonClearAll_Click(ProcedureUI.Button sender) { if (EditorMessageBox.ShowQuestion(Translate("Delete all objects and child components?"), MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } var undoMultiAction = new UndoMultiAction(); foreach (var groupOfObjects in GetObjects <Component_GroupOfObjects>()) { var indexes = groupOfObjects.ObjectsGetAll(); if (indexes.Count != 0) { var action = new Component_GroupOfObjects_Editor.UndoActionCreateDelete(groupOfObjects, indexes.ToArray(), false, true); undoMultiAction.AddAction(action); } var components = groupOfObjects.GetComponents(); undoMultiAction.AddAction(new UndoActionComponentCreateDelete(Provider.DocumentWindow.Document, components, false)); } if (undoMultiAction.Actions.Count != 0) { Provider.DocumentWindow.Document.CommitUndoAction(undoMultiAction); } }
private void ButtonResizeMasks_Click(ProcedureUI.Button sender) { var terrain = GetTerrain(); if (terrain == null) { return; } var layers = GetLayersToResizeMask(terrain); if (layers.Count == 0) { return; } var text = string.Format(EditorLocalization.Translate("Terrain", "Resize masks of selected layers to {0}x{0}?"), terrain.GetPaintMaskSizeInteger()); if (EditorMessageBox.ShowQuestion(text, EMessageBoxButtons.OKCancel) == EDialogResult.OK) { var undoMultiAction = new UndoMultiAction(); foreach (var layer in layers) { var oldValue = layer.Mask; layer.Mask = Component_PaintLayer.ResizeMask(layer.Mask, terrain.GetPaintMaskSizeInteger()); var property = (Metadata.Property)layer.MetadataGetMemberBySignature("property:Mask"); var undoItem = new UndoActionPropertiesChange.Item(layer, property, oldValue); undoMultiAction.AddAction(new UndoActionPropertiesChange(undoItem)); } if (undoMultiAction.Actions.Count != 0) { Provider.DocumentWindow.Document.CommitUndoAction(undoMultiAction); } } }
private void ButtonBakeIntoMesh_Click(ProcedureUI.Button sender) { var document = Provider.DocumentWindow.Document; var undoMultiAction = new UndoMultiAction(); var modifiers = GetMeshModifiers(); if (modifiers.Length != 0) { string text; if (modifiers.Length > 1) { text = Translate("Bake selected geometries into the mesh?"); } else { text = Translate("Bake selected geometry into the mesh?"); } if (EditorMessageBox.ShowQuestion(text, System.Windows.Forms.MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK) { //bake foreach (var modifier in modifiers) { modifier.BakeIntoMesh(document, undoMultiAction); } //delete and add to undo undoMultiAction.AddAction(new UndoActionComponentCreateDelete(document, modifiers, false)); if (undoMultiAction.Actions.Count != 0) { document.CommitUndoAction(undoMultiAction); } } } }
private unsafe void ButtonUpdateAlignment_Click(ProcedureUI.Button sender) { var undoMultiAction = new UndoMultiAction(); var groupsOfObjectToUpdate = new ESet <Component_GroupOfObjects>(); foreach (var element in GetObjects <Component_GroupOfObjectsElement>()) { var groupOfObjects = element.Parent as Component_GroupOfObjects; if (groupOfObjects != null) { var elementMesh = element as Component_GroupOfObjectsElement_Mesh; if (elementMesh != null) { elementMesh.UpdateAlignment(undoMultiAction); groupsOfObjectToUpdate.AddWithCheckAlreadyContained(groupOfObjects); } var elementSurface = element as Component_GroupOfObjectsElement_Surface; if (elementSurface != null) { elementSurface.UpdateAlignment(undoMultiAction); groupsOfObjectToUpdate.AddWithCheckAlreadyContained(groupOfObjects); } } } foreach (var groupOfObjects in groupsOfObjectToUpdate) { groupOfObjects.CreateSectors(); } if (undoMultiAction.Actions.Count != 0) { Provider.DocumentWindow.Document.CommitUndoAction(undoMultiAction); } }
protected virtual void StopToolModify(bool cancel) { //update rendering data foreach (var item in needUpdateRectangle) { item.Terrain.UpdateRenderingData(item.Rectangle, true, true, true); } //update collision if (!cancel) { foreach (var item in needUpdateRectangle) { item.Terrain.UpdateCollisionData(item.Rectangle); ////update MapObject's alignment //{ // const int border = 2; // Vec2I indexMin = item.needUpdateCollisionRectangle.Minimum - new Vec2I( border, border ); // Vec2I indexMax = item.needUpdateCollisionRectangle.Maximum + new Vec2I( border, border ); // item.terrain.ClampCellIndex( ref indexMin ); // item.terrain.ClampCellIndex( ref indexMax ); // Rect rectangle = new Rect( item.terrain.GetPositionXY( indexMin ), // item.terrain.GetPositionXY( indexMax ) ); // if( EntitiesEditManager.Instance != null ) // EntitiesEditManager.Instance.UpdateObjectsVerticalAlignment( rectangle ); //} } } needUpdateRectangle.Clear(); //add to undo if (geometryChangeUndoActions.Count != 0) { if (cancel) { foreach (var action in geometryChangeUndoActions) { action.RestoreOldValues(); } } else { var multiAction = new UndoMultiAction(); foreach (var action in geometryChangeUndoActions) { multiAction.AddAction(action); } DocumentWindow.Document.CommitUndoAction(multiAction); } geometryChangeUndoActions.Clear(); } if (paintSetPropertyUndoActions.Count != 0) { if (cancel) { foreach (var action in paintSetPropertyUndoActions) { action.PerformUndo(); } } else { var multiAction = new UndoMultiAction(); foreach (var action in paintSetPropertyUndoActions) { multiAction.AddAction(action); } DocumentWindow.Document.CommitUndoAction(multiAction); } paintSetPropertyUndoActions.Clear(); } if (paintChangeUndoActions.Count != 0) { if (cancel) { foreach (var action in paintChangeUndoActions) { action.PerformUndo(); } } else { var multiAction = new UndoMultiAction(); foreach (var action in paintChangeUndoActions) { multiAction.AddAction(action); } DocumentWindow.Document.CommitUndoAction(multiAction); } paintChangeUndoActions.Clear(); } //if( holeChangeUndoActions.Count != 0 ) //{ // UndoMultiAction multiAction = new UndoMultiAction(); // foreach( UndoSystem.Action action in holeChangeUndoActions ) // multiAction.AddAction( action ); // UndoSystem.Instance.CommitAction( multiAction ); // holeChangeUndoActions.Clear(); //} toolModify = false; }
//bool CanPaste( out Component destinationParent ) //{ // if( ClipboardManager.CheckAvailableInClipboard<ObjectCutCopyPasteData>() ) // { // destinationParent = ObjectOfWindow as Component; // if( destinationParent != null ) // return true; // } // destinationParent = null; // return false; //} public virtual bool Paste() { if (!CanPaste(out var destinationParent)) { return(false); } var data = ClipboardManager.GetFromClipboard <ObjectCutCopyPasteData>(); if (data != null) { var components = new List <Component>(); foreach (var obj in data.objects) { var c = obj as Component; if (c != null) { components.Add(c); } } //create new objects var newObjects = new List <Component>(); Vector3 addToPosition = Vector3.Zero; for (int n = 0; n < components.Count; n++) { var c = components[n]; var cloned = c.Clone(); if (destinationParent.GetComponent(c.Name) == null) { cloned.Name = c.Name; } else { cloned.Name = destinationParent.Components.GetUniqueName(c.Name, true, 2); } destinationParent.AddComponent(cloned); newObjects.Add(cloned); } if (data.cut) { //cut if (data.documentWindow.Document != Document) { //another document { var action = new UndoActionComponentCreateDelete(data.documentWindow.Document, components, false); data.documentWindow.Document.UndoSystem.CommitAction(action); data.documentWindow.Document.Modified = true; } { var action = new UndoActionComponentCreateDelete(Document, newObjects, true); Document.UndoSystem.CommitAction(action); Document.Modified = true; } } else { //same document var multiAction = new UndoMultiAction(); multiAction.AddAction(new UndoActionComponentCreateDelete(Document, components, false)); multiAction.AddAction(new UndoActionComponentCreateDelete(Document, newObjects, true)); Document.UndoSystem.CommitAction(multiAction); Document.Modified = true; } } else { //copy var action = new UndoActionComponentCreateDelete(Document, newObjects, true); Document.UndoSystem.CommitAction(action); Document.Modified = true; } } return(true); }
private unsafe void ButtonUpdateAlignment_Click(ProcedureUI.Button sender) { var undoMultiAction = new UndoMultiAction(); foreach (var groupOfObjects in GetObjects <Component_GroupOfObjects>()) { foreach (var element in groupOfObjects.GetComponents <Component_GroupOfObjectsElement>()) { var elementMesh = element as Component_GroupOfObjectsElement_Mesh; if (elementMesh != null) { elementMesh.UpdateAlignment(undoMultiAction); } var elementSurface = element as Component_GroupOfObjectsElement_Surface; if (elementSurface != null) { elementSurface.UpdateAlignment(undoMultiAction); } } groupOfObjects.CreateSectors(); } if (undoMultiAction.Actions.Count != 0) { Provider.DocumentWindow.Document.CommitUndoAction(undoMultiAction); } //var undoMultiAction = new UndoMultiAction(); //foreach( var groupOfObjects in GetObjects<Component_GroupOfObjects>() ) // groupOfObjects.UpdateItems( null, undoMultiAction ); //if( undoMultiAction.Actions.Count != 0 ) // Provider.DocumentWindow.Document.CommitUndoAction( undoMultiAction ); //int counter = 0; //int counter2 = 0; //foreach( var groupOfObjects in GetObjects<Component_GroupOfObjects>() ) //{ // { // int count = 50; // var data = new byte[ count * sizeof( Component_GroupOfObjects.ObjectMesh ) ]; // fixed ( byte* pData = data ) // { // Component_GroupOfObjects.ObjectMesh* pMeshObjects = (Component_GroupOfObjects.ObjectMesh*)pData; // for( int n = 0; n < count; n++ ) // { // //pMeshObjects[ n ] = new Component_GroupOfObjects.ObjectMesh( 3, (ushort)( counter2 % 3 ), // // new Vector3( n * 3 - 25, counter * 3, 0 ), QuaternionF.Identity, Vector3F.One, // // new Vector3( n * 3 - 25, counter * 3, 0 ), QuaternionF.Identity, Vector3F.One ); // //pMeshObjects[ n ] = new Component_GroupOfObjects.ObjectMesh( (ushort)( counter2 % 3 ), 0, // // new Vector3( n * 3 - 25, counter * 3, 0 ), QuaternionF.Identity, Vector3F.One, // // new Vector3( n * 3 - 25, counter * 3, 0 ), QuaternionF.Identity, Vector3F.One ); // counter2++; // } // groupOfObjects.ObjectsMeshAdd( (Component_GroupOfObjects.ObjectMesh*)pData, count ); // //ObjectsMeshSet( (ObjectMesh*)pData, 50 ); // } // } // counter++; //} }
public override void Register() { //Attach second selected to first { const string transformOffsetName = "Attach Transform Offset"; var a = new EditorAction(); a.Name = "Attach Second to First"; a.Description = "Attaches the second, third and next selected objects to the first selected object."; a.ImageSmall = Properties.Resources.Attach_16; a.ImageBig = Properties.Resources.Attach_32; a.RibbonText = ("Attach", ""); //!!!!выключить где-то? a.QatSupport = true; //a.qatAddByDefault = true; a.ContextMenuSupport = EditorContextMenuWinForms.MenuTypeEnum.Document; a.GetState += delegate(EditorAction.GetStateContext context) { if (context.ObjectsInFocus.DocumentWindow != null) { object[] selectedObjects = context.ObjectsInFocus.Objects; if (selectedObjects.Length > 1) { var first = selectedObjects[0] as Component_ObjectInSpace; if (first != null) { for (int n = 1; n < selectedObjects.Length; n++) { var second = selectedObjects[n] as Component_ObjectInSpace; if (second != null) { var objectToTransform = Component_ObjectInSpace_Utility.CalculateObjectToTransform(second); if (objectToTransform != null) { second = objectToTransform; } //!!!!проверять? second.GetComponentByName( transformOffsetName ) as Component_TransformOffset == null if (!second.Transform.ReferenceSpecified && second.GetComponent(transformOffsetName) as Component_TransformOffset == null) { context.Enabled = true; } } ////!!!!проверять? second.GetComponentByName( transformOffsetName ) as Component_TransformOffset == null //if( second != null && !second.Transform.ReferenceSpecified && second.GetComponent( transformOffsetName ) as Component_TransformOffset == null ) //{ // context.Enabled = true; //} } } } } }; a.Click += delegate(EditorAction.ClickContext context) { object[] selectedObjects = context.ObjectsInFocus.Objects; var undoMultiAction = new UndoMultiAction(); var first = selectedObjects[0] as Component_ObjectInSpace; for (int n = 1; n < selectedObjects.Length; n++) { var second = selectedObjects[n] as Component_ObjectInSpace; if (second != null) { Component_ObjectInSpace_Utility.Attach(first, second, context.ObjectsInFocus.DocumentWindow.Document, undoMultiAction); } } context.ObjectsInFocus.DocumentWindow.Document.UndoSystem.CommitAction(undoMultiAction); context.ObjectsInFocus.DocumentWindow.Document.Modified = true; ScreenNotifications.Show(Translate("The object was attached to another object.")); //var undoActions = new List<UndoSystem.Action>(); //var first = selectedObjects[ 0 ] as Component_ObjectInSpace; //for( int n = 1; n < selectedObjects.Length; n++ ) //{ // var second = selectedObjects[ n ] as Component_ObjectInSpace; // if( second != null ) // { // var objectToTransform = Component_ObjectInSpace_Utility.CalculateObjectToTransform( second ); // if( objectToTransform != null ) // second = objectToTransform; // //create _TransformOffset // Component_TransformOffset transformOffset; // { // transformOffset = second.CreateComponent<Component_TransformOffset>( -1, false ); // transformOffset.Name = transformOffsetName; // transformOffset.Source = ReferenceUtility.MakeReference<Transform>( null, ReferenceUtility.CalculateThisReference( transformOffset, first, "Transform" ) ); // try // { // var f = first.Transform.Value; // var s = second.Transform.Value; // var offset = f.ToMatrix4().GetInverse() * s.ToMatrix4(); // offset.Decompose( out Vector3 pos, out Quaternion rot, out Vector3 scl ); // transformOffset.PositionOffset = pos; // transformOffset.RotationOffset = rot; // transformOffset.ScaleOffset = scl; // //transformOffset.Matrix = offset; // //var offset = new Mat4( s.Rotation.ToMat3(), s.Position ) * new Mat4( f.Rotation.ToMat3(), f.Position ).GetInverse(); // //var f = first.Transform.Value; // //var s = second.Transform.Value; // //var offset = new Mat4( s.Rotation.ToMat3(), s.Position ) * new Mat4( f.Rotation.ToMat3(), f.Position ).GetInverse(); // ////var offset = second.Transform.Value.ToMat4() * first.Transform.Value.ToMat4().GetInverse(); // //offset.Decompose( out Vec3 pos, out Quat rot, out Vec3 scl ); // //transformOffset.PositionOffset = pos / f.Scale;// / s.Scale; // //transformOffset.RotationOffset = rot; // //transformOffset.ScaleOffset = s.Scale / f.Scale; // ////transformOffset.ScaleOffset = scl; // } // catch { } // transformOffset.Enabled = true; // undoActions.Add( new UndoActionComponentCreateDelete( context.ObjectsInFocus.DocumentWindow.Document, new Component[] { transformOffset }, true ) ); // } // //change Transform // { // //undo action // var property = (Metadata.Property)second.MetadataGetMemberBySignature( "property:Transform" ); // var undoItem = new UndoActionPropertiesChange.Item( second, property, second.Transform, new object[ 0 ] ); // undoActions.Add( new UndoActionPropertiesChange( new UndoActionPropertiesChange.Item[] { undoItem } ) ); // //configure reference // second.Transform = ReferenceUtility.MakeReference<Transform>( null, ReferenceUtility.CalculateThisReference( second, transformOffset, "Result" ) ); // } // } //} //context.ObjectsInFocus.DocumentWindow.Document.UndoSystem.CommitAction( new UndoMultiAction( undoActions ) ); //context.ObjectsInFocus.DocumentWindow.Document.Modified = true; //ScreenNotifications.Show( "The object was attached to another object." ); }; EditorActions.Register(a); } //Detach from Another Object { //const string transformOffsetName = "Attach Transform Offset"; var a = new EditorAction(); a.Name = "Detach from Another Object"; a.Description = "Detaches selected objects from another object."; a.ImageSmall = Properties.Resources.Detach_16; a.ImageBig = Properties.Resources.Detach_32; a.RibbonText = ("Detach", ""); //!!!!выключить где-то? a.QatSupport = true; //a.qatAddByDefault = true; a.ContextMenuSupport = EditorContextMenuWinForms.MenuTypeEnum.Document; a.GetState += delegate(EditorAction.GetStateContext context) { if (context.ObjectsInFocus.DocumentWindow != null) { object[] selectedObjects = context.ObjectsInFocus.Objects; if (selectedObjects.Length != 0 && Array.TrueForAll(selectedObjects, obj => obj is Component_ObjectInSpace)) { foreach (Component_ObjectInSpace objectInSpace in selectedObjects) { var objectToDetach = Component_ObjectInSpace_Utility.FindObjectToDetach(objectInSpace); if (objectToDetach != null) { context.Enabled = true; break; } //var objectInSpace = objectInSpace2; //var objectToTransform = Component_ObjectInSpace_Utility.CalculateObjectToTransform( objectInSpace ); //if( objectToTransform != null ) // objectInSpace = objectToTransform; //if( objectInSpace.GetComponent( transformOffsetName ) as Component_TransformOffset != null ) //{ // context.Enabled = true; // break; //} } //context.Enabled = Array.Exists( selectedObjects, // obj => ( (Component)obj ).GetComponent( transformOffsetName ) as Component_TransformOffset != null ); } } }; a.Click += delegate(EditorAction.ClickContext context) { if (EditorMessageBox.ShowQuestion(Translate("Detach from another object?"), EMessageBoxButtons.YesNo) == EDialogResult.Yes) { var undoMultiAction = new UndoMultiAction(); foreach (Component_ObjectInSpace objectInSpace in context.ObjectsInFocus.Objects) { var objectToDetach = Component_ObjectInSpace_Utility.FindObjectToDetach(objectInSpace); if (objectToDetach != null) { Component_ObjectInSpace_Utility.Detach(objectToDetach, context.ObjectsInFocus.DocumentWindow.Document, undoMultiAction); } } if (undoMultiAction.Actions.Count != 0) { context.ObjectsInFocus.DocumentWindow.Document.UndoSystem.CommitAction(undoMultiAction); context.ObjectsInFocus.DocumentWindow.Document.Modified = true; ScreenNotifications.Show(Translate("The object was detached from another object.")); } //var undoActions = new List<UndoSystem.Action>(); //foreach( Component_ObjectInSpace objectInSpace2 in context.ObjectsInFocus.Objects ) //{ // var objectInSpace = objectInSpace2; // var objectToTransform = Component_ObjectInSpace_Utility.CalculateObjectToTransform( objectInSpace ); // if( objectToTransform != null ) // objectInSpace = objectToTransform; // var transformOffset = objectInSpace.GetComponent( transformOffsetName ) as Component_TransformOffset; // if( transformOffset != null ) // { // //change Transform // { // //undo action // var property = (Metadata.Property)objectInSpace.MetadataGetMemberBySignature( "property:Transform" ); // var undoItem = new UndoActionPropertiesChange.Item( objectInSpace, property, objectInSpace.Transform, new object[ 0 ] ); // undoActions.Add( new UndoActionPropertiesChange( new UndoActionPropertiesChange.Item[] { undoItem } ) ); // //remove reference // objectInSpace.Transform = new Reference<Transform>( objectInSpace.Transform, "" ); // } // //delete // undoActions.Add( new UndoActionComponentCreateDelete( context.ObjectsInFocus.DocumentWindow.Document, new Component[] { transformOffset }, false ) ); // } //} //if( undoActions.Count != 0 ) //{ // context.ObjectsInFocus.DocumentWindow.Document.UndoSystem.CommitAction( new UndoMultiAction( undoActions ) ); // context.ObjectsInFocus.DocumentWindow.Document.Modified = true; // ScreenNotifications.Show( "The object was detached from another object." ); //} } }; EditorActions.Register(a); } }