2000-03-03 06:25:10 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: doc.cpp
|
|
|
|
// Purpose: Implements document functionality in OGLEdit
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 12/07/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Julian Smart
|
2004-06-09 12:42:34 -04:00
|
|
|
// Licence: wxWindows licence
|
2000-03-03 06:25:10 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
#if !wxUSE_DOC_VIEW_ARCHITECTURE
|
|
|
|
#error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in wx_setup.h!
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ogledit.h"
|
|
|
|
#include "doc.h"
|
|
|
|
#include "view.h"
|
|
|
|
|
|
|
|
#if wxUSE_STD_IOSTREAM
|
2001-06-06 12:51:53 -04:00
|
|
|
#include <ioswrap.h>
|
2000-03-03 06:25:10 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(DiagramDocument, wxDocument)
|
|
|
|
|
|
|
|
DiagramDocument::DiagramDocument(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DiagramDocument::~DiagramDocument(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DiagramDocument::OnCloseDocument(void)
|
|
|
|
{
|
|
|
|
diagram.DeleteAllShapes();
|
2004-06-09 12:42:34 -04:00
|
|
|
return true;
|
2000-03-03 06:25:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#if wxUSE_STD_IOSTREAM
|
2001-06-06 12:51:53 -04:00
|
|
|
wxSTD ostream& DiagramDocument::SaveObject(wxSTD ostream& stream)
|
2000-03-03 06:25:10 -05:00
|
|
|
{
|
|
|
|
wxDocument::SaveObject(stream);
|
|
|
|
|
|
|
|
char buf[400];
|
|
|
|
(void) wxGetTempFileName("diag", buf);
|
|
|
|
|
|
|
|
diagram.SaveFile(buf);
|
|
|
|
wxTransferFileToStream(buf, stream);
|
|
|
|
|
|
|
|
wxRemoveFile(buf);
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2001-06-06 12:51:53 -04:00
|
|
|
wxSTD istream& DiagramDocument::LoadObject(wxSTD istream& stream)
|
2000-03-03 06:25:10 -05:00
|
|
|
{
|
|
|
|
wxDocument::LoadObject(stream);
|
|
|
|
|
|
|
|
char buf[400];
|
|
|
|
(void) wxGetTempFileName("diag", buf);
|
|
|
|
|
|
|
|
wxTransferStreamToFile(stream, buf);
|
|
|
|
|
|
|
|
diagram.DeleteAllShapes();
|
|
|
|
diagram.LoadFile(buf);
|
|
|
|
wxRemoveFile(buf);
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
wxOutputStream& DiagramDocument::SaveObject(wxOutputStream& stream)
|
|
|
|
{
|
2003-07-22 12:15:49 -04:00
|
|
|
#if wxUSE_PROLOGIO
|
|
|
|
|
2000-03-03 06:25:10 -05:00
|
|
|
wxDocument::SaveObject(stream);
|
2003-08-21 05:05:56 -04:00
|
|
|
wxChar buf[400];
|
|
|
|
(void) wxGetTempFileName(_T("diag"), buf);
|
2000-03-03 06:25:10 -05:00
|
|
|
|
|
|
|
diagram.SaveFile(buf);
|
|
|
|
|
|
|
|
wxTransferFileToStream(buf, stream);
|
|
|
|
|
|
|
|
wxRemoveFile(buf);
|
2003-07-22 12:15:49 -04:00
|
|
|
|
|
|
|
#endif
|
2000-03-03 06:25:10 -05:00
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxInputStream& DiagramDocument::LoadObject(wxInputStream& stream)
|
|
|
|
{
|
2003-07-22 12:15:49 -04:00
|
|
|
#if wxUSE_PROLOGIO
|
2000-03-03 06:25:10 -05:00
|
|
|
wxDocument::LoadObject(stream);
|
|
|
|
|
2003-08-21 05:05:56 -04:00
|
|
|
wxChar buf[400];
|
|
|
|
(void) wxGetTempFileName(_T("diag"), buf);
|
2000-03-03 06:25:10 -05:00
|
|
|
|
|
|
|
wxTransferStreamToFile(stream, buf);
|
|
|
|
|
|
|
|
diagram.DeleteAllShapes();
|
|
|
|
diagram.LoadFile(buf);
|
|
|
|
wxRemoveFile(buf);
|
2003-07-22 12:15:49 -04:00
|
|
|
#endif
|
2000-03-03 06:25:10 -05:00
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of drawing command
|
|
|
|
*/
|
|
|
|
|
2003-08-21 05:05:56 -04:00
|
|
|
DiagramCommand::DiagramCommand(const wxString& name, int command, DiagramDocument *ddoc, wxClassInfo *info, double xx, double yy,
|
2000-03-03 06:25:10 -05:00
|
|
|
bool sel, wxShape *theShape, wxShape *fs, wxShape *ts):
|
2004-06-09 12:42:34 -04:00
|
|
|
wxCommand(true, name)
|
2000-03-03 06:25:10 -05:00
|
|
|
{
|
|
|
|
doc = ddoc;
|
|
|
|
cmd = command;
|
|
|
|
shape = theShape;
|
|
|
|
fromShape = fs;
|
|
|
|
toShape = ts;
|
|
|
|
shapeInfo = info;
|
|
|
|
shapeBrush = NULL;
|
|
|
|
shapePen = NULL;
|
|
|
|
x = xx;
|
|
|
|
y = yy;
|
|
|
|
selected = sel;
|
2004-06-09 12:42:34 -04:00
|
|
|
deleteShape = false;
|
2000-03-03 06:25:10 -05:00
|
|
|
}
|
|
|
|
|
2003-08-21 05:05:56 -04:00
|
|
|
DiagramCommand::DiagramCommand(const wxString& name, int command, DiagramDocument *ddoc, wxBrush *backgroundColour, wxShape *theShape):
|
2004-06-09 12:42:34 -04:00
|
|
|
wxCommand(true, name)
|
2000-03-03 06:25:10 -05:00
|
|
|
{
|
|
|
|
doc = ddoc;
|
|
|
|
cmd = command;
|
|
|
|
shape = theShape;
|
|
|
|
fromShape = NULL;
|
|
|
|
toShape = NULL;
|
|
|
|
shapeInfo = NULL;
|
|
|
|
x = 0.0;
|
|
|
|
y = 0.0;
|
2004-06-09 12:42:34 -04:00
|
|
|
selected = false;
|
|
|
|
deleteShape = false;
|
2000-03-03 06:25:10 -05:00
|
|
|
shapeBrush = backgroundColour;
|
|
|
|
shapePen = NULL;
|
|
|
|
}
|
|
|
|
|
2003-08-21 05:05:56 -04:00
|
|
|
DiagramCommand::DiagramCommand(const wxString& name, int command, DiagramDocument *ddoc, const wxString& lab, wxShape *theShape):
|
2004-06-09 12:42:34 -04:00
|
|
|
wxCommand(true, name)
|
2000-03-03 06:25:10 -05:00
|
|
|
{
|
|
|
|
doc = ddoc;
|
|
|
|
cmd = command;
|
|
|
|
shape = theShape;
|
|
|
|
fromShape = NULL;
|
|
|
|
toShape = NULL;
|
|
|
|
shapeInfo = NULL;
|
|
|
|
x = 0.0;
|
|
|
|
y = 0.0;
|
2004-06-09 12:42:34 -04:00
|
|
|
selected = false;
|
|
|
|
deleteShape = false;
|
2000-03-03 06:25:10 -05:00
|
|
|
shapeBrush = NULL;
|
|
|
|
shapePen = NULL;
|
|
|
|
shapeLabel = lab;
|
|
|
|
}
|
|
|
|
|
|
|
|
DiagramCommand::~DiagramCommand(void)
|
|
|
|
{
|
|
|
|
if (shape && deleteShape)
|
|
|
|
{
|
|
|
|
shape->SetCanvas(NULL);
|
|
|
|
delete shape;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DiagramCommand::Do(void)
|
|
|
|
{
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case OGLEDIT_CUT:
|
|
|
|
{
|
|
|
|
if (shape)
|
|
|
|
{
|
2004-06-09 12:42:34 -04:00
|
|
|
deleteShape = true;
|
2000-03-03 06:25:10 -05:00
|
|
|
|
2004-06-09 12:42:34 -04:00
|
|
|
shape->Select(false);
|
2000-03-03 06:25:10 -05:00
|
|
|
|
|
|
|
// Generate commands to explicitly remove each connected line.
|
|
|
|
RemoveLines(shape);
|
|
|
|
|
|
|
|
doc->GetDiagram()->RemoveShape(shape);
|
|
|
|
if (shape->IsKindOf(CLASSINFO(wxLineShape)))
|
|
|
|
{
|
|
|
|
wxLineShape *lineShape = (wxLineShape *)shape;
|
|
|
|
fromShape = lineShape->GetFrom();
|
|
|
|
toShape = lineShape->GetTo();
|
|
|
|
}
|
|
|
|
shape->Unlink();
|
|
|
|
|
2004-06-09 12:42:34 -04:00
|
|
|
doc->Modify(true);
|
2000-03-03 06:25:10 -05:00
|
|
|
doc->UpdateAllViews();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OGLEDIT_ADD_SHAPE:
|
|
|
|
{
|
2003-11-09 16:40:34 -05:00
|
|
|
wxShape *theShape;
|
2000-03-03 06:25:10 -05:00
|
|
|
if (shape)
|
|
|
|
theShape = shape; // Saved from undoing the shape
|
|
|
|
else
|
|
|
|
{
|
|
|
|
theShape = (wxShape *)shapeInfo->CreateObject();
|
|
|
|
theShape->AssignNewIds();
|
2003-08-21 05:05:56 -04:00
|
|
|
theShape->SetEventHandler(new MyEvtHandler(theShape, theShape, wxEmptyString));
|
2004-06-09 12:42:34 -04:00
|
|
|
theShape->SetCentreResize(false);
|
2000-03-03 06:25:10 -05:00
|
|
|
theShape->SetPen(wxBLACK_PEN);
|
|
|
|
theShape->SetBrush(wxCYAN_BRUSH);
|
|
|
|
|
|
|
|
theShape->SetSize(60, 60);
|
|
|
|
}
|
|
|
|
doc->GetDiagram()->AddShape(theShape);
|
2004-06-09 12:42:34 -04:00
|
|
|
theShape->Show(true);
|
2000-03-03 06:25:10 -05:00
|
|
|
|
|
|
|
wxClientDC dc(theShape->GetCanvas());
|
|
|
|
theShape->GetCanvas()->PrepareDC(dc);
|
|
|
|
|
|
|
|
theShape->Move(dc, x, y);
|
|
|
|
|
|
|
|
shape = theShape;
|
2004-06-09 12:42:34 -04:00
|
|
|
deleteShape = false;
|
2000-03-03 06:25:10 -05:00
|
|
|
|
2004-06-09 12:42:34 -04:00
|
|
|
doc->Modify(true);
|
2000-03-03 06:25:10 -05:00
|
|
|
doc->UpdateAllViews();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OGLEDIT_ADD_LINE:
|
|
|
|
{
|
2003-11-09 16:40:34 -05:00
|
|
|
wxShape *theShape;
|
2000-03-03 06:25:10 -05:00
|
|
|
if (shape)
|
|
|
|
theShape = shape; // Saved from undoing the line
|
|
|
|
else
|
|
|
|
{
|
|
|
|
theShape = (wxShape *)shapeInfo->CreateObject();
|
|
|
|
theShape->AssignNewIds();
|
2003-08-21 05:05:56 -04:00
|
|
|
theShape->SetEventHandler(new MyEvtHandler(theShape, theShape, wxEmptyString));
|
2000-03-03 06:25:10 -05:00
|
|
|
theShape->SetPen(wxBLACK_PEN);
|
|
|
|
theShape->SetBrush(wxRED_BRUSH);
|
|
|
|
|
|
|
|
wxLineShape *lineShape = (wxLineShape *)theShape;
|
|
|
|
|
|
|
|
// Yes, you can have more than 2 control points, in which case
|
|
|
|
// it becomes a multi-segment line.
|
|
|
|
lineShape->MakeLineControlPoints(2);
|
2003-08-21 05:05:56 -04:00
|
|
|
lineShape->AddArrow(ARROW_ARROW, ARROW_POSITION_END, 10.0, 0.0, _T("Normal arrowhead"));
|
2000-03-03 06:25:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
doc->GetDiagram()->AddShape(theShape);
|
|
|
|
|
|
|
|
fromShape->AddLine((wxLineShape *)theShape, toShape);
|
|
|
|
|
2004-06-09 12:42:34 -04:00
|
|
|
theShape->Show(true);
|
2000-03-03 06:25:10 -05:00
|
|
|
|
|
|
|
wxClientDC dc(theShape->GetCanvas());
|
|
|
|
theShape->GetCanvas()->PrepareDC(dc);
|
|
|
|
|
|
|
|
// It won't get drawn properly unless you move both
|
|
|
|
// connected images
|
|
|
|
fromShape->Move(dc, fromShape->GetX(), fromShape->GetY());
|
|
|
|
toShape->Move(dc, toShape->GetX(), toShape->GetY());
|
|
|
|
|
|
|
|
shape = theShape;
|
2004-06-09 12:42:34 -04:00
|
|
|
deleteShape = false;
|
2000-03-03 06:25:10 -05:00
|
|
|
|
2004-06-09 12:42:34 -04:00
|
|
|
doc->Modify(true);
|
2000-03-03 06:25:10 -05:00
|
|
|
doc->UpdateAllViews();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OGLEDIT_CHANGE_BACKGROUND_COLOUR:
|
|
|
|
{
|
|
|
|
if (shape)
|
|
|
|
{
|
|
|
|
wxClientDC dc(shape->GetCanvas());
|
|
|
|
shape->GetCanvas()->PrepareDC(dc);
|
|
|
|
|
|
|
|
wxBrush *oldBrush = shape->GetBrush();
|
|
|
|
shape->SetBrush(shapeBrush);
|
|
|
|
shapeBrush = oldBrush;
|
|
|
|
shape->Draw(dc);
|
|
|
|
|
2004-06-09 12:42:34 -04:00
|
|
|
doc->Modify(true);
|
2000-03-03 06:25:10 -05:00
|
|
|
doc->UpdateAllViews();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OGLEDIT_EDIT_LABEL:
|
|
|
|
{
|
|
|
|
if (shape)
|
|
|
|
{
|
|
|
|
MyEvtHandler *myHandler = (MyEvtHandler *)shape->GetEventHandler();
|
|
|
|
wxString oldLabel(myHandler->label);
|
|
|
|
myHandler->label = shapeLabel;
|
|
|
|
shapeLabel = oldLabel;
|
|
|
|
|
|
|
|
wxClientDC dc(shape->GetCanvas());
|
|
|
|
shape->GetCanvas()->PrepareDC(dc);
|
|
|
|
|
2003-08-21 05:05:56 -04:00
|
|
|
shape->FormatText(dc, /* (char*) (const char*) */ myHandler->label);
|
2000-03-03 06:25:10 -05:00
|
|
|
shape->Draw(dc);
|
|
|
|
|
2004-06-09 12:42:34 -04:00
|
|
|
doc->Modify(true);
|
2000-03-03 06:25:10 -05:00
|
|
|
doc->UpdateAllViews();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-06-09 12:42:34 -04:00
|
|
|
return true;
|
2000-03-03 06:25:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DiagramCommand::Undo(void)
|
|
|
|
{
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case OGLEDIT_CUT:
|
|
|
|
{
|
|
|
|
if (shape)
|
|
|
|
{
|
|
|
|
doc->GetDiagram()->AddShape(shape);
|
2004-06-09 12:42:34 -04:00
|
|
|
shape->Show(true);
|
2000-03-03 06:25:10 -05:00
|
|
|
|
|
|
|
if (shape->IsKindOf(CLASSINFO(wxLineShape)))
|
|
|
|
{
|
|
|
|
wxLineShape *lineShape = (wxLineShape *)shape;
|
|
|
|
|
|
|
|
fromShape->AddLine(lineShape, toShape);
|
|
|
|
}
|
|
|
|
if (selected)
|
2004-06-09 12:42:34 -04:00
|
|
|
shape->Select(true);
|
2000-03-03 06:25:10 -05:00
|
|
|
|
2004-06-09 12:42:34 -04:00
|
|
|
deleteShape = false;
|
2000-03-03 06:25:10 -05:00
|
|
|
}
|
2004-06-09 12:42:34 -04:00
|
|
|
doc->Modify(true);
|
2000-03-03 06:25:10 -05:00
|
|
|
doc->UpdateAllViews();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OGLEDIT_ADD_SHAPE:
|
|
|
|
case OGLEDIT_ADD_LINE:
|
|
|
|
{
|
|
|
|
if (shape)
|
|
|
|
{
|
|
|
|
wxClientDC dc(shape->GetCanvas());
|
|
|
|
shape->GetCanvas()->PrepareDC(dc);
|
|
|
|
|
2004-06-09 12:42:34 -04:00
|
|
|
shape->Select(false, &dc);
|
2000-03-03 06:25:10 -05:00
|
|
|
doc->GetDiagram()->RemoveShape(shape);
|
|
|
|
shape->Unlink();
|
2004-06-09 12:42:34 -04:00
|
|
|
deleteShape = true;
|
2000-03-03 06:25:10 -05:00
|
|
|
}
|
2004-06-09 12:42:34 -04:00
|
|
|
doc->Modify(true);
|
2000-03-03 06:25:10 -05:00
|
|
|
doc->UpdateAllViews();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OGLEDIT_CHANGE_BACKGROUND_COLOUR:
|
|
|
|
{
|
|
|
|
if (shape)
|
|
|
|
{
|
|
|
|
wxClientDC dc(shape->GetCanvas());
|
|
|
|
shape->GetCanvas()->PrepareDC(dc);
|
|
|
|
|
|
|
|
wxBrush *oldBrush = shape->GetBrush();
|
|
|
|
shape->SetBrush(shapeBrush);
|
|
|
|
shapeBrush = oldBrush;
|
|
|
|
shape->Draw(dc);
|
|
|
|
|
2004-06-09 12:42:34 -04:00
|
|
|
doc->Modify(true);
|
2000-03-03 06:25:10 -05:00
|
|
|
doc->UpdateAllViews();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OGLEDIT_EDIT_LABEL:
|
|
|
|
{
|
|
|
|
if (shape)
|
|
|
|
{
|
|
|
|
MyEvtHandler *myHandler = (MyEvtHandler *)shape->GetEventHandler();
|
|
|
|
wxString oldLabel(myHandler->label);
|
|
|
|
myHandler->label = shapeLabel;
|
|
|
|
shapeLabel = oldLabel;
|
|
|
|
|
|
|
|
wxClientDC dc(shape->GetCanvas());
|
|
|
|
shape->GetCanvas()->PrepareDC(dc);
|
|
|
|
|
2003-08-21 05:05:56 -04:00
|
|
|
shape->FormatText(dc, /* (char*) (const char*) */ myHandler->label);
|
2000-03-03 06:25:10 -05:00
|
|
|
shape->Draw(dc);
|
|
|
|
|
2004-06-09 12:42:34 -04:00
|
|
|
doc->Modify(true);
|
2000-03-03 06:25:10 -05:00
|
|
|
doc->UpdateAllViews();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-06-09 12:42:34 -04:00
|
|
|
return true;
|
2000-03-03 06:25:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove each individual line connected to a shape by sending a command.
|
|
|
|
void DiagramCommand::RemoveLines(wxShape *shape)
|
|
|
|
{
|
2003-11-09 16:40:34 -05:00
|
|
|
wxNode *node = shape->GetLines().GetFirst();
|
2000-03-03 06:25:10 -05:00
|
|
|
while (node)
|
|
|
|
{
|
2003-11-09 16:40:34 -05:00
|
|
|
wxLineShape *line = (wxLineShape *)node->GetData();
|
2003-08-21 05:05:56 -04:00
|
|
|
doc->GetCommandProcessor()->Submit(new DiagramCommand(_T("Cut"), OGLEDIT_CUT, doc, NULL, 0.0, 0.0, line->Selected(), line));
|
2000-03-03 06:25:10 -05:00
|
|
|
|
2003-11-09 16:40:34 -05:00
|
|
|
node = shape->GetLines().GetFirst();
|
2000-03-03 06:25:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MyEvtHandler: an event handler class for all shapes
|
|
|
|
*/
|
|
|
|
|
2003-08-21 05:05:56 -04:00
|
|
|
void MyEvtHandler::OnLeftClick(double WXUNUSED(x), double WXUNUSED(y), int keys, int WXUNUSED(attachment))
|
2000-03-03 06:25:10 -05:00
|
|
|
{
|
|
|
|
wxClientDC dc(GetShape()->GetCanvas());
|
|
|
|
GetShape()->GetCanvas()->PrepareDC(dc);
|
|
|
|
|
|
|
|
if (keys == 0)
|
|
|
|
{
|
|
|
|
// Selection is a concept the library knows about
|
|
|
|
if (GetShape()->Selected())
|
|
|
|
{
|
2004-06-09 12:42:34 -04:00
|
|
|
GetShape()->Select(false, &dc);
|
2000-03-03 06:25:10 -05:00
|
|
|
GetShape()->GetCanvas()->Redraw(dc); // Redraw because bits of objects will be are missing
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Ensure no other shape is selected, to simplify Undo/Redo code
|
2004-06-09 12:42:34 -04:00
|
|
|
bool redraw = false;
|
2003-11-09 16:40:34 -05:00
|
|
|
wxNode *node = GetShape()->GetCanvas()->GetDiagram()->GetShapeList()->GetFirst();
|
2000-03-03 06:25:10 -05:00
|
|
|
while (node)
|
|
|
|
{
|
2003-11-09 16:40:34 -05:00
|
|
|
wxShape *eachShape = (wxShape *)node->GetData();
|
2000-03-03 06:25:10 -05:00
|
|
|
if (eachShape->GetParent() == NULL)
|
|
|
|
{
|
|
|
|
if (eachShape->Selected())
|
|
|
|
{
|
2004-06-09 12:42:34 -04:00
|
|
|
eachShape->Select(false, &dc);
|
|
|
|
redraw = true;
|
2000-03-03 06:25:10 -05:00
|
|
|
}
|
|
|
|
}
|
2003-11-09 16:40:34 -05:00
|
|
|
node = node->GetNext();
|
2000-03-03 06:25:10 -05:00
|
|
|
}
|
2004-06-09 12:42:34 -04:00
|
|
|
GetShape()->Select(true, &dc);
|
2000-03-03 06:25:10 -05:00
|
|
|
if (redraw)
|
|
|
|
GetShape()->GetCanvas()->Redraw(dc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (keys & KEY_CTRL)
|
|
|
|
{
|
|
|
|
// Do something for CONTROL
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-19 11:14:07 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2000-03-03 06:25:10 -05:00
|
|
|
wxGetApp().frame->SetStatusText(label);
|
2004-07-19 11:14:07 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2000-03-03 06:25:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implement connection of two shapes by right-dragging between them.
|
|
|
|
*/
|
|
|
|
|
2003-08-21 05:05:56 -04:00
|
|
|
void MyEvtHandler::OnBeginDragRight(double x, double y, int WXUNUSED(keys), int attachment)
|
2000-03-03 06:25:10 -05:00
|
|
|
{
|
|
|
|
// Force attachment to be zero for now. Eventually we can deal with
|
|
|
|
// the actual attachment point, e.g. a rectangle side if attachment mode is on.
|
|
|
|
attachment = 0;
|
|
|
|
|
|
|
|
wxClientDC dc(GetShape()->GetCanvas());
|
|
|
|
GetShape()->GetCanvas()->PrepareDC(dc);
|
|
|
|
|
|
|
|
wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
|
|
|
|
dc.SetLogicalFunction(OGLRBLF);
|
|
|
|
dc.SetPen(dottedPen);
|
|
|
|
double xp, yp;
|
|
|
|
GetShape()->GetAttachmentPosition(attachment, &xp, &yp);
|
|
|
|
dc.DrawLine((long) xp, (long) yp, (long) x, (long) y);
|
|
|
|
GetShape()->GetCanvas()->CaptureMouse();
|
|
|
|
}
|
|
|
|
|
2003-08-21 05:05:56 -04:00
|
|
|
void MyEvtHandler::OnDragRight(bool WXUNUSED(draw), double x, double y, int WXUNUSED(keys), int attachment)
|
2000-03-03 06:25:10 -05:00
|
|
|
{
|
|
|
|
// Force attachment to be zero for now
|
|
|
|
attachment = 0;
|
|
|
|
|
|
|
|
wxClientDC dc(GetShape()->GetCanvas());
|
|
|
|
GetShape()->GetCanvas()->PrepareDC(dc);
|
|
|
|
|
|
|
|
wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
|
|
|
|
dc.SetLogicalFunction(OGLRBLF);
|
|
|
|
dc.SetPen(dottedPen);
|
|
|
|
double xp, yp;
|
|
|
|
GetShape()->GetAttachmentPosition(attachment, &xp, &yp);
|
|
|
|
dc.DrawLine((long) xp, (long) yp, (long) x, (long) y);
|
|
|
|
}
|
|
|
|
|
2003-08-21 05:05:56 -04:00
|
|
|
void MyEvtHandler::OnEndDragRight(double x, double y, int WXUNUSED(keys), int WXUNUSED(attachment))
|
2000-03-03 06:25:10 -05:00
|
|
|
{
|
|
|
|
GetShape()->GetCanvas()->ReleaseMouse();
|
|
|
|
MyCanvas *canvas = (MyCanvas *)GetShape()->GetCanvas();
|
|
|
|
|
|
|
|
// Check if we're on an object
|
|
|
|
int new_attachment;
|
|
|
|
wxShape *otherShape = canvas->FindFirstSensitiveShape(x, y, &new_attachment, OP_DRAG_RIGHT);
|
|
|
|
|
|
|
|
if (otherShape && !otherShape->IsKindOf(CLASSINFO(wxLineShape)))
|
|
|
|
{
|
|
|
|
canvas->view->GetDocument()->GetCommandProcessor()->Submit(
|
2003-08-21 05:05:56 -04:00
|
|
|
new DiagramCommand(_T("wxLineShape"), OGLEDIT_ADD_LINE, (DiagramDocument *)canvas->view->GetDocument(), CLASSINFO(wxLineShape),
|
2004-06-09 12:42:34 -04:00
|
|
|
0.0, 0.0, false, NULL, GetShape(), otherShape));
|
2000-03-03 06:25:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-21 05:05:56 -04:00
|
|
|
void MyEvtHandler::OnEndSize(double WXUNUSED(x), double WXUNUSED(y))
|
2000-03-03 06:25:10 -05:00
|
|
|
{
|
|
|
|
wxClientDC dc(GetShape()->GetCanvas());
|
|
|
|
GetShape()->GetCanvas()->PrepareDC(dc);
|
|
|
|
|
2003-08-21 05:05:56 -04:00
|
|
|
GetShape()->FormatText(dc, /* (char*) (const char*) */ label);
|
2000-03-03 06:25:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Diagram
|
|
|
|
*/
|
2003-07-22 12:15:49 -04:00
|
|
|
|
|
|
|
#if wxUSE_PROLOGIO
|
2000-03-03 06:25:10 -05:00
|
|
|
|
|
|
|
bool MyDiagram::OnShapeSave(wxExprDatabase& db, wxShape& shape, wxExpr& expr)
|
|
|
|
{
|
|
|
|
wxDiagram::OnShapeSave(db, shape, expr);
|
|
|
|
MyEvtHandler *handler = (MyEvtHandler *)shape.GetEventHandler();
|
2003-08-21 05:05:56 -04:00
|
|
|
expr.AddAttributeValueString(_T("label"), handler->label);
|
2004-06-09 12:42:34 -04:00
|
|
|
return true;
|
2000-03-03 06:25:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MyDiagram::OnShapeLoad(wxExprDatabase& db, wxShape& shape, wxExpr& expr)
|
|
|
|
{
|
|
|
|
wxDiagram::OnShapeLoad(db, shape, expr);
|
2003-08-21 05:05:56 -04:00
|
|
|
wxChar *label = NULL;
|
|
|
|
expr.AssignAttributeValue(_T("label"), &label);
|
2000-03-03 06:25:10 -05:00
|
|
|
MyEvtHandler *handler = new MyEvtHandler(&shape, &shape, wxString(label));
|
|
|
|
shape.SetEventHandler(handler);
|
|
|
|
|
|
|
|
if (label)
|
|
|
|
delete[] label;
|
2004-06-09 12:42:34 -04:00
|
|
|
return true;
|
2000-03-03 06:25:10 -05:00
|
|
|
}
|
|
|
|
|
2003-07-22 12:15:49 -04:00
|
|
|
#endif
|
|
|
|
|
2000-03-03 06:25:10 -05:00
|
|
|
/*
|
|
|
|
* New shapes
|
|
|
|
*/
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(wxRoundedRectangleShape, wxRectangleShape)
|
|
|
|
|
|
|
|
wxRoundedRectangleShape::wxRoundedRectangleShape(double w, double h):
|
|
|
|
wxRectangleShape(w, h)
|
|
|
|
{
|
|
|
|
// 0.3 of the smaller rectangle dimension
|
|
|
|
SetCornerRadius((double) -0.3);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(wxDiamondShape, wxPolygonShape)
|
|
|
|
|
|
|
|
wxDiamondShape::wxDiamondShape(double w, double h):
|
|
|
|
wxPolygonShape()
|
|
|
|
{
|
|
|
|
// wxPolygonShape::SetSize relies on the shape having non-zero
|
|
|
|
// size initially.
|
|
|
|
if (w == 0.0)
|
|
|
|
w = 60.0;
|
|
|
|
if (h == 0.0)
|
|
|
|
h = 60.0;
|
|
|
|
|
|
|
|
wxList *thePoints = new wxList;
|
|
|
|
wxRealPoint *point = new wxRealPoint(0.0, (-h/2.0));
|
|
|
|
thePoints->Append((wxObject*) point);
|
|
|
|
|
|
|
|
point = new wxRealPoint((w/2.0), 0.0);
|
|
|
|
thePoints->Append((wxObject*) point);
|
|
|
|
|
|
|
|
point = new wxRealPoint(0.0, (h/2.0));
|
|
|
|
thePoints->Append((wxObject*) point);
|
|
|
|
|
|
|
|
point = new wxRealPoint((-w/2.0), 0.0);
|
|
|
|
thePoints->Append((wxObject*) point);
|
|
|
|
|
|
|
|
Create(thePoints);
|
|
|
|
}
|