Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
CommandChangeState.cs
Package: DrawTools2005.rar [view]
Upload User: sxsgcs
Upload Date: 2013-10-21
Package Size: 110k
Code Size: 2k
Category:
CAD
Development Platform:
C#
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace DrawTools
- {
- /// <summary>
- /// Changing state of existing objects:
- /// move, resize, change properties.
- /// </summary>
- class CommandChangeState : Command
- {
- // Selected object(s) before operation
- List<DrawObject> listBefore;
- // Selected object(s) after operation
- List<DrawObject> listAfter;
- // Create this command BEFORE operation.
- public CommandChangeState(GraphicsList graphicsList)
- {
- // Keep objects state before operation.
- FillList(graphicsList, ref listBefore);
- }
- // Call this function AFTER operation.
- public void NewState(GraphicsList graphicsList)
- {
- // Keep objects state after operation.
- FillList(graphicsList, ref listAfter);
- }
- public override void Undo(GraphicsList list)
- {
- // Replace all objects in the list with objects from listBefore
- ReplaceObjects(list, listBefore);
- }
- public override void Redo(GraphicsList list)
- {
- // Replace all objects in the list with objects from listAfter
- ReplaceObjects(list, listAfter);
- }
- // Replace objects in graphicsList with objects from list
- private void ReplaceObjects(GraphicsList graphicsList, List<DrawObject> list)
- {
- for ( int i = 0; i < graphicsList.Count; i++ )
- {
- DrawObject replacement = null;
- foreach(DrawObject o in list)
- {
- if ( o.ID == graphicsList[i].ID )
- {
- replacement = o;
- break;
- }
- }
- if ( replacement != null )
- {
- graphicsList.Replace(i, replacement);
- }
- }
- }
- // Fill list from selection
- private void FillList(GraphicsList graphicsList, ref List<DrawObject> listToFill)
- {
- listToFill = new List<DrawObject>();
- foreach (DrawObject o in graphicsList.Selection)
- {
- listToFill.Add(o.Clone());
- }
- }
- }
- }