/*****************************************************************************
  FUNCTION : ui_displMap

  PURPOSE  : Main program to display the MAPs of the network
  NOTES    : Initializes widgets and switches for color or b&w terminal
  RETURNS  : 
  UPDATE   : 22.09.94
******************************************************************************/
void ui_displMap(Widget w, caddr_t call_data)
{
    Widget donebutton,setbutton,framewidget,zoomin,zoomout;
    int maxstepX,maxstepY;
    Arg		   args[25];   
    Cardinal	   n = 0;
    char           buf[40];
  
    /* do nothing, if no network is defined */
    if( (krui_getNoOfUnits()) == 0){
	ui_confirmOk("No network loaded !");
	return;
    }
  

    /* If a MAP window already exists, just put it on top */

    if(MAP_WINDOW_created == 1){
	XRaiseWindow (XtDisplay (MAP_GRAPH_mainwidget), 
		      XtWindow (MAP_GRAPH_mainwidget));
	return;
    }
  

    /* Create all necessary widgets */

    n = 0;
    sprintf(buf," SNNS Unit Projection\n");
    MAP_GRAPH_mainwidget = 
	XtCreatePopupShell(buf,topLevelShellWidgetClass,ui_toplevel,args,n);
    n = 0;
    framewidget = XtCreateManagedWidget("form",formWidgetClass,
					MAP_GRAPH_mainwidget,args,n);
    donebutton  = ui_xCreateButtonItem("done", framewidget, NULL, NULL);

    zoomin = ui_xCreateButtonItem("zoomin",framewidget,NULL,donebutton);
    setbutton = ui_xCreateButtonItem("setup",framewidget,zoomin,NULL);
    zoomout = ui_xCreateButtonItem("zoomout",framewidget,zoomin,donebutton);
    n = 0;
    XtSetArg(args[n], XtNx, 0);n++;
    XtSetArg(args[n], XtNy, 0);n++;
    XtSetArg(args[n], XtNwidth, 210); n++;
    XtSetArg(args[n], XtNheight, 25); n++;
    XtSetArg(args[n], XtNinternalHeight, 1); n++;
    XtSetArg(args[n], XtNinternalWidth , 1); n++;
    XtSetArg(args[n], XtNborderWidth,  0); n++;
    XtSetArg(args[n], XtNhorizDistance, 30);      n++;
    XtSetArg(args[n], XtNfromHoriz, setbutton);      n++;
    XtSetArg(args[n], XtNfromVert, NULL); n++;
    XtSetArg(args[n], XtNleft  , XtChainLeft);  n++;
    XtSetArg(args[n], XtNright , XtChainLeft); n++;
    XtSetArg(args[n], XtNtop   , XtChainTop);   n++;
    XtSetArg(args[n], XtNbottom, XtChainTop);n++;
    scale = XtCreateManagedWidget("Label",formWidgetClass,framewidget,args,n);
  
    n = 0;
    XtSetArg(args[n], XtNx, 0);n++;
    XtSetArg(args[n], XtNy, 0);n++;
    XtSetArg(args[n], XtNborderWidth,  1); n++;
    XtSetArg(args[n], XtNwidth,  MAP_windowsizeX+62); n++;
    XtSetArg(args[n], XtNheight, MAP_windowsizeY+62); n++;
    XtSetArg(args[n], XtNallowHoriz, TRUE);n++;
    XtSetArg(args[n], XtNallowVert, TRUE);n++;
    XtSetArg(args[n], XtNforceBars, TRUE);n++;
    XtSetArg(args[n], XtNfromHoriz, NULL);      n++;
    XtSetArg(args[n], XtNfromVert, zoomin); n++;
    XtSetArg(args[n], XtNvertDistance, 10); n++;
    XtSetArg(args[n], XtNleft  , XtChainLeft);  n++;
    XtSetArg(args[n], XtNright , XtChainRight); n++;
    XtSetArg(args[n], XtNtop   , XtChainTop);   n++;
    XtSetArg(args[n], XtNbottom, XtChainBottom);n++;
    view = XtCreateManagedWidget("view",viewportWidgetClass,framewidget,args,n);
    MAP_GRAPH_displaywidget =
	ui_createMyScreen("screen",view,MAP_windowsizeX,MAP_windowsizeY,
			  NULL,scale);
    MAP_WINDOW_created = 1;
  
  
    /* define the routines to be called for widget events */

    XtAddCallback(donebutton, XtNcallback,
		  (XtCallbackProc)ui_map_close,MAP_GRAPH_mainwidget);
    XtAddCallback(setbutton, XtNcallback,(XtCallbackProc)ui_map_setup,NULL);
    XtAddCallback(zoomin, XtNcallback,(XtCallbackProc)ui_map_zoom_in,NULL);
    XtAddCallback(zoomout, XtNcallback,(XtCallbackProc)ui_map_zoom_out,NULL);
    XtAddEventHandler(MAP_GRAPH_displaywidget, 
		      StructureNotifyMask | ExposureMask, GraphicsExpose,
		      (XtEventHandler) ui_map_event,ui_display);
    XtAddEventHandler(framewidget,KeyPressMask,FALSE,
		      (XtEventHandler)ui_key_control,(Cardinal *) 0);
  

    /* set the maximum size of each square and the size of the whole window */
    maxstepX = (int)((float)(MAP_xMax - MAP_xMin)/ MAP_scaleX);
    maxstepY = (int)((float)(MAP_yMax - MAP_yMin)/ MAP_scaleY);

    if(ui_col_monochromeMode){
	/* B&W terminal => variable square size needed */
	MAP_squaresizeX = (maxstepX > MAP_viewsizeX/MAP_BW_squaresizeX)? 
                           MAP_BW_squaresizeX: 
  	                   (int)((float)MAP_viewsizeX/(float)maxstepX);
	MAP_windowsizeX = MAP_squaresizeX*maxstepX+40;
	MAP_squaresizeY = (maxstepY > MAP_viewsizeY/MAP_BW_squaresizeY)? 
                           MAP_BW_squaresizeY: 
  	                   (int)((float)MAP_viewsizeY/(float)maxstepY);
	MAP_windowsizeX = MAP_squaresizeX*maxstepX+40;
    }else{
	/* color terminal => fixed square size */
	MAP_squaresizeX = 
	    ( maxstepX > MAP_viewsizeX/5)?5:(int)(MAP_viewsizeX/maxstepX);
	MAP_squaresizeY = 
	    ( maxstepY > MAP_viewsizeY/5)?5:(int)(MAP_viewsizeY/maxstepY);
	MAP_windowsizeX = MAP_squaresizeX*maxstepX+40;
	MAP_windowsizeY = MAP_squaresizeY*maxstepY+40;
    }
  
    /* Realize the window */
    XtPopup(MAP_GRAPH_mainwidget, XtGrabNone);
  
    MAP_GRAPH_screen = DefaultScreen(ui_display);
    MAP_GRAPH_win    = XtWindow(MAP_GRAPH_displaywidget);
}
Esempio n. 2
0
/******************************************************************************
*   MAIN function
******************************************************************************/
int main ( int argc, char **argv )
{
    trace_main = TRACE_MAIN;

    XtAppContext app;
    m_init();
    XtSetLanguageProc (NULL, NULL, NULL);
    XawInitializeWidgetSet();

    /*  --  Intialize Toolkit creating the application shell
     */
    Widget appShell = XtOpenApplication (&app, APP_NAME,
             /* resources: can be set from argv */
             options, XtNumber(options),
	     &argc, argv,
	     fallback_resources,
	     sessionShellWidgetClass,
	     NULL, 0
	   );
    load_icon(XtDisplay(appShell));
    //    load_icon_default();

    /*  --  Enable Editres support
     */
    XtAddEventHandler(appShell, (EventMask) 0, True, _XEditResCheckMessages, NULL);

    XtAddCallback( appShell, XtNdieCallback, quit_cb, NULL );

    /*  --  not parsed options are removed by XtOpenApplication
            the only entry left should be the program name
    */
    if (argc != 1) { m_destruct(); syntax(); exit(1); }
    TopLevel = appShell;


    /*  --  Register all application specific
            callbacks and widget classes
    */
    RegisterApplication ( appShell );

    /*  --  Register all Athena and Public
            widget classes, CBs, ACTs
    */
    XpRegisterAll ( app );

    /*  --  Create widget tree below toplevel shell
            using Xrm database
    */
    WcWidgetCreation ( appShell );


    /*  -- Get application resources and widget ptrs
     */
    XtGetApplicationResources(	appShell, (XtPointer)&CWNET,
				CWNET_CONFIG_RES,
				XtNumber(CWNET_CONFIG_RES),
				(ArgList)0, 0 );

    InitializeApplication(appShell);

    /*  --  Realize the widget tree and enter
            the main application loop  */
    XtRealizeWidget ( appShell );
    /*  --  Set Icon for Window */
    set_app_icon(appShell);

    grab_window_quit( appShell );


    /*------------------------------------------------------------------------*/
    CWNET.lgfx = lgfx_init( CWNET.widget_draw1 );

    /* init commands */
    cp_init();
    cp_add( "PUT:", cmd_put );
    cp_add( "EXIT", cmd_exit );
    cp_add( "CIRCLE:", cmd_circle );
    cp_add( "CLRSCR", cmd_clrscr );
    cp_add( "RECT:", cmd_rect );
    cp_add( "MEASURE", cmd_measure );
    int sln = sln_init();
    CWNET.sln = sln;
    XtAppAddTimeOut(app , 1000, try_connect, (XtPointer) (intptr_t) sln );
    /*------------------------------------------------------------------------*/

    
    XtAppMainLoop ( app ); /* use XtAppSetExitFlag */
    XtDestroyWidget(appShell);

    sln_destruct();
    m_destruct();

    return EXIT_SUCCESS;
}