📄 crdiagram.c
字号:
//////////////////////////////////////////////////////////////////////////////////// This file is part of Toolkit for Conceptual Modeling (TCM).// (c) copyright 1995, Vrije Universiteit Amsterdam.// Author: Frank Dehne (frank@cs.vu.nl).//// TCM is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// TCM is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with TCM; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA// 02111-1307, USA.////////////////////////////////////////////////////////////////////////////////#include "crgraph.h"#include "crwindow.h"#include "crviewer.h"#include "crchecks.h"#include "messagedialog.h"#include "grafport.h"#include "tripleclassbox.h"#include "doubleclassbox.h"#include "c1arrow.h"#include "c2r2line.h"#include "binaryrelationship.h"#include "componentfunction.h"#include "isarelationship.h"#include "modejunction.h"#include "emptyedge.h"#include "miniellipse.h"#include "textbox.h"#include "comment.h"#include "crdiagram.h"#include <limits.h>CRDiagram::CRDiagram(Config *c, CRWindow *d, CRViewer *v, CRGraph *g): ERDiagram(c, d, v, g) { UpdateNodeType(1); UpdateEdgeType(1); crChecks = new CRChecks(this, g);}CRDiagram::~CRDiagram() { delete crChecks;}Thing *CRDiagram::CreateThing(int classNr) { Grafport *g = GetDiagramViewer()->GetGrafport(); ShapeView *v = GetDiagramViewer()->GetCurView(); CRGraph *cg = (CRGraph *)GetGraph(); Thing *thing = 0; // view if (classNr == Code::VIEW) thing = new ShapeView(GetDiagramViewer()); // node shapes else if (classNr==Code::TRIPLE_BOX) thing = new TripleClassBox(v, g, 0, 0); else if (classNr==Code::DOUBLE_BOX) thing = new DoubleClassBox(v, g, 0, 0); else if (classNr==Code::BOX) thing = new Box(v, g, 0, 0); else if (classNr == Code::MINI_ELLIPSE) { MiniEllipse *ellipse = new MiniEllipse(v, g, 0, 0); // extra for older diagram versions. ellipse->SetFixedName(False); thing = ellipse; } else if (classNr==Code::TEXT_BOX) thing = new TextBox(v, g, 0, 0); // lines else if (classNr==Code::T1_LINE) thing = new C1Arrow(v, g, 0, 0, 0); else if (classNr==Code::T4_LINE || classNr==Code::C2R2_LINE) thing = new C2R2Line(v, g, 0, 0, 0); else if (classNr==Code::LINE) thing = new Line(v, g, 0, 0, 0); // (T1_)ARROW and DOUBLE_ARROW from old file formats. else if (classNr==Code::T1_ARROW) thing = new C1Arrow(v, g, 0, 0, 0); else if (classNr==Code::ARROW) { Line *line = new Line(v, g, 0, 0, 0); line->SetEnd2(LineEnd::FILLED_ARROW); line->SetFixedName(True); thing = line; } else if (classNr==Code::DOUBLE_ARROW) { Line *line = new Line(v, g, 0, 0, 0); line->SetEnd1(LineEnd::FILLED_ARROW); line->SetEnd2(LineEnd::FILLED_ARROW); thing = line; } // nodes else if (classNr==Code::CLASS_NODE) thing = new ClassNode(cg); else if (classNr==Code::TAXONOMY_JUNCTION) thing = new TaxonomyJunction(cg); else if (classNr==Code::MODE_JUNCTION) thing = new ModeJunction(cg); else if (classNr==Code::COMMENT) thing = new Comment(cg); // edges else if (classNr==Code::BINARY_RELATIONSHIP) thing = new BinaryRelationship(cg, 0, 0); else if (classNr==Code::FUNCTION) thing = new Function(cg, 0, 0); else if (classNr==Code::COMPONENT_FUNCTION) thing = new ComponentFunction(cg, 0, 0); else if (classNr==Code::EMPTY_EDGE) thing = new EmptyEdge(cg, 0, 0); else if (classNr==Code::ISA_RELATIONSHIP) thing = new IsaRelationship(cg, 0, 0); else error("%s, line %d: impl error: wrong class number %d\n", __FILE__, __LINE__, classNr); return thing;} Node *CRDiagram::CreateNode(){ Node *node = 0; CRGraph *g = (CRGraph *)GetGraph(); if (GetNodeType()==Code::MODE_JUNCTION) node = new ModeJunction(g); else if (GetNodeType()==Code::TAXONOMY_JUNCTION) node = new TaxonomyJunction(g); else if (GetNodeType()==Code::CLASS_NODE) node = new ClassNode(g); else if (GetNodeType()==Code::COMMENT) node = new Comment(g); else error( "%s, line %d: impl error: unknown node type\n", __FILE__, __LINE__); return node;}Edge *CRDiagram::CreateEdge(Subject *subj1, Subject *subj2){ if (!CheckEdgeConstraints(subj1, subj2)) return 0; Edge *edge = 0; CRGraph *g = (CRGraph *)GetGraph(); if (GetEdgeType() == Code::EMPTY_EDGE) edge = new EmptyEdge(g, subj1, subj2); else if (GetEdgeType() == Code::FUNCTION) edge = new Function(g, subj1, subj2); else if (GetEdgeType() == Code::BINARY_RELATIONSHIP) edge = new BinaryRelationship(g, subj1, subj2); else if (GetEdgeType() == Code::COMPONENT_FUNCTION) edge = new ComponentFunction(g, subj1, subj2); else if (GetEdgeType() == Code::ISA_RELATIONSHIP) edge = new IsaRelationship(g, subj1, subj2); else error( "%s, line %d: impl error: unknown edge type\n", __FILE__, __LINE__); if (GetEdgeType() == Code::EMPTY_EDGE || GetEdgeType() == Code::ISA_RELATIONSHIP) { if (!CheckIsaLoop(edge) || !CheckTaxonomyCombination(edge)) { delete edge; return 0; } } return edge;}NodeShape *CRDiagram::CreateNodeShape(Node *node, int x, int y) { NodeShape *shape = 0; Grafport *g = GetDiagramViewer()->GetGrafport(); ShapeView *v = GetDiagramViewer()->GetCurView(); if (GetNodeShapeType() == Code::BOX) shape = new Box(v, g, x, y); else if (GetNodeShapeType() == Code::MINI_ELLIPSE) { shape = new MiniEllipse(v, g, x, y); shape->SetFixedName(False); } else if (GetNodeShapeType() == Code::DOUBLE_BOX) shape = new DoubleClassBox(v, g, x, y); else if (GetNodeShapeType() == Code::TEXT_BOX) shape = new TextBox(v, g, x, y); else if (GetNodeShapeType() == Code::TRIPLE_BOX) shape = new TripleClassBox(v, g, x, y); else error( "%s, line %d: impl error: " "node shape type doesn't exist\n", __FILE__, __LINE__); if (check(shape)) { shape->SetSubject(node); shape->SetTextShape(); } return shape;}Line *CRDiagram::CreateLine( Edge *edge, GShape *from, GShape *to, List<Point *> *l) { Grafport *g = GetDiagramViewer()->GetGrafport(); ShapeView *v = GetDiagramViewer()->GetCurView(); Line *line = 0; if (GetLineType()== Code::T1_LINE) line = new C1Arrow(v, g, from, to, l, IsCurve()); else if (GetLineType()== Code::C2R2_LINE) line = new C2R2Line(v, g, from, to, l, IsCurve()); else if (GetLineType()== Code::LINE) line = new Line(v, g, from, to, l, IsCurve()); else error( "%s, line %d: impl error: " "line type does not exist\n", __FILE__, __LINE__); if (check(line)) { line->SetSubject(edge); line->SetTextShape(); line->SetEnd1(GetLineEnd1()); line->SetEnd2(GetLineEnd2()); if (GetEdgeType()==Code::EMPTY_EDGE || GetEdgeType()==Code::ISA_RELATIONSHIP) line->SetFixedName(True); if (GetLineEnd1()==LineEnd::FILLED_ARROW) { if (edge->GetClassType()==Code::FUNCTION) { string constr("1"); ((Function *)edge)->SetConstraint(&constr); } } } return line;}void CRDiagram::UpdateNodeType(int num) { ((DiagramWindow *)GetMainWindow())->SetNodeName(num); switch (num) { case 1: SetNodeType(Code::CLASS_NODE); SetNodeShapeType(Code::BOX); SetNodeLineStyle(LineStyle::SOLID); break; case 2: SetNodeType(Code::CLASS_NODE); SetNodeShapeType(Code::DOUBLE_BOX); SetNodeLineStyle(LineStyle::SOLID); break; case 3: SetNodeType(Code::CLASS_NODE); SetNodeShapeType(Code::TRIPLE_BOX); SetNodeLineStyle(LineStyle::SOLID); break; case 4: SetNodeType(Code::TAXONOMY_JUNCTION); SetNodeShapeType(Code::MINI_ELLIPSE); SetNodeLineStyle(LineStyle::SOLID); break; case 5: SetNodeType(Code::MODE_JUNCTION); SetNodeShapeType(Code::MINI_ELLIPSE); SetNodeLineStyle(LineStyle::DASHED); break; case 6: SetNodeType(Code::COMMENT); SetNodeShapeType(Code::TEXT_BOX); SetNodeLineStyle(LineStyle::INVISIBLE); break; default: error("%s, line %d: impl error: " "unknown node type selected\n", __FILE__,__LINE__); }}void CRDiagram::UpdateEdgeType(int num) { ((DiagramWindow *)GetMainWindow())->SetEdgeName(num); switch(num) { case 1: SetEdgeType(Code::BINARY_RELATIONSHIP); SetLineType(Code::C2R2_LINE); SetEdgeLineStyle(LineStyle::SOLID); SetLineEnd1(LineEnd::EMPTY);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -