📄 shapes.cpp
字号:
wxShape* newShape = GetShape()->CreateNewCopy(); newShape->SetX(xx); newShape->SetY(yy); csDiagramCommand* cmd = new csDiagramCommand(_T("Move"), (csDiagramDocument*)canvas->GetView()->GetDocument(), new csCommandState(ID_CS_MOVE, newShape, GetShape())); // Move line points wxObjectList::compatibility_iterator node = GetShape()->GetCanvas()->GetDiagram()->GetShapeList()->GetFirst(); while (node) { wxShape* shape = (wxShape*) node->GetData(); // Only move the line point(s) if both ends move too if (shape->IsKindOf(CLASSINFO(wxLineShape)) && ((wxLineShape*)shape)->GetTo()->Selected() && ((wxLineShape*)shape)->GetFrom()->Selected()) { wxLineShape* lineShape = (wxLineShape*) shape; if (lineShape->GetLineControlPoints()->GetCount() > 2) { wxLineShape* newLineShape = (wxLineShape*) lineShape->CreateNewCopy(); wxObjectList::compatibility_iterator node1 = newLineShape->GetLineControlPoints()->GetFirst(); while (node1) { wxRealPoint *point = (wxRealPoint *)node1->GetData(); point->x += offsetX; point->y += offsetY; node1 = node1->GetNext(); } cmd->AddState(new csCommandState(ID_CS_MOVE_LINE_POINT, newLineShape, lineShape)); lineShape->Erase(dc); } } node = node->GetNext(); } // Add other selected node shapes, if any node = GetShape()->GetCanvas()->GetDiagram()->GetShapeList()->GetFirst(); while (node) { wxShape* shape = (wxShape*) node->GetData(); if (shape->Selected() && !shape->IsKindOf(CLASSINFO(wxLineShape)) && (shape != GetShape())) { wxShape* newShape2 = shape->CreateNewCopy(); newShape2->SetX(shape->GetX() + offsetX); newShape2->SetY(shape->GetY() + offsetY); cmd->AddState(new csCommandState(ID_CS_MOVE, newShape2, shape)); } node = node->GetNext(); } canvas->GetView()->GetDocument()->GetCommandProcessor()->Submit(cmd);}void csEvtHandler::OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys, int attachment){ wxShape* shape = GetShape(); csCanvas *canvas = (csCanvas *)GetShape()->GetCanvas(); if (shape->IsKindOf(CLASSINFO(wxLineShape))) { // TODO: Do/Undo support for line operations ((wxLineShape*)shape)->wxLineShape::OnSizingEndDragLeft(pt, x, y, keys, attachment);#if 0 wxLineShape* lineShape = (wxLineShape*) shape; wxLineControlPoint* lpt = (wxLineControlPoint*) pt; wxClientDC dc(canvas); canvas->PrepareDC(dc); shape->SetDisableLabel(false); if (lpt->m_type == CONTROL_POINT_LINE) { canvas->Snap(&x, &y); dc.SetLogicalFunction(wxCOPY); lpt->SetX(x); lpt->SetY(y); lpt->m_point->x = x; lpt->m_point->y = y; this->OnMoveLink(dc); } if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM) { if (lpt->m_oldCursor) canvas->SetCursor(lpt->m_oldCursor); lineShape->Erase(dc); lpt->SetX(x); lpt->SetY(y); if (lineShape->GetFrom()) { lineShape->GetFrom()->MoveLineToNewAttachment(dc, lineShape, x, y); } } if (lpt->m_type == CONTROL_POINT_ENDPOINT_TO) { if (lpt->m_oldCursor) canvas->SetCursor(lpt->m_oldCursor); lpt->SetX(x); lpt->SetY(y); if (lineShape->GetTo()) { lineShape->GetTo()->MoveLineToNewAttachment(dc, lineShape, x, y); } }#endif return; } wxClientDC dc(canvas); canvas->PrepareDC(dc); canvas->ReleaseMouse(); dc.SetLogicalFunction(wxCOPY);// shape->Erase(dc);/* shape->Recompute(); shape->ResetControlPoints(); if (!pt->m_eraseObject) shape->Show(false);*/ wxShape* newShape = shape->CreateNewCopy(); if (newShape->IsKindOf(CLASSINFO(wxPolygonShape))) { wxPolygonControlPoint* ppt = (wxPolygonControlPoint*) pt; newShape->SetSize(ppt->GetNewSize().x, ppt->GetNewSize().y); ((wxPolygonShape *)newShape)->CalculateBoundingBox(); ((wxPolygonShape *)newShape)->CalculatePolygonCentre(); newShape->ResetControlPoints(); } else { newShape->SetSize(pt->sm_controlPointDragEndWidth, pt->sm_controlPointDragEndHeight); if (shape->GetCentreResize()) { // Old position is fine } else { newShape->SetX(pt->sm_controlPointDragPosX); newShape->SetY(pt->sm_controlPointDragPosY); } } csDiagramCommand* cmd = new csDiagramCommand(_T("Size"), (csDiagramDocument*)canvas->GetView()->GetDocument(), new csCommandState(ID_CS_SIZE, newShape, shape)); canvas->GetView()->GetDocument()->GetCommandProcessor()->Submit(cmd);}void csEvtHandler::OnEndSize(double WXUNUSED(x), double WXUNUSED(y)){ wxClientDC dc(GetShape()->GetCanvas()); GetShape()->GetCanvas()->PrepareDC(dc); GetShape()->FormatText(dc, m_label);}void csEvtHandler::OnChangeAttachment(int attachment, wxLineShape* line, wxList& ordering){ csCanvas *canvas = (csCanvas *)GetShape()->GetCanvas(); // We actually submit two different states: one to change the ordering, and another // to change the attachment for the line. // Problem. If we refresh after the attachment change, we'll get a flicker. // We really want to do both in a oner. csDiagramCommand* cmd = new csDiagramCommand(_T("Change attachment"), (csDiagramDocument*)canvas->GetView()->GetDocument()); wxLineShape* newLine = (wxLineShape*) line->CreateNewCopy(); if (line->GetTo() == GetShape()) newLine->SetAttachmentTo(attachment); else newLine->SetAttachmentFrom(attachment); cmd->AddState(new csCommandState(ID_CS_CHANGE_LINE_ATTACHMENT, newLine, line)); // Change ordering wxShape* newShape = GetShape()->CreateNewCopy(); newShape->ApplyAttachmentOrdering(ordering); cmd->AddState(new csCommandState(ID_CS_CHANGE_LINE_ORDERING, newShape, GetShape())); canvas->GetView()->GetDocument()->GetCommandProcessor()->Submit(cmd);}void csEvtHandler::OnLeftDoubleClick(double WXUNUSED(x), double WXUNUSED(y), int WXUNUSED(keys), int WXUNUSED(attachment)){ EditProperties();}// Popup up a property dialogbool csEvtHandler::EditProperties(){ wxShape* shape = GetShape(); // For now, no line property editing if (shape->IsKindOf(CLASSINFO(wxLineShape))) return false; csDiagramView* view = ((csCanvas*)shape->GetCanvas())->GetView(); wxPanel* attributeDialog; wxString attributeDialogName; wxString title; if (shape->IsKindOf(CLASSINFO(csThinRectangleShape))) { attributeDialog = new csThinRectangleDialog; attributeDialogName = _T("thin_rectangle"); title = _T("Thin Rectangle Properties"); } else if (shape->IsKindOf(CLASSINFO(csWideRectangleShape))) { attributeDialog = new csWideRectangleDialog; attributeDialogName = _T("wide_rectangle"); title = _T("Wide Rectangle Properties"); } else if (shape->IsKindOf(CLASSINFO(csTriangleShape))) { attributeDialog = new csTriangleDialog; attributeDialogName = _T("triangle"); title = _T("Triangle Properties"); } else if (shape->IsKindOf(CLASSINFO(csSemiCircleShape))) { attributeDialog = new csSemiCircleDialog; attributeDialogName = _T("semi_circle"); title = _T("Semicircle Properties"); } else if (shape->IsKindOf(CLASSINFO(csCircleShape))) { attributeDialog = new csCircleDialog; attributeDialogName = _T("circle"); title = _T("Circle Properties"); } else if (shape->IsKindOf(CLASSINFO(csCircleShadowShape))) { attributeDialog = new csCircleShadowDialog; attributeDialogName = _T("circle_shadow"); title = _T("Circle Shadow Properties"); } else if (shape->IsKindOf(CLASSINFO(csTextBoxShape))) { attributeDialog = new csTextBoxDialog; attributeDialogName = _T("text_box"); title = _T("Text Box Properties"); } else if (shape->IsKindOf(CLASSINFO(csGroupShape))) { attributeDialog = new csGroupDialog; attributeDialogName = _T("group"); title = _T("Group Properties"); } else if (shape->IsKindOf(CLASSINFO(csOctagonShape))) { attributeDialog = new csOctagonDialog; attributeDialogName = _T("octagon"); title = _T("Octagon Properties"); } else { wxMessageBox(_T("Unrecognised shape."), _T("Studio"), wxICON_EXCLAMATION); return false; } wxString newLabel(m_label);#if wxUSE_WX_RESOURCES csShapePropertiesDialog* dialog = new csShapePropertiesDialog(shape->GetCanvas()->GetParent(), title, attributeDialog, attributeDialogName); dialog->GetGeneralPropertiesDialog()->SetShapeLabel(m_label); if (dialog->ShowModal() == wxID_CANCEL) { dialog->Destroy(); return false; } newLabel = dialog->GetGeneralPropertiesDialog()->GetShapeLabel(); dialog->Destroy();#else wxUnusedVar(attributeDialog);#endif // wxUSE_WX_RESOURCES wxShape* newShape = shape->CreateNewCopy(); csEvtHandler* handler2 = (csEvtHandler *)newShape->GetEventHandler(); handler2->m_label = newLabel; view->GetDocument()->GetCommandProcessor()->Submit(new csDiagramCommand(_T("Edit properties"), (csDiagramDocument*) view->GetDocument(), new csCommandState(ID_CS_EDIT_PROPERTIES, newShape, shape))); return true;}/* * Diagram */#if wxUSE_PROLOGIObool csDiagram::OnShapeSave(wxExprDatabase& db, wxShape& shape, wxExpr& expr){ wxDiagram::OnShapeSave(db, shape, expr); csEvtHandler *handler = (csEvtHandler *)shape.GetEventHandler(); expr.AddAttributeValueString(_T("label"), handler->m_label); return true;}bool csDiagram::OnShapeLoad(wxExprDatabase& db, wxShape& shape, wxExpr& expr){ wxDiagram::OnShapeLoad(db, shape, expr); wxString label = wxEmptyString; expr.GetAttributeValue(_T("label"), label); csEvtHandler *handler = new csEvtHandler(&shape, &shape, label); shape.SetEventHandler(handler); return true;}#endif // wxUSE_PROLOGIOIMPLEMENT_DYNAMIC_CLASS(csThinRectangleShape, wxDrawnShape)csThinRectangleShape::csThinRectangleShape(){ SetDrawnPen(wxBLACK_PEN); wxBrush* brush = wxTheBrushList->FindOrCreateBrush(wxColour(220, 220, 220), wxSOLID); SetDrawnBrush(brush); double w = csSTANDARD_SHAPE_WIDTH/2; double h = csSTANDARD_SHAPE_WIDTH; DrawRectangle(wxRect((int)(- w/2), (int)(- h/2), (int)(w), (int)(h))); CalculateSize(); SetAttachmentMode(ATTACHMENT_MODE_BRANCHING); SetBranchStyle(BRANCHING_ATTACHMENT_NORMAL|BRANCHING_ATTACHMENT_BLOB); SetCentreResize(false);}IMPLEMENT_DYNAMIC_CLASS(csWideRectangleShape, wxDrawnShape)csWideRectangleShape::csWideRectangleShape(){ SetDrawnPen(wxBLACK_PEN); wxBrush* brush = wxTheBrushList->FindOrCreateBrush(wxColour(220, 220, 220), wxSOLID); SetDrawnBrush(brush); double w = csSTANDARD_SHAPE_WIDTH; double h = w/2.0; DrawRoundedRectangle(wxRect((int)(- w/2), (int)(- h/2), (int)(w), (int)(h)), -0.3); CalculateSize(); SetAttachmentMode(ATTACHMENT_MODE_BRANCHING); SetBranchStyle(BRANCHING_ATTACHMENT_NORMAL|BRANCHING_ATTACHMENT_BLOB); SetCentreResize(false);}IMPLEMENT_DYNAMIC_CLASS(csTriangleShape, wxDrawnShape)csTriangleShape::csTriangleShape(){ SetDrawnPen(wxBLACK_PEN); wxBrush* brush = wxTheBrushList->FindOrCreateBrush(wxColour(220, 220, 220), wxSOLID); SetDrawnBrush(brush); double w = csSTANDARD_SHAPE_WIDTH; double h = (csSTANDARD_SHAPE_WIDTH*2.0)/3.0; // Triangle, from top vertex wxPoint* points = new wxPoint[3]; points[0] = wxPoint( 0 , (int)(- h / 2) ); points[1] = wxPoint( (int)(w / 2) , (int)(h / 2) ); points[2] = wxPoint( (int)(-w / 2), (int)(h / 2) ); DrawPolygon(3, points, oglMETAFLAGS_OUTLINE); delete[] points; // Add another triangle at the top for the black bit SetDrawnBrush(wxBLACK_BRUSH); points = new wxPoint[3]; // Calculate where the new points will be, using the proportions // of the triangle. double h1 = 8; // Height of little triangle.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -