📄 scdiagram.c
字号:
//////////////////////////////////////////////////////////////////////////////////// This file is part of Toolkit for Conceptual Modeling (TCM).// (c) copyright 2001, Universiteit Twente.// Author: Frank Dehne (frank@cs.vu.nl),// David N. Jansen (dnjansen@cs.utwente.nl)// Rik Eshuis (eshuis@cs.utwente.nl)// Jose Canete (canete@lsi.us.es)//// 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 "scgraph.h"#include "scwindow.h"#include "textbox.h"#include "comment.h"#include "commentlink.h"#include "scdiagram.h"#include "roundedbox.h"#include "scdandstatebox.h"#include "scdorstate.h"#include "scdandstate.h"#include "scdandedge.h"#include "scdtransitionedge.h"#include "scdandline.h"#include "blackdot.h"#include "bullseye.h"#include "minidiamond.h"#include "solidhorizontalbar.h"#include "solidverticalbar.h"#include "note.h"#include "notebox.h"#include "scddefaultstate.h"#include "scdfinalstate.h"#include "scddecisionstate.h"#include "scdsynchronizationstate.h"#include "scviewer.h"#ifdef MODELCHECK#include "modelcheckdialog.h"//#include "scdsmv.h"#include <ctype.h>#endif#include "outputfile.h"#include "adsmcoutputparse.h"#include "adsedgelabelparse.h"#include <limits.h>#include <stdlib.h>#include <unistd.h>SCDiagram::SCDiagram(Config *c, SCWindow *d, SCViewer *v, SCGraph *g): Diagram(c,d,v,g) { UpdateNodeType(1); UpdateEdgeType(1);// GetReplaceDialog()->ManageNameOnlyToggle(True);// scChecks = new SCChecks(this,g);#ifdef MODELCHECK promptDialog = new ModelCheckDialog(GetMainWindow()->GetWidget()); promptDialog->Initialize();#endif}SCDiagram::~SCDiagram() {#ifdef MODELCHECK delete promptDialog;#endif// delete scChecks;}/* virtual */ void SCDiagram::Initialize() { Diagram::Initialize(); SetHierarchic(True);}Thing *SCDiagram::CreateThing(int classNr) { Grafport *g = GetDiagramViewer()->GetGrafport(); ShapeView *v = GetDiagramViewer()->GetCurView(); SCGraph *sg = (SCGraph *)GetGraph(); Thing *thing = 0; switch ( classNr ) { // view case Code::VIEW: thing = new ShapeView(GetDiagramViewer()); break; // node shapes case Code::ROUNDED_BOX: thing = new RoundedBox(v, g, 0, 0); break; case Code::SCD_AND_STATE_BOX: thing = new SCDAndStateBox(v, g, 0, 0); break; case Code::TEXT_BOX: thing = new TextBox(v, g, 0, 0); break; case Code::BLACK_DOT: thing = new BlackDot(v, g, 0, 0); break; case Code::BULLS_EYE: thing = new BullsEye(v, g, 0, 0); break; case Code::MINI_DIAMOND: thing = new MiniDiamond(v, g, 0, 0); break; case Code::SOLID_HORIZONTAL_BAR: thing = new SolidHorizontalBar(v, g, 0, 0); break; case Code::SOLID_VERTICAL_BAR: thing = new SolidVerticalBar(v, g, 0, 0); break; case Code::NOTE_BOX: thing = new NoteBox(v, g, 0, 0); break; // lines case Code::LINE: thing = new Line(v, g, 0, 0, 0); break;// case Code::ARROW:// Line *line = new Line(v, g, 0, 0, 0);// line->SetEnd1(LineEnd::EMPTY);// line->SetEnd2(LineEnd::FILLED_ARROW);// thing = line;// break; case Code::SCD_AND_LINE: thing = new SCDAndLine(v, g, 0, 0); break; // nodes case Code::SCD_AND_STATE: thing = new SCDAndState(sg); break; case Code::SCD_DECISION_STATE: thing = new SCDDecisionState(sg); break; case Code::SCD_DEFAULT_STATE: thing = new SCDDefaultState(sg); break; case Code::SCD_FINAL_STATE: thing = new SCDFinalState(sg); break; case Code::SCD_OR_STATE: thing = new SCDOrState(sg); break; case Code::SCD_SYNCHRONIZATION_STATE: thing = new SCDSynchronizationState(sg); break; case Code::COMMENT: thing = new Comment(sg); break; case Code::NOTE: thing = new Note(sg); break; // edges case Code::SCD_TRANSITION_EDGE: thing = new SCDTransitionEdge(sg, 0, 0); break; case Code::SCD_AND_EDGE: thing = new SCDAndEdge(sg, 0, 0); break; case Code::COMMENT_LINK: thing = new CommentLink(sg, 0, 0); break; default: error("%s, line %d: impl error: " "wrong class number %d\n", __FILE__, __LINE__, classNr); } return thing;}Node *SCDiagram::CreateNode() { Node *node = 0; SCGraph *sg = (SCGraph *)GetGraph(); switch ( GetNodeType() ) { case Code::SCD_AND_STATE: node = new SCDAndState(sg); break; case Code::SCD_DECISION_STATE: node = new SCDDecisionState(sg); break; case Code::SCD_DEFAULT_STATE: node = new SCDDefaultState(sg); break; case Code::SCD_FINAL_STATE: node = new SCDFinalState(sg); break; case Code::SCD_OR_STATE: node = new SCDOrState(sg); break; case Code::SCD_SYNCHRONIZATION_STATE: node = new SCDSynchronizationState(sg); break; case Code::COMMENT: node = new Comment(sg); break; case Code::NOTE: node = new Note(sg); break; default: error("%s, line %d: impl error: " "unknown node type\n", __FILE__, __LINE__); } return node;}Edge *SCDiagram::CreateEdge(Subject *subj1, Subject *subj2){ if ( ! CheckEdgeConstraints(subj1, subj2) ) return 0; Edge *edge = 0; SCGraph *sg = (SCGraph *)GetGraph(); switch ( GetEdgeType() ) { case Code::SCD_TRANSITION_EDGE: edge = new SCDTransitionEdge(sg, subj1, subj2); break; case Code::SCD_AND_EDGE: if ( ! CheckAndEdgeConstraints(subj1, subj2) ) return 0; edge = new SCDAndEdge(sg, subj1, subj2); break; case Code::COMMENT_LINK: edge = new CommentLink(sg, subj1, subj2); break; default: error("%s, line %d: impl error: " "unknown edge type\n", __FILE__, __LINE__); } return edge;}NodeShape *SCDiagram::CreateNodeShape(Node *node, int x, int y) { NodeShape *shape = 0; Grafport *g = GetDiagramViewer()->GetGrafport(); ShapeView *v = GetDiagramViewer()->GetCurView(); switch ( GetNodeShapeType() ) { case Code::ROUNDED_BOX: shape = new RoundedBox(v, g, x, y); break; case Code::SCD_AND_STATE_BOX: shape = new SCDAndStateBox(v, g, x, y); break; case Code::TEXT_BOX: shape = new TextBox(v, g, x, y); break; case Code::NOTE_BOX: shape = new NoteBox(v, g, x, y); break; case Code::BLACK_DOT: shape = new BlackDot(v, g, x, y); break; case Code::BULLS_EYE: shape = new BullsEye(v, g, x, y); break; case Code::MINI_DIAMOND: shape = new MiniDiamond(v, g, x, y); break; case Code::SOLID_HORIZONTAL_BAR: shape = new SolidHorizontalBar(v, g, x, y); break; case Code::SOLID_VERTICAL_BAR: shape = new SolidVerticalBar(v, g, x, y); break; default: error("%s, line %d: impl error: " "node shape type does not exist\n", __FILE__, __LINE__); } if (check(shape)) { shape->SetSubject(node); shape->SetTextShape(); } return shape;}Line *SCDiagram::CreateLine( Edge *edge, GShape *from, GShape *to, List<Point *> *l) { Line *line = 0; Grafport *g = GetDiagramViewer()->GetGrafport(); ShapeView *v = GetDiagramViewer()->GetCurView();// *((*l)[0]) = *(from->GetPosition());// *((*l)[l->count()-1]) = *(to->GetPosition()); switch ( GetLineType() ) { case Code::LINE: line = new Line(v, g, from, to, l, IsCurve()); break; case Code::SCD_AND_LINE: line = new SCDAndLine(v, g, from, l, IsCurve()); break; default: 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()); } return line;}void SCDiagram::UpdateNodeType(int num) { ((DiagramWindow *)GetMainWindow())->SetNodeName(num); switch (num) { case 1: SetNodeType(Code::SCD_OR_STATE); SetNodeShapeType(Code::ROUNDED_BOX); break; case 2: SetNodeType(Code::SCD_AND_STATE); SetNodeShapeType(Code::SCD_AND_STATE_BOX); break; case 3: SetNodeType(Code::SCD_DEFAULT_STATE); SetNodeShapeType(Code::BLACK_DOT); break; case 4: SetNodeType(Code::SCD_FINAL_STATE); SetNodeShapeType(Code::BULLS_EYE); break; case 5: SetNodeType(Code::COMMENT); SetNodeShapeType(Code::TEXT_BOX); break; case 6: SetNodeType(Code::SCD_DECISION_STATE); SetNodeShapeType(Code::MINI_DIAMOND); break; case 7: SetNodeType(Code::SCD_SYNCHRONIZATION_STATE); SetNodeShapeType(Code::SOLID_HORIZONTAL_BAR); break; case 8: SetNodeType(Code::SCD_SYNCHRONIZATION_STATE); SetNodeShapeType(Code::SOLID_VERTICAL_BAR); break; case 9: SetNodeType(Code::NOTE); SetNodeShapeType(Code::NOTE_BOX); break; default: error("%s, line %d: impl error: " "unknown node type selected\n", __FILE__,__LINE__); }}void SCDiagram::UpdateEdgeType(int num) { ((DiagramWindow *)GetMainWindow())->SetEdgeName(num); switch(num) { case 1: SetEdgeType(Code::SCD_TRANSITION_EDGE); SetLineType(Code::LINE); SetEdgeLineStyle(LineStyle::SOLID);// SetLineEnd1(LineEnd::EMPTY); SetLineEnd2(LineEnd::FILLED_ARROW); break; case 2: SetEdgeType(Code::COMMENT_LINK); SetLineType(Code::LINE); SetEdgeLineStyle(LineStyle::WIDE_DOTTED);// SetLineEnd1(LineEnd::EMPTY); SetLineEnd2(LineEnd::EMPTY); break; case 3: SetEdgeType(Code::SCD_AND_EDGE); SetLineType(Code::SCD_AND_LINE); SetEdgeLineStyle(LineStyle::DASHED);// SetLineEnd1(LineEnd::EMPTY); SetLineEnd2(LineEnd::EMPTY); break; default: error("%s, line %d: impl error: " "unknown edge type selected\n", __FILE__,__LINE__); }}bool SCDiagram::CheckAndEdgeConstraints(Subject *subj1, Subject *subj2) { if ( subj1->GetClassType() != Code::SCD_AND_STATE ) { ShowDialog(MessageDialog::ERROR, "Error", "An and-line must begin at an and-state"); return False; } if ( subj1 != subj2 ) { ShowDialog(MessageDialog::ERROR, "Error", "An and-line must begin and end at the same state"); return False; }// ----> Hier toevoegen: check that an and-edge lies inside its and-shape. return True;}bool SCDiagram::CheckEdgeConstraints(Subject *subj1, Subject *subj2) { // Check possible connections (subj-subj-edge matrix). if (!CheckConnection(subj1, subj2)) return False; return True;}//bool SCDiagram::SetEvent(Transition *t, const string *s) {// List<GShape *> shapes;// GetDiagramViewer()->GetShapes(t, &shapes);// Subject::NameErrType n = t->SetEvent(s);// if (n == Subject::OK) {// if (shapes.first())// do// ((TransitionArrow *)shapes.cur())->UpdateEvent(s);// while (shapes.next());// else {// error("%s, line %d: shape does not exist\n", // __FILE__, __LINE__);// return False;// }// return True;// }// else if (n == Subject::IMPOSSIBLE_NAME) {// string msg = "'" + *s + "' wrong syntax\n for an event string";// ShowDialog(MessageDialog::ERROR, "Error", &msg);// return False;// }// else if (n == Subject::DOUBLE_EDGE) {// string msg = "there is already a transition with\n"// "event string '" + *s + "' between this pair of states";// ShowDialog(MessageDialog::ERROR, "Error", &msg);// return False;// }// else {// error("%s, line %d: case not handled\n", __FILE__, __LINE__);// }// return True;//}//bool SCDiagram::SetAction(Subject *t, const string *s, unsigned nr) {// List<GShape *> shapes;// GetDiagramViewer()->GetShapes(t, &shapes);// unsigned m = nr;// // split string in different one line strings.// string ss(*s);// char *str = (char *)ss.getstr();// char empty[2] = "";// char *x = strtok(str, "\r");// if (x == 0)// x = empty;// while (x != 0) {// string *ns = new string(x);// bool update = True;// Subject::NameErrType result;// if (m == nr) {// if (t->IsEdge())// result = ((Transition *)t)->SetAction(ns, m, True);// else// result = ((InitialState *)t)->SetAction(ns, m, True);// }// else {// if (t->IsEdge())// result = ((Transition *)t)->SetAction(ns, m, False);// else// result = ((InitialState *)t)->SetAction(ns, m, False);// update = False;// }// if (result != Subject::OK) {// string msg;// if (result == Subject::HAS_ACTION)// msg = "transition already has an action '" + *ns + "'";// else// msg = "'" + *ns + "' wrong syntax\n for an action string";// ShowDialog(MessageDialog::ERROR, "Error", &msg);// // make actions empty.// *ns = "";// if (!update) {// for (shapes.first(); !shapes.done(); shapes.next()) {// if (t->IsEdge())// ((TransitionArrow *)shapes.cur())->// UpdateAction(ns, m, update);// else// ((InitialStateBox *)shapes.cur())->// UpdateAction(ns, m, update);// }// } // delete ns;// return False;// }// // update the shapes.// if (shapes.first())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -