home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / editors / eedraw / src / ed / eelayer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-23  |  13.2 KB  |  594 lines

  1. /* Set up the basic primitives for Layer control */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "\usr\include\intr_lib.h"
  6. /* #include "\usr\include\intr_gr.h" */
  7. #include "program.h"
  8. #include "eelayer.h"
  9.  
  10.  
  11. #define MAX_LAYERS 44
  12. #define LAYER_OFF 0
  13. #define LAYER_ON  1
  14. #define LAYER_ENABLED 2
  15. #define LAYER_UNUSED  4
  16.  
  17. #define BLACK        0
  18. #define RED        4
  19. #define GREEN        2
  20. #define BLUE        1
  21. #define YELLOW        14
  22. #define CYAN        3
  23. #define MAGENTA        5
  24. #define WHITE        15
  25.  
  26.  
  27. static char *UsedLayers[] ={
  28.     "Wire",
  29.     "Bus",
  30.     "Gate",
  31.     "IEEE",
  32.     "PinFun",
  33.     "PinNum",
  34.     "PinNam",
  35.     "RefDes",
  36.     "Attr",
  37.     "Device",
  38.     "Notes",
  39.     "NetNam",
  40.     "Pin",
  41.     "END"
  42. };
  43. static int LayerInfo[] ={
  44.      WHITE,0x8200,
  45.      YELLOW,0x0100,
  46.      CYAN,0x0100,
  47.      RED,0x0100, 
  48.      BLUE,0x0100, 
  49.      YELLOW,0x0100, 
  50.      BLUE,0x0100, 
  51.      YELLOW,0x0100, 
  52.      YELLOW,0x0100, 
  53.      CYAN,0x0100, 
  54.      BLUE,0x0100, 
  55.      RED,0x0100,
  56.      WHITE,0x0100
  57. };
  58. static int ColorSet[47];
  59. static int BaseColorMap[8] ={
  60.     WHITE,BLACK,RED,GREEN,BLUE,YELLOW,CYAN,MAGENTA
  61. };
  62. char ShowData[47][20];
  63.  
  64. void SetColorSet()
  65. {
  66.     int pt = 0;
  67.     ColorSet[pt] = BaseColorMap[EELayerWire];
  68.     pt++;
  69.     ColorSet[pt] = BaseColorMap[EELayerBus];
  70.     pt++;
  71.     ColorSet[pt] = BaseColorMap[EELayerGate];
  72.     pt++;
  73.     ColorSet[pt] = BaseColorMap[EELayerIEEE];
  74.     pt++;
  75.     ColorSet[pt] = BaseColorMap[EELayerPinFun];
  76.     pt++;
  77.     ColorSet[pt] = BaseColorMap[EELayerPinNum];
  78.     pt++;
  79.     ColorSet[pt] = BaseColorMap[EELayerPinNam];
  80.     pt++;
  81.     ColorSet[pt] = BaseColorMap[EELayerRefDes];
  82.     pt++;
  83.     ColorSet[pt] = BaseColorMap[EELayerAttr];
  84.     pt++;
  85.     ColorSet[pt] = BaseColorMap[EELayerDevice];
  86.     pt++;
  87.     ColorSet[pt] = BaseColorMap[EELayerNotes];
  88.     pt++;
  89.     ColorSet[pt] = BaseColorMap[EELayerNetNam];
  90.     pt++;
  91.     ColorSet[pt] = BaseColorMap[EELayerPin];
  92.     pt++;
  93.     while(pt!=46)
  94.         ColorSet[pt++]=BLACK;
  95. }
  96. void SeedLayers(Window)
  97. EEWindowStruct *Window;
  98. {
  99.     int pt;
  100.     
  101.     Window->Layer = (LayerStruct *) MyMalloc(sizeof(LayerStruct));
  102.     Window->Layer->CommonColor = WHITE;
  103.     Window->Layer->Flags = 0;
  104.     pt=0;
  105.     Window->Layer->CurrentWidth = 1;
  106. /* seed Up the Layer Strings and colours, set all user layers off */
  107.     while((strcmp(UsedLayers[pt],"END"))!=0){
  108.         /* set layer name up */
  109.      
  110.         strcpy(Window->Layer->LayerNames[pt],UsedLayers[pt]);
  111.         Window->Layer->LayerStatus[pt]=
  112.              (LayerInfo[(pt * 2) +1] & 0x0f00)/0x100;
  113.      
  114.         Window->Layer->LayerColor[pt] = ColorSet[pt];
  115.         if(LayerInfo[(pt * 2) +1] & 0x8200)
  116.             Window->Layer->CurrentLayer=pt;
  117.      
  118.         pt++;
  119.     }
  120.      
  121.     Window->Layer->NumberOfLayers=pt-1;
  122.     while(pt!=MAX_LAYERS){
  123.         sprintf(Window->Layer->LayerNames[pt],"User%d",pt);
  124.  
  125.         
  126.         Window->Layer->LayerStatus[pt] = LAYER_UNUSED;
  127.                             /* layers clear */
  128.                             /* and Off */
  129.         Window->Layer->LayerColor[pt] = INTR_COLOR_BLACK;
  130.         /* Colours Black */ 
  131.         pt++;
  132.     }
  133.     sprintf(Window->StatusL,"%8s",
  134.         Window->Layer->LayerNames[Window->Layer->CurrentLayer]); 
  135.      
  136. }
  137. /*****************************************************************************
  138. * Routine to Display Layer window drawing.                     *
  139. *****************************************************************************/
  140.  
  141. void ShowLayers()
  142. {
  143.     int pt;
  144.     
  145.     char LayerMode[0x10];
  146.  
  147.     /* basic code to display the Layer data to user */
  148.     
  149.  
  150.     
  151.     pt=0;
  152.     sprintf(ShowData[0],"       Quit");
  153.     sprintf(ShowData[1],"  New Layer");
  154.     while(pt!= ReturnLayerNumber() +1 ){
  155.         
  156.     switch(ReturnLayerMode(pt)){
  157.         case LAYER_OFF :
  158.             sprintf(LayerMode,"Off");
  159.             break;
  160.         case LAYER_ON :
  161.             sprintf(LayerMode,"On");
  162.             break;
  163.         case LAYER_ENABLED :
  164.             sprintf(LayerMode,"Use");
  165.             break;
  166.         case LAYER_UNUSED :
  167.             sprintf(LayerMode,"N/A");
  168.             break;
  169.     }
  170.  
  171.     if(pt == ReturnCurrentLayer())
  172.         sprintf(ShowData[pt+2],"%8s %4s A",
  173.             ReturnLayerName(pt),LayerMode);
  174.     else
  175.         sprintf(ShowData[pt+2],"%8s %4s  ",
  176.             ReturnLayerName(pt),LayerMode);
  177.      pt++;
  178.  
  179.  
  180.     }
  181. }
  182.  
  183. /* Start of routines to change the Layer Setups, commands will be    */
  184. /* AddNewLayer    -    Add another usable layer to the list, (User)    */
  185. /* ChangeLayerMode    -    Change the Display Mode of a Layer    */
  186. /* ChangeLayerColor    -    Change the drawing colour of a Layer    */
  187. /* ChangeLayername    -    Change a defined LayerName, Watch for    */
  188. /*            Silly changes in the default names!        */
  189. /* QUIT        -    Quit back to draw mode from Layer Control    */
  190.  
  191. static     char    *Layerstr[] ={
  192.     "Change Name      ",
  193.     "Change Mode      ",
  194.     "Change Colour    ",
  195.     "Set Active Layer ", 
  196. };
  197. static char *LayerColor[] ={
  198.     "Black",
  199.     "Red",
  200.     "Green",
  201.     "Blue",
  202.     "Yellow",
  203.     "Cyan",
  204.     "Magenta         ",
  205.     "White"
  206. };
  207. static char *LayerMode[] ={
  208.     "Off",
  209.     "On",
  210.     "Use",
  211.     "Use and Active       "
  212. };
  213. static int LayerColorData[] ={
  214.     BLACK,
  215.     RED,
  216.     GREEN,
  217.     BLUE,
  218.     YELLOW,
  219.     CYAN,
  220.     MAGENTA,
  221.     WHITE
  222. };
  223.  
  224. #define LAYER_MENU_SIZE (sizeof(Layerstr) / sizeof(char *))
  225. #define COLOR_MENU_SIZE (sizeof(LayerColor) / sizeof(char *))
  226. #define MODE_MENU_SIZE (sizeof(LayerMode) / sizeof(char *))
  227. static IntrPopUpMenuStruct *LayerPopUpMenu;
  228. static IntrPopUpMenuStruct *ColorPopUpMenu;
  229. static IntrPopUpMenuStruct *ModePopUpMenu;
  230. static IntrCursorShapeStruct Cursor;
  231.  
  232. int SetLayer()
  233.  
  234. {
  235.     int PopPosition;
  236.     int Layer,LayerData;
  237.     char Line[LINE_LEN_SHORT];
  238.     
  239.     Line[0]=NULL;
  240.  
  241.     Cursor.CursorType = INTR_CURSOR_ARROW;
  242.     ShowLayers();    /* seed up start data */
  243.     while((Layer=SetLayerList())!=-1){
  244.     if(Layer==0)
  245.         return(0);
  246.     else if(Layer==1){    /* New Layer Needed */
  247.          NewLayer();
  248.     }
  249.     else {
  250.         Layer=Layer-2;
  251.         if (LayerPopUpMenu == NULL) {
  252.             LayerPopUpMenu =
  253.                 IntrPopUpMenuCreate("Change Layer Data", (char **) Layerstr,
  254.                             0, LAYER_MENU_SIZE, EEPopUpFrameColor,
  255.                                   EEPopUpBackColor, EEPopUpForeColor,
  256.                                 EEPopUpXorColor, EEWindowsFrameWidth, &Cursor);
  257.            }
  258.  
  259.             PopPosition=INTR_WNDW_PLACE_RIGHT;
  260.             IntrPopUpMenu(LayerPopUpMenu, PopPosition);
  261.                
  262.         switch (LayerPopUpMenu -> SelectedIndex) {
  263.             case 0 :    /* Change Layer Name */
  264.                  
  265.  
  266.                 
  267.                     if(Layer==-1 || 
  268.                         Layer > ReturnLayerNumber()){
  269.                         /* Error */
  270.                         GRTone(1500,100);
  271.                         GRTone(500,200);
  272.                         break;
  273.                     }
  274.                 strcpy(Line,ReturnLayerName(Layer));
  275.                 IntrQueryLine("Enter New Layer Name:", Line,
  276.                     LINE_LEN_SHORT -1, EEPopUpFrameColor,
  277.                     EEPopUpBackColor,EEPopUpForeColor,
  278.                     EEWindowsFrameWidth,PopPosition);
  279.                 SetLayerName(Layer,Line);
  280.                     break;
  281.             case 1 :    /* Change Layer Mode */
  282.                  
  283.  
  284.                 
  285.                      if(Layer==-1 || 
  286.                         Layer > ReturnLayerNumber()){
  287.                         /* Error */
  288.                         GRTone(1500,100);
  289.                         GRTone(500,200);
  290.                         break;
  291.                     }
  292.                      LayerData=SetMode();
  293.                     if(LayerData==-1)
  294.                         break;
  295.                     if(LayerData == 3){
  296.                         LayerPointer->CurrentLayer =
  297.                             Layer;
  298.                         LayerData=2;
  299.                     }
  300.                     if((Layer==LayerPointer->CurrentLayer) &
  301.                         (LayerData!=2))
  302.         LayerPointer->CurrentLayer = ReturnNextUsableLayer(Layer);
  303.                     SetLayerMode(Layer,LayerData);
  304.                     break;
  305.             case 2 :    /* Change Layer Color */
  306.                  
  307.  
  308.             
  309.  
  310.                      if(Layer==-1 || 
  311.                         Layer > ReturnLayerNumber()){
  312.                         /* Error */
  313.                         GRTone(1500,100);
  314.                         GRTone(500,200);
  315.                         break;
  316.                     }
  317.                     LayerData=SetColor();
  318.                     if(LayerData==-1)
  319.                         break;
  320.                     SetLayerColor(Layer,LayerData);
  321.                     break;
  322.             case 3 :
  323.         
  324.  
  325.  
  326.                     if(Layer==-1 ||
  327.                         Layer > ReturnLayerNumber()){
  328.                         /* Error */
  329.                         GRTone(1500,100);
  330.                         GRTone(500,200);
  331.                         break;
  332.                     }
  333.                     LayerPointer->CurrentLayer = Layer;
  334.                     SetLayerMode(Layer,2);
  335.                     break;
  336.  
  337.          
  338.             }
  339.  
  340.         }
  341.         ShowLayers();
  342.     }
  343.     /* ShowStatus(EEActiveWindow,1); */
  344.     return(0);
  345. }
  346. int SetColor(void)
  347. {
  348.     int PopPosition;
  349.     int i;
  350.     Cursor.CursorType = INTR_CURSOR_ARROW;
  351.     if (ColorPopUpMenu == NULL) {
  352.         ColorPopUpMenu =
  353.             IntrPopUpMenuCreate("Change Color Data", (char **) LayerColor,
  354.                         0, COLOR_MENU_SIZE, EEPopUpFrameColor,
  355.                               EEPopUpBackColor, EEPopUpForeColor,
  356.                             EEPopUpXorColor, EEWindowsFrameWidth, &Cursor);
  357.     }
  358.  
  359.     PopPosition=INTR_WNDW_PLACE_RIGHT;
  360.     i=IntrPopUpMenu(ColorPopUpMenu, PopPosition);
  361.     if(i)
  362.         return(LayerColorData[ColorPopUpMenu -> SelectedIndex]);
  363.     else
  364.     return(-1);
  365.     
  366. }
  367. int SetMode(void)
  368. {
  369.     int PopPosition;
  370.     int i;
  371.     Cursor.CursorType = INTR_CURSOR_ARROW;
  372.     if (ModePopUpMenu == NULL) {
  373.         ModePopUpMenu =
  374.             IntrPopUpMenuCreate("Change Layer Mode", (char **) LayerMode,
  375.                         0, MODE_MENU_SIZE, EEPopUpFrameColor,
  376.                               EEPopUpBackColor, EEPopUpForeColor,
  377.                             EEPopUpXorColor, EEWindowsFrameWidth, &Cursor);
  378.     }
  379.  
  380.     PopPosition=INTR_WNDW_PLACE_RIGHT;
  381.         i=IntrPopUpMenu(ModePopUpMenu, PopPosition); 
  382.     if(i)
  383.         return(ModePopUpMenu -> SelectedIndex);
  384.     else
  385.         return(-1);
  386.     
  387. }
  388. int ReturnCurrentWidth()
  389. {
  390.     return(LayerPointer -> CurrentWidth);
  391. }
  392. void SetCurrentWidth(int Width)
  393. {
  394.     LayerPointer -> CurrentWidth = Width;
  395. }
  396. int ReturnCurrentLayer()
  397. {
  398.     return(LayerPointer -> CurrentLayer);
  399. }
  400. void SetCurrentLayer(int Layer)
  401. {
  402.     LayerPointer->CurrentLayer = Layer;
  403. }
  404. char *ReturnLayerName(Layer)
  405. int Layer;
  406. {
  407.     return(LayerPointer->LayerNames[Layer]);
  408. }
  409. void SetLayerName(Layer,Name)
  410. int Layer;
  411. char *Name;
  412. {
  413.     strcpy(LayerPointer->LayerNames[Layer],Name);
  414. }
  415. int ReturnLayerMode(Layer)
  416. int Layer;
  417. {
  418.     return(LayerPointer->LayerStatus[Layer]);
  419. }
  420. void SetLayerMode(Layer,Mode)
  421. int Layer,Mode;
  422. {
  423.     LayerPointer->LayerStatus[Layer]=Mode;
  424. }
  425. void SetCommonColor()
  426. {
  427.     if(LayerPointer->Flags == 0)
  428.         LayerPointer->Flags = 1;
  429.     else
  430.         LayerPointer->Flags = 0;
  431. }
  432. int ReturnLayerColor(Layer)
  433. int Layer;
  434. {
  435.     if(LayerPointer->Flags==0)
  436.         return(LayerPointer->LayerColor[Layer]);
  437.     else
  438.         return(LayerPointer->CommonColor);
  439. }
  440. void SetLayerColor(Layer,Color)
  441. int Layer,Color;
  442. {
  443.     LayerPointer->LayerColor[Layer]=Color;
  444. }
  445. int ReturnLayerNumber()
  446. {
  447.     return(LayerPointer->NumberOfLayers);
  448. }
  449. void SetLayerNumber(Number)
  450. int Number;
  451. {
  452.     LayerPointer->NumberOfLayers=Number;
  453. }
  454. int ReturnNextUsableLayer(Layer)
  455. int Layer;
  456. {
  457.     int a,b;
  458.     a=Layer;
  459.     a++;    /* take Layer counter to current layer +1 */
  460.     while(a!=LayerPointer->NumberOfLayers +1){
  461.         b=ReturnLayerMode(a);
  462.         if(b==LAYER_ENABLED)
  463.             return(a);
  464.         else
  465.             a++;
  466.     }
  467.     a=0;
  468.     while(a!=LayerPointer->NumberOfLayers +1){
  469.         b=ReturnLayerMode(a);
  470.         if(b==LAYER_ENABLED) 
  471.             return(a);
  472.         else
  473.             a++;
  474.     }
  475.     return(Layer);    /* should never get reached */
  476. }
  477. void LoadLayers(f)
  478. FILE *f;    /* Load the Layer Structuer from a file */
  479. {
  480.     int cnt,Number;
  481.     char Line[LINE_LEN];
  482.     int Mode,Color,Layer;
  483.     char Name[0x10];
  484.  
  485.     fgets(Line,LINE_LEN-1,f);    /* read line */
  486.     sscanf(Line,"%s %d %d",Name,&Number,&LayerPointer->CurrentLayer);
  487.     if((strcmp(Name,"EELAYER"))!=0){
  488.         /* Error! */
  489.     } else
  490.         SetLayerNumber(Number);
  491.     cnt=0;
  492.     while(cnt!=Number+1){
  493.         fgets(Line,LINE_LEN-1,f);    /* read line */
  494.         sscanf(Line,"%s %d %d %d",Name,&Color,&Mode,&Layer);
  495.         SetLayerName(Layer,Name);
  496.         SetLayerColor(Layer,Color);
  497.         SetLayerMode(Layer,Mode);
  498.         cnt++;
  499.     }
  500.     fgets(Line,LINE_LEN-1,f);    /* read trailing Line */
  501.  
  502. }
  503. void SaveLayers(f)
  504. FILE *f;    /* Save a Layer Structure to a file */
  505. {
  506.     int a;
  507.     fprintf(f,"EELAYER %2d %2d\n",
  508.         ReturnLayerNumber(),LayerPointer->CurrentLayer);
  509.     a=0;
  510.     while(a!=(ReturnLayerNumber() + 1)){
  511.         fprintf(f,"%8s %4d %2d %2d\n",
  512.             ReturnLayerName(a),ReturnLayerColor(a),
  513.             ReturnLayerMode(a),a);
  514.         a++;
  515.     }
  516.     fprintf(f,"EELAYER END\n");
  517. }
  518. int SetLayerList(void)
  519. {
  520.  
  521.     char **Names;
  522.     
  523.     char loop;
  524.     int i;
  525.  
  526.     Cursor.CursorType = INTR_CURSOR_ARROW;
  527.  
  528.     Names = (char **) MyMalloc(sizeof(char *) * (ReturnLayerNumber() +4));
  529.     
  530.     loop=0;
  531.     while(loop!=ReturnLayerNumber()+4){
  532.         Names[loop]=ShowData[loop];
  533.         loop++;
  534.     }
  535.     i=IntrQueryList("Layers",(char **) Names,0,
  536.         ReturnLayerNumber() +3,EEListNumDisplayed,
  537.         EEPopUpFrameColor, EEPopUpBackColor,EEPopUpForeColor,
  538.         EEPopUpXorColor,EEWindowsFrameWidth, &Cursor,
  539.         INTR_WNDW_PLACE_RIGHT);
  540.     MyFree((VoidPtr)Names);
  541.     return(i);
  542. }
  543. void ShowStatus(Window,flag)
  544. EEWindowStruct *Window;
  545. int flag;
  546. {
  547.     char Mod,HVL,Wid,Disp;
  548.     if(Window->Modified)
  549.         Mod='M';
  550.     else
  551.         Mod='O';
  552.     if(EEHVLineDrawing)
  553.         HVL='O';
  554.     else
  555.         HVL='A';
  556.     if(Window->Layer->Flags == 0)
  557.         Disp='N';
  558.     else
  559.         Disp='S';
  560.     sprintf(Window->StatusR,"%c %c %d %d %c",Mod,HVL,
  561.         EESnapDistance,Window->Layer->CurrentWidth,Disp);
  562.     strcpy(Window->StatusL,ReturnLayerName(ReturnCurrentLayer()));
  563.     IntrWndwSetStatus(Window -> IntrLibWindowID, 
  564.        Window->StatusL, Window->StatusR, /* TRUE */ FALSE);
  565.     if(flag!=1)
  566.          IntrWndwPop(Window -> IntrLibWindowID, TRUE, FALSE); 
  567. }
  568. int NewLayer()
  569. {
  570.  
  571.     int PopPosition;
  572.     int Layer;
  573.     int i;
  574.     char Line[LINE_LEN_SHORT];
  575.     Layer=ReturnLayerNumber() +1;
  576.     SetLayerNumber(Layer);
  577.     SetLayerMode(Layer,2);    /* Set Layer Usable */
  578.     sprintf(Line,"User%02d",ReturnLayerNumber());
  579.      PopPosition=INTR_WNDW_PLACE_RIGHT;
  580.     IntrQueryLine("Enter New Layer Name:", Line,
  581.         LINE_LEN_SHORT -1, EEPopUpFrameColor,
  582.         EEPopUpBackColor,EEPopUpForeColor,
  583.         EEWindowsFrameWidth,PopPosition);
  584.     SetLayerName(Layer,Line);
  585.     i=SetColor();
  586.     if(i==-1){
  587.         Layer=ReturnLayerNumber() -1;
  588.         SetLayerNumber(Layer);
  589.         return(-1);
  590.     } else
  591.         SetLayerColor(Layer,i);
  592.     return(ReturnLayerNumber());
  593. }
  594.