2000-03-03 06:25:10 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: symbols.cpp
|
|
|
|
// Purpose: Implements the Studio symbol database
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 12/07/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Julian Smart
|
|
|
|
// Licence:
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
// #pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx.h".
|
2001-10-30 08:33:34 -05:00
|
|
|
#include "wx/wxprec.h"
|
2000-03-03 06:25:10 -05:00
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include <wx/wx.h>
|
|
|
|
#endif
|
|
|
|
|
2003-03-31 05:24:36 -05:00
|
|
|
#include <wx/deprecated/setup.h>
|
|
|
|
#include <wx/deprecated/wxexpr.h>
|
2000-03-03 06:25:10 -05:00
|
|
|
|
|
|
|
#include "studio.h"
|
|
|
|
#include "doc.h"
|
|
|
|
#include "shapes.h"
|
|
|
|
#include "view.h"
|
|
|
|
#include "symbols.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* csSymbol
|
|
|
|
* Represents information about a symbol.
|
|
|
|
*/
|
|
|
|
|
|
|
|
csSymbol::csSymbol(const wxString& name, wxShape* shape)
|
|
|
|
{
|
|
|
|
m_name = name;
|
|
|
|
m_shape = shape;
|
|
|
|
m_toolId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
csSymbol::~csSymbol()
|
|
|
|
{
|
|
|
|
delete m_shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A table of all possible shapes.
|
|
|
|
* We can use this to construct a palette, etc.
|
|
|
|
*/
|
|
|
|
csSymbolDatabase::csSymbolDatabase()
|
|
|
|
{
|
|
|
|
m_currentId = 800;
|
|
|
|
}
|
|
|
|
|
|
|
|
csSymbolDatabase::~csSymbolDatabase()
|
|
|
|
{
|
|
|
|
ClearSymbols();
|
|
|
|
}
|
|
|
|
|
|
|
|
void csSymbolDatabase::AddSymbol(csSymbol* symbol)
|
|
|
|
{
|
|
|
|
symbol->SetToolId(m_currentId);
|
|
|
|
m_symbols.Append(symbol);
|
|
|
|
|
|
|
|
m_currentId ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void csSymbolDatabase::ClearSymbols()
|
|
|
|
{
|
|
|
|
wxNode* node = m_symbols.First();
|
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
csSymbol* symbol = (csSymbol*) node->Data();
|
|
|
|
delete symbol;
|
|
|
|
|
|
|
|
node = node->Next();
|
|
|
|
}
|
|
|
|
m_symbols.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
csSymbol* csSymbolDatabase::FindSymbol(const wxString& name) const
|
|
|
|
{
|
|
|
|
wxNode* node = m_symbols.First();
|
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
csSymbol* symbol = (csSymbol*) node->Data();
|
|
|
|
if (symbol->GetName() == name)
|
|
|
|
return symbol;
|
|
|
|
|
|
|
|
node = node->Next();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
csSymbol* csSymbolDatabase::FindSymbol(int toolId) const
|
|
|
|
{
|
|
|
|
wxNode* node = m_symbols.First();
|
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
csSymbol* symbol = (csSymbol*) node->Data();
|
|
|
|
if (symbol->GetToolId() == toolId)
|
|
|
|
return symbol;
|
|
|
|
|
|
|
|
node = node->Next();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add symbols to database
|
|
|
|
void csApp::InitSymbols()
|
|
|
|
{
|
|
|
|
m_symbolDatabase = new csSymbolDatabase;
|
|
|
|
|
|
|
|
wxShape* shape = new csCircleShape();
|
|
|
|
shape->AssignNewIds();
|
|
|
|
shape->SetEventHandler(new csEvtHandler(shape, shape, wxString("")));
|
|
|
|
|
|
|
|
m_symbolDatabase->AddSymbol(new csSymbol("Circle", shape));
|
|
|
|
|
|
|
|
shape = new csCircleShadowShape();
|
|
|
|
shape->AssignNewIds();
|
|
|
|
shape->SetEventHandler(new csEvtHandler(shape, shape, wxString("")));
|
|
|
|
|
|
|
|
m_symbolDatabase->AddSymbol(new csSymbol("Circle shadow", shape));
|
|
|
|
|
|
|
|
shape = new csThinRectangleShape();
|
|
|
|
shape->AssignNewIds();
|
|
|
|
shape->SetEventHandler(new csEvtHandler(shape, shape, wxString("")));
|
|
|
|
|
|
|
|
m_symbolDatabase->AddSymbol(new csSymbol("Thin Rectangle", shape));
|
|
|
|
|
|
|
|
shape = new csWideRectangleShape();
|
|
|
|
shape->AssignNewIds();
|
|
|
|
shape->SetEventHandler(new csEvtHandler(shape, shape, wxString("")));
|
|
|
|
|
|
|
|
m_symbolDatabase->AddSymbol(new csSymbol("Wide Rectangle", shape));
|
|
|
|
|
|
|
|
shape = new csSemiCircleShape();
|
|
|
|
shape->AssignNewIds();
|
|
|
|
shape->SetEventHandler(new csEvtHandler(shape, shape, wxString("")));
|
|
|
|
|
|
|
|
m_symbolDatabase->AddSymbol(new csSymbol("SemiCircle", shape));
|
|
|
|
|
|
|
|
shape = new csTriangleShape();
|
|
|
|
shape->AssignNewIds();
|
|
|
|
shape->SetEventHandler(new csEvtHandler(shape, shape, wxString("")));
|
|
|
|
|
|
|
|
m_symbolDatabase->AddSymbol(new csSymbol("Triangle", shape));
|
|
|
|
|
|
|
|
shape = new csOctagonShape();
|
|
|
|
shape->AssignNewIds();
|
|
|
|
shape->SetEventHandler(new csEvtHandler(shape, shape, wxString("")));
|
|
|
|
|
|
|
|
m_symbolDatabase->AddSymbol(new csSymbol("Octagon", shape));
|
|
|
|
|
|
|
|
shape = new csGroupShape();
|
|
|
|
shape->AssignNewIds();
|
|
|
|
shape->SetEventHandler(new csEvtHandler(shape, shape, wxString("")));
|
|
|
|
|
|
|
|
m_symbolDatabase->AddSymbol(new csSymbol("Group", shape));
|
|
|
|
}
|
|
|
|
|
2000-03-20 08:41:16 -05:00
|
|
|
wxBitmap* csSymbolDatabase::CreateToolBitmap(csSymbol* symbol, const wxSize& toolSize)
|
2000-03-03 06:25:10 -05:00
|
|
|
{
|
|
|
|
symbol->GetShape()->Recompute();
|
|
|
|
|
2000-03-20 08:41:16 -05:00
|
|
|
wxBitmap *newBitmap = new wxBitmap(toolSize.x, toolSize.y);
|
2000-03-03 06:25:10 -05:00
|
|
|
|
2000-03-20 08:41:16 -05:00
|
|
|
// Test code
|
|
|
|
#if 0
|
2000-03-03 06:25:10 -05:00
|
|
|
wxMemoryDC memDC;
|
2000-03-20 08:41:16 -05:00
|
|
|
memDC.SelectObject(*newBitmap);
|
|
|
|
memDC.SetPen(* wxBLACK_PEN);
|
|
|
|
memDC.SetBrush(* wxWHITE_BRUSH);
|
2002-01-08 18:27:54 -05:00
|
|
|
memDC.SetBackground(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE), wxSOLID));
|
2000-03-20 08:41:16 -05:00
|
|
|
memDC.SetLogicalFunction(wxCOPY);
|
|
|
|
memDC.Clear();
|
|
|
|
|
|
|
|
memDC.DrawLine(0, 0, toolSize.x, toolSize.y);
|
|
|
|
memDC.DrawLine(0, toolSize.y, toolSize.x, 0);
|
|
|
|
|
|
|
|
memDC.SelectObject(wxNullBitmap);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
wxMemoryDC memDC;
|
|
|
|
|
2000-03-03 06:25:10 -05:00
|
|
|
double height, width, maxSize;
|
|
|
|
symbol->GetShape()->GetBoundingBoxMax(&width, &height);
|
|
|
|
|
|
|
|
if (height > width)
|
|
|
|
maxSize = height;
|
|
|
|
else
|
|
|
|
maxSize = width;
|
|
|
|
|
|
|
|
double borderMargin = 4.0;
|
2000-03-20 08:41:16 -05:00
|
|
|
double scaleFactor = (double)(toolSize.x / (maxSize + 2*borderMargin));
|
|
|
|
double centreX = (double)((toolSize.x/scaleFactor)/2.0)-1;
|
2000-03-03 06:25:10 -05:00
|
|
|
double centreY = centreX;
|
|
|
|
|
|
|
|
memDC.SelectObject(*newBitmap);
|
2000-03-20 08:41:16 -05:00
|
|
|
|
2000-03-03 06:25:10 -05:00
|
|
|
memDC.SetUserScale(scaleFactor, scaleFactor);
|
|
|
|
|
2002-01-08 18:27:54 -05:00
|
|
|
memDC.SetBackground(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE), wxSOLID));
|
2000-03-03 06:25:10 -05:00
|
|
|
memDC.Clear();
|
2000-03-20 08:41:16 -05:00
|
|
|
|
2000-03-03 06:25:10 -05:00
|
|
|
symbol->GetShape()->Show(TRUE);
|
|
|
|
symbol->GetShape()->Move(memDC, centreX, centreY);
|
2000-03-20 08:41:16 -05:00
|
|
|
|
2000-03-03 06:25:10 -05:00
|
|
|
memDC.SelectObject(wxNullBitmap);
|
2000-03-20 08:41:16 -05:00
|
|
|
#endif
|
2000-03-03 06:25:10 -05:00
|
|
|
|
|
|
|
return newBitmap;
|
|
|
|
}
|
|
|
|
|