⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainwindow.cc

📁 模糊聚类分析的源程序!
💻 CC
📖 第 1 页 / 共 2 页
字号:
//**************************************************************//*   filename: mainwindow.cc                                  *//*                                                            *//**************************************************************//* programmed by: Thomas Wagner                               *//* last change:  (XXX: not updated)                           *//**************************************************************#include <stdio.h>#include <stdlib.h>#include "mainwindow.h"#include "saveloadwindow.h"extern unsigned long buttonpix, whitepix, blackpix;extern unsigned long shadowpix, lightpix, selectpix;extern XContext Windowcontext;extern Cursor movestartcursor, moveendcursor, delconnectcursor;extern Cursor maincursor, waitcursor, createstartcursor;extern Cursor deleteiconcursor, diskcursor;MainWindow::MainWindow (Display * initdisplay,	    GC initgc,	    XFontStruct * initfontstruct,	    int initx, int inity,	    int initwidth, int initheight,	    char *text):BigWindow (initdisplay,	   initgc,	   DefaultRootWindow (initdisplay),	   initfontstruct,	   initx, inity, initwidth,	   initheight,	   text,	   DEFAULT_BDWIDTH){  XWMHints *p_xwmh;		/* Hints for the window manager  */  XSizeHints *p_xsh;		/* Size hints for window manager */  XClassHint *p_ch;		/* Class hint for window manager */  XSetWindowAttributes xswa;  XTextProperty blabla;  moveableiconlist = new MoveableIconlist ();  status = MAINNORMALSTATUS;  Done = FALSE;  if ((p_xwmh = XAllocWMHints ()) == NULL) {    printf ("Error allocating Window Manager hints!\n");    exit (1);  }  p_xwmh->flags = (InputHint | StateHint);  p_xwmh->input = False;	//True;  p_xwmh->initial_state = NormalState;  if ((p_xsh = XAllocSizeHints ()) == NULL) {    printf ("Error allocating size hints!\n");    exit (1);  }  p_xsh->flags = (PPosition | PSize | PMinSize);  p_xsh->width = p_xsh->min_width = width;  p_xsh->height = p_xsh->min_height = height;  p_xsh->x = x;  p_xsh->y = y;  if ((p_ch = XAllocClassHint ()) == NULL) {    printf ("Error allocating class hint!\n");    exit (1);  }  p_ch->res_name = text;  p_ch->res_class = "XHello";/* work around a bug in gcc v2.5.8 optimizer (copy text var): */  {    XTextProperty tp_dummy;    char *text_ptr = text;    XStringListToTextProperty (&text_ptr, 1, &tp_dummy);    XSetWMProperties (display, window, &tp_dummy, &tp_dummy, &text_ptr, 0,		      p_xsh, p_xwmh, p_ch);  }  xswa.colormap = DefaultColormap (display, DefaultScreen (display));  xswa.bit_gravity = CenterGravity;  XChangeWindowAttributes (display, window, (CWColormap | CWBitGravity),			   &xswa);  SetSelectedInput (ExposureMask		    | StructureNotifyMask		    | ButtonPressMask		    | ButtonReleaseMask		    | PointerMotionMask		    | ButtonMotionMask | FocusChangeMask    );  XDefineCursor (display, window, maincursor);  XSaveContext (display, window, Windowcontext, (caddr_t) this);  allconnections = new Connectlist ();  menu = new Menu (display, gc, this, fontstruct, 0, 0);  MenuIconInfo Actions[4] =  {    {"Connection & Co.", STATUS_DEFAULT, 1, 0},    {"new Connection", STATUS_DEFAULT, MAIN_CREATECONNECTION_ACTION, 0},    {"delete Connection", STATUS_DEFAULT, MAIN_DESTROYCONNECTION_ACTION, 0},    {"Quit", STATUS_DEFAULT, MAIN_QUIT_ACTION, 0}  };  menu->AddPulldownMenu (Actions, 4);  MenuIconInfo Input[4] =  {    {"Inputobject", STATUS_DEFAULT, 1, 0},    {"save Input", STATUS_DEFAULT, MAIN_SAVEINPUT_ACTION, 0},    {"load Input", STATUS_DEFAULT, MAIN_NEWINPUT_ACTION, 0},    {"delete Input", STATUS_DEFAULT, MAIN_DELETEINPUT_ACTION, 0}  };  menu->AddPulldownMenu (Input, 4);  MenuIconInfo Cluster[4] =  {    {"Clusterobject", STATUS_DEFAULT, 1, 0},    {"new Clusterobject", STATUS_DEFAULT, MAIN_CREATECLUSTERSELECTION_ACTION, 0},    {"delete Clusterobject", STATUS_DEFAULT, MAIN_DELETECLUSTER_ACTION, 0},    {"load Clusterobject", STATUS_DEFAULT, MAIN_LOADCLUSTER_OKACTION, 0}  };  menu->AddPulldownMenu (Cluster, 4);  MenuIconInfo Clustersub[5] =  {    {"FCM Clustering", STATUS_DEFAULT, MAIN_CREATECLUSTERSELECTION_ACTION, FCM},  {"GK Clustering", STATUS_DEFAULT, MAIN_CREATECLUSTERSELECTION_ACTION, GK},    {"GK parallel Clustering", STATUS_DEFAULT, MAIN_CREATECLUSTERSELECTION_ACTION, GK_parallel},  {"GG Clustering", STATUS_DEFAULT, MAIN_CREATECLUSTERSELECTION_ACTION, GG},    {"GG parallel Clustering", STATUS_DEFAULT, MAIN_CREATECLUSTERSELECTION_ACTION, GG_parallel}  };  menu->GetPulldownMenu (2)->GetMenuIcon (0)->    SetSonPulldownMenu (new PulldownMenu (display,					  gc,					  this,					  menu,					  fontstruct,					  50, 30,					  30,					  Clustersub, 5));  MenuIconInfo Rule[4] =  {    {"Ruleobject", STATUS_DEFAULT, 1, 0},    {"save Ruleobject", STATUS_DEFAULT, MAIN_SAVERULE_ACTION, 0},    {"load Ruleobject", STATUS_DEFAULT, MAIN_LOADRULE_ACTION, 0},    {"delete Ruleobject", STATUS_DEFAULT, MAIN_DELETERULE_ACTION, 0}  };  menu->AddPulldownMenu (Rule, 4);  MenuIconInfo Classify[4] =  {    {"Classifyobject", STATUS_DEFAULT, 1, 0},    {"save Classifyobject", STATUS_DEFAULT, MAIN_SAVECLASSIFY_ACTION, 0},    {"load Classifyobject", STATUS_DEFAULT, MAIN_LOADCLASSIFY_ACTION, 0},    {"delete Classifyobject", STATUS_DEFAULT, MAIN_DELETECLASSIFY_ACTION, 0}  };  menu->AddPulldownMenu (Classify, 4);  saveloadwindow = new SaveLoadWindow (display,				       gc,				       this,				       fontstruct,				       100, 100,				       MAIN_CREATEINPUT_OK,				       "LOAD INPUT",				       WORK_AS_LOAD_SELECTOR);  errorbox = new ErrorBox (display,			   gc,			   this,			   fontstruct,			   0, height - 17,			   350, 15);}MainWindow::~MainWindow (){  UnmapMe ();  delete menu;  delete saveloadwindow;  delete errorbox;  delete moveableiconlist;  delete allconnections;}void MainWindow::printError (char *newtext){  errorbox->ChangeText (newtext);  errorbox->MapMe ();  XBell (display, 100);}void MainWindow::HandleEventqueue (){  while (!Done) {    XEvent theEvent;		// Structure for current event    Window_Info *window_info;    XNextEvent (display, &theEvent);    if (! XFindContext (display, theEvent.xany.window, Windowcontext,		       (caddr_t *) & window_info)) {      window_info->HandleEvent (&theEvent);    }  }				// while (!Done)}void MainWindow::SetStatus (MAINSTATUS newstatus){  status = newstatus;  if (status == MAINNORMALSTATUS) {    menu->MakeSelectable ();    XDefineCursor (display, window, maincursor);  } else {    menu->MakeUnselectable ();  }  errorbox->UnmapMe ();}void MainWindow::Action (int actionnumber, int value){  switch (actionnumber) {  case MAIN_NEWINPUT_ACTION:    saveloadwindow->ChangeFunction (WORK_AS_LOAD_SELECTOR,				    this,				    MAIN_CREATEINPUT_OK,				    "LOAD INPUT");    saveloadwindow->MapMe ();    SetStatus (MAINLOADINPUTSTATUS);    break;  case MAIN_CREATEINPUT_OK:    {      if ((char *) value != NULL) {	Reset_Fehlerstatus ();	Datensatz tempdataset = File_einlesen ((char *) value);	SetStatus (MAINNORMALSTATUS);	if (Lese_Fehlerstatus () == KEINFEHLER) {	  InputIcon *temp = new InputIcon (display,					   gc,					   fontstruct,					   this,					   20, 70,				    MOVEABLEICON_WIDTH, MOVEABLEICON_HEIGHT,					   (char *) value);	  temp->GetOutput ()->SetDataset (&tempdataset);	  AddnewMoveableIcon (temp);	} else {	  switch (Lese_Fehlerstatus ()) {	  case DATEIFORMATFEHLER:	    printError ("Error in format of input-file!");	    break;	  default:	    break;	  }	  Reset_Fehlerstatus ();	}      } else {	SetStatus (MAINNORMALSTATUS);      }    }    break;  case MAIN_SAVEINPUT_ACTION:    SetStatus (MAINSAVEINPUTSTATUS);    XDefineCursor (display, window, diskcursor);    break;  case MAIN_SAVERULE_ACTION:    SetStatus (MAINSAVERULESTATUS);    XDefineCursor (display, window, diskcursor);    break;  case MAIN_LOADRULE_ACTION:    saveloadwindow->ChangeFunction (WORK_AS_LOAD_SELECTOR,				    this,				    MAIN_LOADRULE_OK,				    "LOAD RULE-OBJECT");    saveloadwindow->MapMe ();    SetStatus (MAINLOADRULESTATUS);    break;  case MAIN_LOADRULE_OK:    if ((char *) value != NULL) {      RuleInfo tempRuleinfo;      tempRuleinfo.datasetname = (char *) value;      Reset_Fehlerstatus ();      tempRuleinfo.rules = Regelbasis_einlesen ((char *) value);      SetStatus (MAINNORMALSTATUS);      if (Lese_Fehlerstatus () == KEINFEHLER) {	RuleIcon *temp = new RuleIcon (display,				       gc,				       fontstruct,				       this,				       20, 70,				    MOVEABLEICON_WIDTH, MOVEABLEICON_HEIGHT,				       (char *) value,				       &tempRuleinfo);	AddnewMoveableIcon (temp);      } else {	switch (Lese_Fehlerstatus ()) {	case DATEIFORMATFEHLER:	  printError ("Error in format of rule-file!");	  break;	default:	  break;	}	Reset_Fehlerstatus ();      }    } else {      SetStatus (MAINNORMALSTATUS);    }    break;  case MAIN_SAVECLASSIFY_ACTION:    SetStatus (MAINSAVECLASSIFYSTATUS);    XDefineCursor (display, window, diskcursor);    break;  case MAIN_LOADCLASSIFY_ACTION:    saveloadwindow->ChangeFunction (WORK_AS_LOAD_SELECTOR,				    this,				    MAIN_LOADCLASSIFY_OK,				    "LOAD CLASSIFY-OBJECT");    saveloadwindow->MapMe ();    SetStatus (MAINLOADCLASSIFYSTATUS);    break;  case MAIN_LOADCLASSIFY_OK:    if ((char *) value != NULL) {      RuleInfo tempRuleinfo;      tempRuleinfo.datasetname = (char *) value;      Reset_Fehlerstatus ();      tempRuleinfo.classify = Klassifizierung_einlesen ((char *) value);      SetStatus (MAINNORMALSTATUS);      if (Lese_Fehlerstatus () == KEINFEHLER) {	ClassifyIcon *temp = new ClassifyIcon (display,					       gc,					       fontstruct,					       this,					       20, 70,				    MOVEABLEICON_WIDTH, MOVEABLEICON_HEIGHT,					       (char *) value,					       &tempRuleinfo);	AddnewMoveableIcon (temp);//           temp->DrawMoveableIcon();      } else {	switch (Lese_Fehlerstatus ()) {	case DATEIFORMATFEHLER:	  printError ("Error in format of classify-file!");	  break;	default:	  break;	}	Reset_Fehlerstatus ();      }    } else {      SetStatus (MAINNORMALSTATUS);    }    break;  case MAIN_LOADCLUSTER_OKACTION:    saveloadwindow->ChangeFunction (WORK_AS_LOAD_SELECTOR,				    this,				    MAIN_LOADCLUSTER_OK,				    "LOAD CLUSTER-OBJECT");    saveloadwindow->MapMe ();    SetStatus (MAINLOADCLUSTERSTATUS);    break;  case MAIN_LOADCLUSTER_OK:    if ((char *) value != NULL) {      Reset_Fehlerstatus ();      Clustering *tempclustering = Clustering_Laden ((char *) value);      if (Lese_Fehlerstatus () == KEINFEHLER) {	ClusterIcon *temp = new ClusterIcon (display,					     gc,					     fontstruct,					     this,					     20, 70,				    MOVEABLEICON_WIDTH, MOVEABLEICON_HEIGHT,					     (char *) value,					     NULL);//                                       tempclustering);	AddnewMoveableIcon (temp);	temp->GetOutput ()->Action (OUTPUT_LOADOK, (int) tempclustering);	temp->DrawMoveableIcon ();      } else {	switch (Lese_Fehlerstatus ()) {	case DATEIFORMATFEHLER:	  printError ("Error in format of cluster-file!");	  break;	default:	  break;	}	Reset_Fehlerstatus ();      }    }    SetStatus (MAINNORMALSTATUS);    break;  case MAIN_MAPME_ACTION:    MapMe ();    break;  case MAIN_CREATERULE_ACTION:    {      RuleIcon *temp = new RuleIcon (display,				     gc,				     fontstruct,				     this,				     20, 70,				     MOVEABLEICON_WIDTH, MOVEABLEICON_HEIGHT,				     ((RuleInfo *) value)->datasetname,				     (RuleInfo *) value);      AddnewMoveableIcon (temp);    }    break;  case MAIN_CREATECLASSIFY_ACTION:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -