📄 mainwindow.cc
字号:
{ ClassifyIcon *temp = new ClassifyIcon (display, gc, fontstruct, this, 20, 70, MOVEABLEICON_WIDTH, MOVEABLEICON_HEIGHT, ((RuleInfo *) value)->datasetname, (RuleInfo *) value); AddnewMoveableIcon (temp); } break; case MAIN_CREATECLUSTERSELECTION_ACTION: { ClusterInfo cinfo (NULL, 0, value, MAXINT, MAXINT, 2, 1, 0, DEFAULT_DELTA_U, S, NULL); ClusterOptionWindow *clusteroptionwindow = new ClusterOptionWindow (display, gc, this, fontstruct, 20, 20, "Create Cluster-Object", MAIN_CREATECLUSTERING_OK, &cinfo); clusteroptionwindow->MapMe (); SetStatus (MAINNEWCLUSTERINGSTATUS); } break; case MAIN_DELETECLUSTER_ACTION: SetStatus (MAINDELETECLUSTERINGSTATUS); XDefineCursor (display, window, deleteiconcursor); break; case MAIN_DELETECLASSIFY_ACTION: SetStatus (MAINDELETECLASSIFYSTATUS); XDefineCursor (display, window, deleteiconcursor); break; case MAIN_DELETEINPUT_ACTION: SetStatus (MAINDELETEINPUTSTATUS); XDefineCursor (display, window, deleteiconcursor); break; case MAIN_DELETERULE_ACTION: SetStatus (MAINDELETERULESTATUS); XDefineCursor (display, window, deleteiconcursor); break; case MAIN_CREATECLUSTERING_OK: if ((ClusterInfo *) value != NULL) { ClusterIcon *temp = new ClusterIcon (display, gc, fontstruct, this, 20, 70, MOVEABLEICON_WIDTH, MOVEABLEICON_HEIGHT, "unplugged", (ClusterInfo *) value);// NULL); AddnewMoveableIcon (temp); } SetStatus (MAINNORMALSTATUS); break; case MAIN_CREATECONNECTION_ACTION: XDefineCursor (display, window, createstartcursor); SetStatus (MAINSTARTCONNECTSTATUS); break; case MAIN_QUIT_ACTION: { Dialog *dialog = new Dialog (display, gc, this, fontstruct, 10, 10, 200, 80, "Do you really want to quit!", DISPLAY_YES | DISPLAY_NO, MAIN_QUIT_DIALOG_FINISHED_ACTION); SetStatus (MAINQUITREQUESTSTATUS); dialog->MapMe (); } break; case MAIN_QUIT_DIALOG_FINISHED_ACTION: if (value == DIALOG_YES_ACTION) Done = TRUE; SetStatus (MAINNORMALSTATUS); break; case MAIN_DESTROYCONNECTION_ACTION: if (allconnections->GetConnection () != NULL) { SetStatus (MAINDESTROYCONNECTSTATUS); XDefineCursor (display, window, delconnectcursor); } break; default: printf ("MainWindow::Action: don't know action: %d\n", actionnumber); }}void MainWindow::DelMoveableIcon (MoveableIcon * Icon){ *moveableiconlist -= Icon; XClearWindow (display, window); allconnections->DrawAllArrow ();}void MainWindow::AddnewMoveableIcon (MoveableIcon * NewIcon){ short minarea = MAXSHORT; short xcounter = 0, ycounter = 0, xpos = 0, ypos = 0; short bestxpos = 0, bestypos = MAIN_TOP_SPACE; short xrepeats = width / (NewIcon->Getwidth () + 2 * DEFAULT_BDWIDTH); short yrepeats = (height - MAIN_TOP_SPACE) / (NewIcon->Getheight () + 2 * DEFAULT_BDWIDTH); MoveableIconlist *temp; // first find a good position for new icon while (ycounter < yrepeats) { xcounter = 0; while (xcounter < xrepeats) { short area = 0; temp = moveableiconlist; while (temp != NULL) { xpos = xcounter * (NewIcon->Getwidth () + 2 * DEFAULT_BDWIDTH); ypos = ycounter * (NewIcon->Getheight () + 2 * DEFAULT_BDWIDTH) + MAIN_TOP_SPACE; NewIcon->PlaceMe (xpos, ypos); MoveableIcon *icon = temp->GetIcon (); short cutwide, cutheight; if (icon != NULL) { cutwide = 0; cutheight = 0; // calculate wide of cut { MoveableIcon *left, *right; if (NewIcon->Getx () < icon->Getx ()) { left = NewIcon; right = icon; } else { right = NewIcon; left = icon; } if ((left->Getx () + left->Getwidth ()) > right->Getx ()) { // cut != 0 if ((right->Getx () + right->Getwidth ()) < (left->Getx () + left->Getwidth ())) { // right(-icon) in left(-icon) cutwide = right->Getwidth (); } else { cutwide = left->Getx () + left->Getwidth () - right->Getx (); } } } // calculate height of cut { MoveableIcon *higher, *lower; if (NewIcon->Gety () < icon->Gety ()) { higher = NewIcon; lower = icon; } else { lower = NewIcon; higher = icon; } if ((higher->Gety () + higher->Getheight ()) > lower->Gety ()) { // cut != 0 if ((lower->Gety () + lower->Getheight ()) < (higher->Gety () + higher->Getheight ())) { // lower(-icon) in higher(-icon) cutheight = lower->Getheight (); } else { cutheight = higher->Gety () + higher->Getheight () - lower->Gety (); } } } area = MAX (area, cutwide * cutheight); } // if(icon!=NULL) temp = temp->Getnext (); } if (area == 0) // found one of the best positions { bestxpos = xpos; bestypos = ypos; ycounter = yrepeats; xcounter = xrepeats; } else { // found a better position, but cutarea != 0 if (area < minarea) { bestxpos = xpos; bestypos = ypos; minarea = area; } } // if(area==0) xcounter++; } ycounter++; } // now find the index, display in ruleicon if (NewIcon->GetTyp () == MOVEABLEICONTYP_RULE) { temp = moveableiconlist; short maxindex = 0; while (temp != NULL) { MoveableIcon *icon = temp->GetIcon (); if (icon != NULL) { if (icon->GetTyp () == MOVEABLEICONTYP_RULE) { if (((RuleIcon *) icon)->GetIndex () != 0) maxindex = MAX (((RuleIcon *) icon)->GetIndex (), maxindex); } } temp = temp->Getnext (); } ((RuleIcon *) NewIcon)->SetIndex (maxindex + 1); } // now find the index, display in classifyicon if (NewIcon->GetTyp () == MOVEABLEICONTYP_CLASSIFY) { temp = moveableiconlist; short maxindex = 0; while (temp != NULL) { MoveableIcon *icon = temp->GetIcon (); if (icon != NULL) { if (icon->GetTyp () == MOVEABLEICONTYP_CLASSIFY) { if (((ClassifyIcon *) icon)->GetIndex () != 0) maxindex = MAX (((ClassifyIcon *) icon)->GetIndex (), maxindex); } } temp = temp->Getnext (); } ((ClassifyIcon *) NewIcon)->SetIndex (maxindex + 1); } // final add new icon to list *moveableiconlist += NewIcon; NewIcon->PlaceMe (bestxpos, bestypos); NewIcon->MapMe ();}void MainWindow::HandleEvent (XEvent * Event){ switch (Event->type) { case Expose: XSetForeground (display, gc, buttonpix); XFillRectangle (display, window, gc, Event->xgraphicsexpose.x, Event->xgraphicsexpose.y, Event->xgraphicsexpose.width, Event->xgraphicsexpose.height); if (Event->xexpose.count == 0) allconnections->DrawAllArrow (); break; case ConfigureNotify: if ((Event->xconfigure.width != width) || (Event->xconfigure.height != height)) { errorbox->MoveMe (0, Event->xconfigure.height - height); width = Event->xconfigure.width; height = Event->xconfigure.height; XResizeWindow (display, window, width, height); XSetForeground (display, gc, buttonpix); XFillRectangle (display, window, gc, 0, 0, width, height); } if (Event->xconfigure.x != x) x = Event->xconfigure.x; if (Event->xconfigure.y != y) y = Event->xconfigure.y; break; case ButtonPress: switch (Event->xbutton.button) { case Button1: int xpos, ypos; switch (status) { case MAINDESTROYCONNECTSTATUS: // destroy connector Connection * nearest; xpos = Event->xbutton.x; ypos = Event->xbutton.y; nearest = allconnections->FindnearestConnection (xpos, ypos); nearest->GetStartIcon ()->Action (ICON_REMOVECONNECTOUT, (int) nearest); nearest->GetEndIcon ()->Action (ICON_REMOVECONNECTIN, 0); delete nearest; XDefineCursor (display, window, maincursor); SetStatus (MAINNORMALSTATUS); XClearWindow (display, window); allconnections->DrawAllArrow (); break; // case MAINDESTROYCONNECTSTATUS: case MAINNORMALSTATUS: char pointtyp; if (allconnections->GetConnection () != NULL) { xpos = Event->xbutton.x; ypos = Event->xbutton.y; acuteconnection = allconnections->FindnearestConnection (xpos, ypos, &pointtyp); if (pointtyp == STARTPOINT) { XDefineCursor (display, window, movestartcursor); acuteconnection->SetStart (xpos, ypos); SetStatus (MAINMOVECONNECTSTARTSTATUS); } else { XDefineCursor (display, window, moveendcursor); acuteconnection->SetEnd (xpos, ypos); SetStatus (MAINMOVECONNECTENDSTATUS); } acuteconnection->SetStatus (CONNECTSTATUS_INVISIBLE); XClearWindow (display, window); allconnections->DrawAllArrow (); acuteconnection->DrawtempArrow (); } break; // case MAINNORMALSTATUS: default: break; } break; // case Button1 case Button3: switch (status) { case MAINSAVEINPUTSTATUS: case MAINSAVECLASSIFYSTATUS: case MAINSAVERULESTATUS: case MAINDELETECLUSTERINGSTATUS: case MAINDELETECLASSIFYSTATUS: case MAINDELETEINPUTSTATUS: case MAINDELETERULESTATUS: SetStatus (MAINNORMALSTATUS); break; case MAINDESTROYCONNECTSTATUS: SetStatus (MAINNORMALSTATUS); break; case MAINSTARTCONNECTSTATUS: // stop creating connection SetStatus (MAINNORMALSTATUS); break; case MAINENDCONNECTSTATUS: // or delete start-point of connection acuteconnection->ErasetempArrow (); *(acuteconnection->GetStartIcon ()->GetOutputConnectlist ()) -= acuteconnection; delete acuteconnection; SetStatus (MAINNORMALSTATUS); break; case MAINMOVECONNECTSTARTSTATUS: acuteconnection->ErasetempArrow (); acuteconnection->SetStart (acuteconnection->GetStartIcon ()->x + (int) (acuteconnection->GetStartIcon ()->width / 2), acuteconnection->GetStartIcon ()->y + (int) (acuteconnection->GetStartIcon ()->height / 2)); acuteconnection->SetStatus (CONNECTSTATUS_VISIBLE); acuteconnection->DrawArrow (); SetStatus (MAINNORMALSTATUS); break; case MAINMOVECONNECTENDSTATUS: acuteconnection->ErasetempArrow (); acuteconnection->SetEnd (acuteconnection->GetEndIcon ()->x + (int) (acuteconnection->GetEndIcon ()->width / 2), acuteconnection->GetEndIcon ()->y + (int) (acuteconnection->GetEndIcon ()->height / 2)); acuteconnection->SetStatus (CONNECTSTATUS_VISIBLE); acuteconnection->DrawArrow (); SetStatus (MAINNORMALSTATUS); break; default: break; } XDefineCursor (display, window, maincursor); break; // case Button3 } break; // case ButtonPress: case ButtonRelease: switch (Event->xbutton.button) { case Button1: break; // case Button1 } break; // case ButtonRelease case MotionNotify: switch (status) { int xpos, ypos; case MAINENDCONNECTSTATUS: xpos = Event->xmotion.x; ypos = Event->xmotion.y; acuteconnection->ErasetempArrow (); acuteconnection->DrawtempArrow (xpos, ypos); break; // case MAINENDCONNECTSTATUS case MAINMOVECONNECTSTARTSTATUS: xpos = Event->xmotion.x; ypos = Event->xmotion.y; acuteconnection->ErasetempArrow (); acuteconnection->SetStart (xpos, ypos); acuteconnection->DrawtempArrow (); break; // case MAINMOVECONNECTSTARTSTATUS case MAINMOVECONNECTENDSTATUS: xpos = Event->xmotion.x; ypos = Event->xmotion.y; acuteconnection->ErasetempArrow (); acuteconnection->SetEnd (xpos, ypos); acuteconnection->DrawtempArrow (); break; // case MAINMOVECONNECTENDSTATUS default: break; } break; // switch(status) }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -