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
DiagramEntity.cpp
Package: solidgraph_sources.zip [view]
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 55k
Category:
Graph program
Development Platform:
Visual C++
- /* ==========================================================================
- Class : CDiagramEntity
- Author : Johan Rosengren, Abstrakt Mekanik AB
- Date : 2004-03-29
- Purpose : "CDiagramEntity" is the base class for all objects that can
- be drawn and managed by "CDiagramEditor".
- Description : "CDiagramEntity" is derived from "CObject", to allow
- instances to be stored in "CObArrays".
- Usage : Classes should be derived from "CDiagramEntity". "Clone"
- must be overridden, returning a copy of the this
- pointer.
- Normally, "Draw" should also be overridden.
- The class supports basic saving to a text file. If this
- is desired, "SetType" must be called from the derived
- class ctor with a string uniquely identifying the class.
- "FromString" and "GetString" must be overridden if other
- properties than the default are to be saved. Loading can
- be accomplished by creating a static "factory"-function
- returning an instance of the class if "FromString" returns
- "TRUE" for a given line from a data file. See "CreateFromString"
- in this class for a model implementation.
- Minimum- and maximum sizes for an instance of the
- derived object can be set in the class ctor by calling
- "SetConstraints". A 0-constraint means that the object
- can't be turned "inside out", while -1 means no
- constraints.
- Popup menus for the derived classes can be created by
- overriding "ShowPopup". Command ids for the menu items
- must be in the range "CMD_START" to "CMD_END" inclusively,
- and if a menu alternative is selected, it will be
- returned to the class instance through "DoMessage" -
- which must of course also be overriddden.
- Each derived class can also have a property dialog. The
- dialog class must be derived from "CDiagramPropertyDlg".
- The derived "CDiagramEntity" class must have a class
- member instance of the desired "CDiagramPropertyDlg"-
- derived class, and call "SetAttributeDialog" in the "ctor".
- Transport of data to and from the object is made in the
- "CDiagramPropertyDlg"-derived class (see
- CDiagramPropertyDlg.cpp)
- The number, position and types of the selection rects
- can be modified by overriding "GetHitCode" and
- "DrawSelectionMarkers", see CDiagramLine.cpp for an
- example.
- "BodyInRect" can be overridden to allow non-rect hit
- testing, see CDiagramLine.cpp for an example.
- "GetCursor" can be overridden to display other cursors
- than the default ones.
- ========================================================================
- Changes : 10/4 2004 Changed accessors for m_type to public.
- 24/4 2004 Added colon as a replace-character for
- saving
- 30/4 2004 Added redraw parent to the property dialog
- ========================================================================
- 23/6 2004 Added \newline as a replace-character when
- saving/loading (Unruled Boy).
- 26/6 2004 Added group handling (Unruled Boy).
- 27/6 2004 Added help functions for saving and loading
- ========================================================================
- 19/8 2004 Setting m_parent to NULL in the ctor (Marc G)
- ========================================================================
- 23/1 2005 Made SetParent/GetParent public.
- ========================================================================*/
- #include "stdafx.h"
- #include "DiagramEntity.h"
- #include "DiagramEntityContainer.h"
- #include "Tokenizer.h"
- #include "..//UnitConversion.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDiagramEntity
- CDiagramEntity::CDiagramEntity()
- /* ============================================================
- Function : CDiagramEntity::CDiagramEntity
- Description : Constructor
- Access : Public
- Return : void
- Parameters : none
- Usage :
- ============================================================*/
- {
- SetParent( NULL );
- SetAttributeDialog( NULL, 0 );
- Clear();
- SetType( _T( "basic" ) );
- SetGroup( 0 );
- }
- CDiagramEntity::~CDiagramEntity()
- /* ============================================================
- Function : CDiagramEntity::~CDiagramEntity
- Description : Destructor
- Access : Public
- Return : void
- Parameters : none
- Usage :
- ============================================================*/
- {
- }
- void CDiagramEntity::Clear()
- /* ============================================================
- Function : CDiagramEntity::Clear
- Description : Zero all properties of this object.
- Access : Protected
- Return : void
- Parameters : none
- Usage : Call to initialize the object.
- ============================================================*/
- {
- SetRect( 0.0, 0.0, 0.0, 0.0 );
- SetMarkerSize( CSize( 8, 8 ) );
- SetConstraints( CSize( 1, 1 ), CSize( -1, -1 ) );
- Select( FALSE );
- SetParent( NULL );
- SetName( _T( "" ) );
- }
- CDiagramEntity* CDiagramEntity::Clone()
- /* ============================================================
- Function : CDiagramEntity::Clone
- Description : Clone this object to a new object.
- Access : Public
- Return : CDiagramEntity* - The new object.
- Parameters : none
- Usage : Call to create a clone of the object. The
- caller will have to delete the object.
- ============================================================*/
- {
- CDiagramEntity* obj = new CDiagramEntity;
- obj->Copy( this );
- return obj;
- }
- void CDiagramEntity::Copy( CDiagramEntity* obj )
- /* ============================================================
- Function : CDiagramEntity::Copy
- Description : Copy the information in "obj" to this object.
- Access : Public
- Return : void
- Parameters : CDiagramEntity* obj - The object to copy
- from.
- Usage : Copies basic information. from "obj" to this.
- "GetType" can be used to check for the correct
- object type in overridden versions.
- ============================================================*/
- {
- Clear();
- SetMarkerSize( obj->GetMarkerSize() );
- SetConstraints( obj->GetMinimumSize(), obj->GetMaximumSize() );
- Select( obj->IsSelected() );
- SetParent( obj->GetParent() );
- SetType( obj->GetType() );
- SetTitle( obj->GetTitle() );
- SetName( obj->GetName() );
- SetRect( obj->GetLeft(), obj->GetTop(), obj->GetRight(), obj->GetBottom() );
- }
- BOOL CDiagramEntity::FromString( const CString& str )
- /* ============================================================
- Function : CDiagramEntity::FromString
- Description : Sets the values for an object from "str".
- Access : Public
- Return : BOOL - "TRUE" if "str"
- represents an
- object of this
- type.
- Parameters : const CString& str - Possible text
- format
- representation.
- Usage : Can be called to fill an existing object
- with information from a string created with
- "GetString".
- ============================================================*/
- {
- BOOL result = FALSE;
- CString data( str );
- CString header = GetHeaderFromString( data );
- if( header == GetType() )
- if( GetDefaultFromString( data ) )
- result = TRUE;
- return result;
- }
- CString CDiagramEntity::GetHeaderFromString( CString& str )
- /* ============================================================
- Function : CDiagramEntity::GetHeaderFromString
- Description : Gets the header from "str".
- Access : Protected
- Return : CString - The type of "str".
- Parameters : CString& str - "CString" to get type from.
- Usage : Call as a part of loading the object. "str"
- will have the type removed after the call.
- ============================================================*/
- {
- CTokenizer main( str, _T( ":" ) );
- CString header;
- CString data;
- if( main.GetSize() == 2 )
- {
- main.GetAt( 0, header );
- main.GetAt( 1, data );
- header.TrimLeft();
- header.TrimRight();
- data.TrimLeft();
- data.TrimRight();
- str = data;
- }
- return header;
- }
- BOOL CDiagramEntity::GetDefaultFromString( CString& str )
- /* ============================================================
- Function : CDiagramEntity::GetDefaultFromString
- Description : Gets the default properties from "str"
- Access : Protected
- Return : BOOL - "TRUE" if the default
- properties could be loaded ok.
- Parameters : CString& str - "CString" to get the
- default properties from.
- Usage : Call as a part of loading the object from
- disk. The default object properties will
- be stripped from "str" and the object
- properties set from the data.
- ============================================================*/
- {
- BOOL result = FALSE;
- CString data( str );
- if( data[ data.GetLength() -1 ] == _TCHAR( ';' ) )
- data = data.Left( data.GetLength() - 1 ); // Strip the ';'
- CTokenizer tok( data );
- int size = tok.GetSize();
- if( size >= 7 )
- {
- double left;
- double top;
- double right;
- double bottom;
- CString title;
- CString name;
- int group;
- int count = 0;
- tok.GetAt( count++, left );
- tok.GetAt( count++, top );
- tok.GetAt( count++, right );
- tok.GetAt( count++, bottom );
- tok.GetAt( count++, title );
- tok.GetAt( count++, name );
- tok.GetAt( count++, group );
- SetRect( left, top, right, bottom );
- title.Replace( _T( "\colon" ), _T( ":" ) );
- title.Replace( _T( "\semicolon" ), _T( ";" ) );
- title.Replace( _T( "\comma" ), _T( "," ) );
- title.Replace( _T( "\newline" ), _T( "rn" ) );
- name.Replace( _T( "\colon" ), _T( ":" ) );
- name.Replace( _T( "\semicolon" ), _T( ";" ) );
- name.Replace( _T( "\comma" ), _T( "," ) );
- name.Replace( _T( "\newline" ), _T( "rn" ) );
- SetTitle( title );
- SetName( name );
- SetGroup( group );
- // Rebuild rest of string
- str = _T( "" );
- for( int t = count ; t < size ; t++ )
- {
- tok.GetAt( t, data );
- str += data;
- if( t < size - 1 )
- str += _T( "," );
- }
- result = TRUE;
- }
- return result;
- }
- BOOL CDiagramEntity::LoadFromString( CString& data )
- /* ============================================================
- Function : CDiagramEntity::LoadFromString
- Description : Loads the object from "data".
- Access : Public
- Return : BOOL - "TRUE" if "str" is a
- well-formed object prefix.
- Parameters : CString& data - String to load from
- Usage : Call to load the first part of an object
- from string.
- ============================================================*/
- {
- BOOL result = FALSE;
- CString header = GetHeaderFromString( data );
- if( header == GetType() )
- if( GetDefaultFromString( data ) )
- result = TRUE;
- return result;
- }
- CDiagramEntity* CDiagramEntity::CreateFromString( const CString& str )
- /* ============================================================
- Function : CDiagramEntity::CreateFromString
- Description : Static factory function that creates and
- returns an instance of this class if "str"
- is a valid representation.
- Access : Public
- Return : CDiagramEntity* - The object, or "NULL"
- if "str" is not a
- representation of
- this type.
- Parameters : const CString& str - The string to create
- from.
- Usage : Can be used as a factory for text file loads.
- Each object type should have its own
- version - the default one is a model
- implementation.
- ============================================================*/
- {
- CDiagramEntity* obj = new CDiagramEntity;
- if(!obj->FromString( str ) )
- {
- delete obj;
- obj = NULL;
- }
- return obj;
- }
- void CDiagramEntity::ReadStringFromArchive(CArchive& ar, CString& str)
- {
- int str_sz = 0;
- ar.Read(&str_sz,sizeof(int));
- if (str_sz<=0)
- return;
- ar.Read(str.GetBufferSetLength(str_sz), str_sz);
- }
- void CDiagramEntity::WriteStringToArchive(CArchive& ar, CString& str)
- {
- int str_sz = str.GetLength();
- ar.Write(&str_sz, sizeof(int));
- if (str_sz<=0)
- return;
- ar.Write(str, str_sz);
- }
- void CDiagramEntity::Serialize(CArchive& ar)
- {
- typedef struct
- {
- int a_f;
- int b_f;
- int c_f;
- int d_f;
- } OBJ_RESERVE_FIELDS;
- OBJ_RESERVE_FIELDS obj_reserve;
- memset(&obj_reserve,0,sizeof(OBJ_RESERVE_FIELDS));
- CRect rect = GetRect();
- // Saving and loading to/from a text file
- if (ar.IsStoring())
- {
- // 杨躔囗