📄 umltemplatepropertydialog.cpp
字号:
Parameters : none
Usage : Call to (re)fill the listboxes.
============================================================*/
{
ClearListboxes();
CUMLEntityClassTemplate* uml = static_cast< CUMLEntityClassTemplate* >( GetEntity() );
int max = uml->GetAttributes();
for( int t = 0 ; t < max ; t++ )
{
CAttribute* obj = uml->GetAttribute( t );
CString output = obj->ToString( FALSE );
int index = m_attribute.AddString( output );
m_attribute.SetItemData( index, ( DWORD ) obj->Clone() );
}
max = uml->GetOperations();
for( t = 0 ; t < max ; t++ )
{
COperation* obj = uml->GetOperation( t );
CString output = obj->ToString( FALSE, FALSE );
int index = m_operation.AddString( output );
m_operation.SetItemData( index, ( DWORD ) obj->Clone() );
}
}
void CUMLTemplatePropertyDialog::ClearListboxes()
/* ============================================================
Function : CUMLTemplatePropertyDialog::ClearListboxes
Description : Clears the attribute and operation
listboxes.
Access : Private
Return : void
Parameters : none
Usage : Call to clear the listboxes.
============================================================*/
{
int max = m_attribute.GetCount();
for( int t = 0 ; t < max ; t++ )
{
CAttribute* obj = reinterpret_cast< CAttribute* >( m_attribute.GetItemData( t ) );
delete obj;
}
max = m_operation.GetCount();
for( t = 0 ; t < max ; t++ )
{
COperation* obj = reinterpret_cast< COperation* >( m_operation.GetItemData( t ) );
delete obj;
}
m_attribute.ResetContent();
m_operation.ResetContent();
}
void CUMLTemplatePropertyDialog::RefreshListboxes()
/* ============================================================
Function : CUMLTemplatePropertyDialog::RefreshListboxes
Description : Refills the attribute and operation
listboxes from the internal attribute-
and operation containers.
Access : Private
Return : void
Parameters : none
Usage : Call to refill the listboxes with internal
data.
============================================================*/
{
int max = m_attribute.GetCount();
for( int t = 0 ; t < max ; t++ )
{
CAttribute* obj = reinterpret_cast< CAttribute* >( m_attribute.GetItemData( t ) );
CString output = obj->ToString( FALSE );
m_attribute.DeleteString( t );
int index = m_attribute.InsertString( t, output );
m_attribute.SetItemData( index, ( DWORD ) obj );
}
max = m_operation.GetCount();
for( t = 0 ; t < max ; t++ )
{
COperation* obj = reinterpret_cast< COperation* >( m_operation.GetItemData( t ) );
CString output = obj->ToString( FALSE, FALSE );
m_operation.DeleteString( t );
int index = m_operation.InsertString( t, output );
m_operation.SetItemData( index, ( DWORD ) obj );
}
}
LRESULT CUMLTemplatePropertyDialog::OnListboxDblClick( WPARAM id, LPARAM )
/* ============================================================
Function : CUMLTemplatePropertyDialog::OnListboxDblClick
Description : Mapped to the registered message
"rwm_EXLISTBOX_DBLCLICK".
Access : Protected
Return : LRESULT - Always 0
Parameters : WPARAM id - ID of "CExListBox" sending this.
LPARAM - Not used
Usage : Sent from "CExListBox" when the user
double-clicks a line. Can come from either
the attribute- or operation listbox.
============================================================*/
{
if( static_cast< int >( id ) == m_attribute.GetDlgCtrlID() )
EditAttribute();
if( static_cast< int >( id ) == m_operation.GetDlgCtrlID() )
EditOperation();
return 0;
}
LRESULT CUMLTemplatePropertyDialog::OnListboxDelete( WPARAM id, LPARAM )
/* ============================================================
Function : CUMLTemplatePropertyDialog::OnListboxDelete
Description : Mapped to the registered message
"rwm_EXLISTBOX_DELETE"
Access : Protected
Return : LRESULT - Always 0
Parameters : WPARAM id - ID of "CExListBox" sending this.
LPARAM - Not used
Usage : Sent from "CExListBox" when the user
presses the DEL-key. Can come from either
the attribute- or operation listbox.
============================================================*/
{
if( static_cast< int >( id ) == m_attribute.GetDlgCtrlID() )
DeleteAttribute();
if( static_cast< int >( id ) == m_operation.GetDlgCtrlID() )
DeleteOperation();
return 0;
}
void CUMLTemplatePropertyDialog::OnButtonPropertyList()
/* ============================================================
Function : CUMLTemplatePropertyDialog::OnButtonPropertyList
Description : Handler for the dialog button Property List
Access : Protected
Return : void
Parameters : none
Usage : Called from MFC.
============================================================*/
{
UpdateData();
CPropertyListEditorDialog dlg;
dlg.SetProperties( m_properties );
if( dlg.DoModal() == IDOK )
{
m_properties.Copy( *( dlg.GetProperties() ) );
m_propertylist = m_properties.GetString( STRING_FORMAT_UML );
UpdateData( FALSE );
}
}
void CUMLTemplatePropertyDialog::OnButtonAutoGenerate()
/* ============================================================
Function : CUMLTemplatePropertyDialog::OnButtonAutoGenerate
Description : Handler for the dialog button Generate
getters/setters
Access : Protected
Return : void
Parameters : none
Usage : Called from MFC.
============================================================*/
{
int index = m_attribute.GetCurSel();
if( index != LB_ERR )
{
CAttribute* attr = reinterpret_cast< CAttribute* >( m_attribute.GetItemData( index ) );
if( attr )
{
if( AfxMessageBox( IDS_UML_CREATEGETTERS_SETTERS, MB_YESNO ) == IDYES )
{
CString name = attr->name;
if( name.GetLength() > 2 && name.Left( 2 ) == _T( "m_" ) )
name = name.Right( name.GetLength() - 2 );
name = _TCHAR( _totupper( name[ 0 ] ) ) + name.Right( name.GetLength() - 1 );
CString getName( _T( "Get" ) + name );
CString setName( _T( "Set" ) + name );
BOOL getFound = FALSE;
BOOL setFound = FALSE;
CreateAttributes();
CreateOperations();
CUMLEntityClassTemplate* uml = static_cast< CUMLEntityClassTemplate* >( GetEntity() );
int size = uml->GetOperations();
for( int i = 0 ; i < size ; i++ )
{
COperation* op = uml->GetOperation( i );
if( op->getter && op->getsetvariable == attr->name )
getFound = TRUE;
if( op->setter && op->getsetvariable == attr->name )
setFound = TRUE;
}
if( !getFound || !setFound )
{
CGetterSetterDialog dlg;
if( !getFound )
dlg.m_getter = getName;
else
dlg.m_noget = TRUE;
if( !setFound )
dlg.m_setter = setName;
else
dlg.m_noset = TRUE;
if( dlg.DoModal() == IDOK )
{
BOOL added = FALSE;
if( !dlg.m_noget && dlg.m_getter.GetLength() )
{
COperation* op = new COperation;
op->name = dlg.m_getter;
op->type = attr->type;
op->access = ACCESS_TYPE_PUBLIC;
op->properties.Add( _T( "query" ) );
op->getter = TRUE;
op->getsetvariable = attr->name;
uml->AddOperation( op );
added = TRUE;
}
if( !dlg.m_noset && dlg.m_setter.GetLength() )
{
COperation* op = new COperation;
op->name = dlg.m_setter;
op->access = ACCESS_TYPE_PUBLIC;
CParameter* parameter = new CParameter;
parameter->name = _T( "value" );
parameter->type = attr->type;
op->parameters.Add( parameter );
op->setter = TRUE;
op->getsetvariable = attr->name;
uml->AddOperation( op );
added = TRUE;
}
if( added )
FillListboxes();
}
}
else
AfxMessageBox( IDS_UML_GETSET_DEFINED );
}
}
}
else
AfxMessageBox( IDS_UML_MUST_SELECT_AN_ATTRIBUTE );
m_attribute.SetCurSel( index );
m_attribute.SetFocus();
}
void CUMLTemplatePropertyDialog::CreateAttributes()
/* ============================================================
Function : CUMLTemplatePropertyDialog::CreateAttributes
Description : Creates the edited attributes in the
attached "CUMLEntityClassTemplate" object.
Access : Private
Return : void
Parameters : none
Usage : Call to update the attached object.
============================================================*/
{
CUMLEntityClassTemplate* uml = static_cast< CUMLEntityClassTemplate* >( GetEntity() );
// Wipe current attributes from the class.
uml->ClearAttributes();
// Re-add from listbox.
int max = m_attribute.GetCount();
for( int t = 0 ; t < max ; t++ )
{
CAttribute* obj = reinterpret_cast< CAttribute* >( m_attribute.GetItemData( t ) );
if( obj )
uml->AddAttribute( obj->Clone() );
}
}
void CUMLTemplatePropertyDialog::CreateOperations()
/* ============================================================
Function : CUMLTemplatePropertyDialog::CreateOperations
Description : Creates the edited operations in the
attached "CUMLEntityClassTemplate" object.
Access : Private
Return : void
Parameters : none
Usage : Call to update the attached object.
============================================================*/
{
CUMLEntityClassTemplate* uml = static_cast< CUMLEntityClassTemplate* >( GetEntity() );
// Wipe current operations from the class.
uml->ClearOperations();
int max = m_operation.GetCount();
for( int t = 0 ; t < max ; t++ )
{
COperation* obj = reinterpret_cast< COperation* >( m_operation.GetItemData( t ) );
if( obj )
uml->AddOperation( obj->Clone() );
}
}
void CUMLTemplatePropertyDialog::OnButtonVisibility()
/* ============================================================
Function : CUMLTemplatePropertyDialog::OnButtonVisibility
Description : Handler for the dialog button Visibility
Access : Protected
Return : void
Parameters : none
Usage : Called from MFC.
============================================================*/
{
CUMLEntityClassTemplate* uml = static_cast< CUMLEntityClassTemplate* >( GetEntity() );
CClassDisplayPropertyDialog dlg;
int displayOptions = uml->GetDisplayOptions();
dlg.m_noattributenames = ( displayOptions & DISPLAY_NO_OPERATION_ATTRIBUTE_NAMES ) != 0;
dlg.m_noattributes = ( displayOptions & DISPLAY_NO_ATTRIBUTES ) != 0;
dlg.m_nomarkers = ( displayOptions & DISPLAY_NO_MARKERS ) != 0;
dlg.m_nooperations = ( displayOptions & DISPLAY_NO_OPERATIONS ) != 0;
dlg.m_onlypublic = ( displayOptions & DISPLAY_ONLY_PUBLIC ) != 0;
if( dlg.DoModal() )
{
displayOptions = 0;
if( dlg.m_noattributenames )
displayOptions |= DISPLAY_NO_OPERATION_ATTRIBUTE_NAMES;
if( dlg.m_noattributes )
displayOptions |= DISPLAY_NO_ATTRIBUTES;
if( dlg.m_nomarkers )
displayOptions |= DISPLAY_NO_MARKERS;
if( dlg.m_nooperations )
displayOptions |= DISPLAY_NO_OPERATIONS;
if( dlg.m_onlypublic )
displayOptions |= DISPLAY_ONLY_PUBLIC;
uml->SetDisplayOptions( displayOptions );
}
}
void CUMLTemplatePropertyDialog::OnButtonAutoGenerate2()
/* ============================================================
Function : CUMLTemplatePropertyDialog::OnButtonAutoGenerate2
Description : Handler for the dialog button Generate
ctor/dtor
Access : Protected
Return : void
Parameters : none
Usage : Called from MFC.
============================================================*/
{
if( AfxMessageBox( IDS_UML_CREATECTOR_DTOR, MB_YESNO ) == IDYES )
{
UpdateData();
CreateAttributes();
CreateOperations();
CUMLEntityClassTemplate* uml = static_cast< CUMLEntityClassTemplate* >( GetEntity() );
COperation* op = new COperation;
op->name = m_name;
op->access = ACCESS_TYPE_PUBLIC;
uml->AddOperation( op );
op = new COperation;
op->name = _T( "~" ) + m_name;
op->access = ACCESS_TYPE_PUBLIC;
op->maintype = ENTITY_TYPE_VIRTUAL;
op->properties.Add( _T( "virtual" ) );
uml->AddOperation( op );
FillListboxes();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -