home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
disks
/
disk373.lzh
/
Multiplot
/
source
/
mplot_src
/
src.zoo
/
physio.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-02
|
54KB
|
1,322 lines
#include "physio.h"
short tit; /* Flag for window title */
void PToU();
/**********************************************************
[ ]
[ InitWind() ]
[ ]
[ Open interlace backdrop borderless window for rendering ]
[ plot into. ]
[ ]
**********************************************************/
InitWind(Pict)
struct Pict *Pict;
{
newwindow.Screen = screen;
if (!(window = (struct Window *)OpenWindow(&newwindow)))
{
ErrorAlert(0);
FreeMemory(Pict);
CloseScreen(screen);
sexit(FALSE);
}
SetPointer(window,WaitSprite,26,14,-4,-4);
rp = window->RPort; vp = &window->WScreen->ViewPort;
SetDrMd(rp,JAM1); SetAPen(rp,1);
SetMenuStrip(window,&Project);
tit=TRUE;
return(1);
}
/************************************************************
[ ]
[ InitColours() and SavColours() ]
[ ]
[ Open a default file, and read the new screen colours from ]
[ it. Ditto for save. ]
[ ]
************************************************************/
void InitColours()
{
int depth, i, r, g, b;
FILE *fp;
depth = 1 << screen->BitMap.Depth; /* no easier way? */
strmfp(Def_file,StartDir,"MPlot.def");
if (!(fp = fopen(Def_file,"r")))
{
strcpy(Def_file,"s:");
strcat(Def_file,"MPlot.def");
fp = fopen(Def_file,"r");
}
if (!fp)
{
Message(" Can't open file MPlot.def ");
SetRGB4(vp,0,15,10,5); SetRGB4(vp,1,0,0,0); SetRGB4(vp,2,15,15,15);
SetRGB4(vp,3,15,0,0); SetRGB4(vp,4,0,0,0); SetRGB4(vp,5,15,0,0);
SetRGB4(vp,6,0,12,0); SetRGB4(vp,7,0,5,15); SetRGB4(vp,8,13,13,0);
SetRGB4(vp,9,0,13,13); SetRGB4(vp,10,15,0,15); SetRGB4(vp,11,10,10,0);
SetRGB4(vp,12,8,8,8); SetRGB4(vp,13,5,5,0); SetRGB4(vp,14,0,10,15);
SetRGB4(vp,15,15,8,0);
}
else
{
for (i=0; (i < depth) && (fscanf(fp,"%d %d %d\n",&r,&g,&b)==3); i++)
SetRGB4(vp,i,r,g,b);
fclose(fp);
}
}
SvColours()
{
int depth, i, r, g, b;
FILE *fp;
UWORD colour; /* I only remember these typedefs */
struct ColorMap *map; /* when reading includes :-) */
depth = 1 << screen->BitMap.Depth; /* no easier way? */
map = vp->ColorMap;
strmfp(Def_file,StartDir,"MPlot.def");
if (!(fp = fopen(Def_file,"w")))
{
strcpy(Def_file,"s:");
strcat(Def_file,"MPlot.def");
fp = fopen(Def_file,"w");
}
if (!fp)
{
Message(" Can't open file MPlot.def ");
return(0);
}
for (i=0; i < depth; i++)
{
colour = GetRGB4(map,i); /* each colour component encoded by 4 bits */
r = (colour & 0xf00) >> 8;
g = (colour & 0x0f0) >> 4;
b = (colour & 0x00f);
fprintf(fp,"%d %d %d\n",r,g,b);
}
fclose(fp);
return(1);
}
/*************************************************************
[ ]
[ CheckMenu(), ExcludeMenu() and AttrOnOff(). ]
[ ]
[ Not nice, but keeps the Plot window menus up to date. Note ]
[ this is run after the "Snooze pointer" is turned off. This ]
[ creates the impression that the program runs faster than ]
[ it really does. Hope no-one has fast reflexes! ]
[ ]
*************************************************************/
#define SELECT 0
#define REGION 1
#define LINE 2
#define BOX 3
#define SLIDE 4
short MouseAction = SELECT;
CheckMenu(Pict)
struct Pict *Pict;
{
switch (Pict->Grid) {
case 0:
ExcludeMenu(&Tics,&Grid_si,&None);
ExcludeMenu(&StemNleaf,&BoxAxes,&NoAxes);
break;
case 1:
ExcludeMenu(&None,&Grid_si,&Tics);
ExcludeMenu(&StemNleaf,&BoxAxes,&NoAxes);
break;
case 2:
ExcludeMenu(&Grid_si,&Tics,&None);
ExcludeMenu(&BoxAxes,&StemNleaf,&NoAxes);
break;
case 3:
ExcludeMenu(&Tics,&Grid_si,&None);
ExcludeMenu(&BoxAxes,&StemNleaf,&NoAxes);
break;
case 4:
ExcludeMenu(&None,&Grid_si,&Tics);
ExcludeMenu(&BoxAxes,&StemNleaf,&NoAxes);
break;
case 5:
ExcludeMenu(&None,&Grid_si,&Tics);
ExcludeMenu(&NoAxes,&StemNleaf,&BoxAxes);
break;
default:
ExcludeMenu(&Tics,&Grid_si,&None);
ExcludeMenu(&StemNleaf,&BoxAxes,&NoAxes);
break;
}
switch (MouseAction) {
case SELECT: ExcludeMenu(&Select,&Zoom,&Slide); break;
case REGION: ExcludeMenu(&Zoom,&Select,&Slide); break;
case SLIDE: ExcludeMenu(&Slide,&Zoom,&Select); break;
default: break;
}
return(1);
}
ExcludeMenu(MItem1,MItem2,MItem3)
struct MenuItem *MItem1, *MItem2, *MItem3;
{
if (MItem2->Flags & CHECKED) MItem2->Flags &= ~CHECKED;
if (MItem3->Flags & CHECKED) MItem3->Flags &= ~CHECKED;
if (MItem1->Flags & CHECKED) return(0);
MItem1->Flags |= CHECKED;
return(1);
}
void AttrOnOff(Pict, item)
struct Pict *Pict;
int item;
{
ClearMenuStrip(window);
switch(item) {
case SI_XREGION:
if (Pict->XRegionLock)
{
if (Xregion.Flags & CHECKED) ;
else Xregion.Flags |= CHECKED;
}
else if (Xregion.Flags & CHECKED) Xregion.Flags &= ~CHECKED;
break;
case SI_YREGION:
if (Pict->YRegionLock)
{
if (Yregion.Flags & CHECKED) ;
else Yregion.Flags |= CHECKED;
}
else if (Yregion.Flags & CHECKED) Yregion.Flags &= ~CHECKED;
break;
default: break;
}
SetMenuStrip(window, &Project);
}
/************************************************************
[ ]
[ CleanUp() ]
[ ]
[ Close interlace backdrop borderless window for rendering ]
[ plot into. ]
[ ]
************************************************************/
void CleanUp()
{ClearMenuStrip(window); CloseWindow(window);}
/************************************************************
[ ]
[ PutXHair(), GetXHair() and KillXHair() ]
[ ]
[ Cross Hair handling. Works by drawing lines in COMPLIMENT ]
[ then udrawing them by drawing them again. ]
[ ]
************************************************************/
USHORT InvisPtr[] = {
0x0,0x0, 0x0,0x0, 0x0,0x0, 0x0,0x0, 0x0,0x0, 0x0,0x0, 0x0,0x0,
0x0,0x0, 0x0,0x0, 0x0,0x0, 0x0,0x0};
static short XHair = FALSE;
static short WhiteBG = FALSE;
void PutXHair(x,y)
short x,y;
{Move(rp,0,y); Draw(rp,MAXHORIZ,y); Move(rp,x,0); Draw(rp,x,MAXVERT);}
void GetXHair(x,y)
short *x, *y;
{SetPointer(window,InvisPtr,9,9,0,0); PutXHair(*x,*y);}
void KillXHair(x,y)
short x,y;
{ClearPointer(window); PutXHair(x,y);}
/************************************************************
[ ]
[ RubberBox() ]
[ ]
[ Works same way as the cross hair handling ]
[ ]
************************************************************/
void RubberBox(x1, y1, x2, y2)
short *x1, *y1, *x2, *y2;
{
Move(rp,x1,y1);
if (XHair) {Draw(rp,x1,y2); Move(rp,x1,y1); Draw(rp,x2,y1);}
else {Draw(rp,x1,y2); Draw(rp,x2,y2); Draw(rp,x2,y1); Draw(rp,x1,y1);}
}
/****************************************************************
[ ]
[ CheckUser(Pict) ]
[ ]
[ The big bastard. This slug sits there waiting for you to move ]
[ Is basically the entire user interface. ]
[ ]
****************************************************************/
#define SHIFTED (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT)
extern int KEEP_GOING;
extern char filename[150];
extern int CALC_XMIN;
extern int CALC_YMIN;
extern struct Remember *Key;
struct TextBox *ExtraText=NULL;
struct Selection *Sump=NULL;
struct Remember *SumpKey=NULL;
CheckUser(Pict)
struct Pict *Pict;
{
ULONG class;
USHORT code, qual;
static ULONG seconds, micros;
static ULONG Click_seconds=0, Click_micros=0;
struct Selection *Seln, *TempSeln, *TempSump;
struct Remember *SelnKey=NULL;
struct TextBox *SelectedTextBox=NULL, *TempText, *GetSelectedText();
struct Plot *SelectedPlot=NULL, *GetSelectedPlot(), *TempPlot;
void KillText();
int retval = NOACTION, screensave(), CATCHUP;
static short x0, y0, x, y;
short tempx, tempy, x1, y1, count, RubberBand = FALSE, SlideBox = FALSE;
USHORT OldChoice;
FFP XMin, YMin, XMax, YMax;
struct PlotRegion *Reg;
struct Process *OurTask;
struct Window *old_pr_WindowPtr;
struct MenuItem *item;
char plotname[150], def_drive[150], def_path[100], def_node[30],def_extn[20];
char Command[180];
char convert_tool[150]; /* string descibing path to current directory */
/* when started from workbench to locate tools */
AttrOnOff(Pict, SI_XREGION); AttrOnOff(Pict, SI_YREGION);
x1=x=window->MouseX; y1=y=window->MouseY;
SetDrMd(rp,COMPLEMENT);
if (XHair) GetXHair(&x,&y);
TempSeln=Seln=NULL; SelectedTextBox=NULL;
do {
CATCHUP=FALSE;
while (msg = (struct IntuiMessage *) GetMsg(window->UserPort) ) {
class = msg->Class;
code = msg->Code; x = msg->MouseX; y = msg->MouseY;
seconds=msg->Seconds; micros=msg->Micros;
qual=msg->Qualifier;
ReplyMsg(msg);
if (class == MENUPICK) {
while (code != MENUNULL) {
switch (MENUNUM(code)) {
case M_PROJECT:
switch(ITEMNUM(code)) {
case MI_QUIT:
KEEP_GOING=FALSE;
retval = QUIT;
if (Sump) FreeRemember(&SumpKey,TRUE);
Sump=NULL;
break;
case MI_PRINT:
SetPointer(window,WaitSprite,26,14,-4,-4);
WrtPlt(Pict,FALSE);
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
break;
case MI_OPEN: KEEP_GOING=TRUE; retval = QUIT; break;
case MI_SAVE:
SetPointer(window,WaitSprite,26,14,-4,-4);
SaveDat(Pict,FALSE);
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
break;
case MI_SAVEAS:
switch (SUBNUM(code)) {
case SI_HPGL:
SetPointer(window,WaitSprite,26,14,-4,-4);
WrtPlt(Pict,TRUE);
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
break;
case SI_MCAD:
SetPointer(window,WaitSprite,26,14,-4,-4);
To_mCAD(Pict,TRUE);
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
break;
case SI_IFF:
SetPointer(window,WaitSprite,26,14,-4,-4);
screensave();
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
break;
case SI_DRAW:
SetPointer(window,WaitSprite,26,14,-4,-4);
strcpy(plotname,filename);
strsfn(plotname,def_drive,def_path,def_node,def_extn);
strcat(def_drive,def_path);
strcat(def_node,".draw");
OurTask = (struct Process *)FindTask(0L);
old_pr_WindowPtr = (struct Window *)OurTask->pr_WindowPtr;
OurTask->pr_WindowPtr = (APTR)window;
if (get_fname(window,screen,"Save File As...",def_node,def_drive)==NULL)
{
OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
break;
}
OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
strmfp(plotname,def_drive,def_node);
if (To_mCAD(Pict,FALSE))
{
strmfp(convert_tool,StartDir,"plot2draw");
sprintf(Command,"\"%s\" t:tempfile \"%s\"",convert_tool,plotname);
Execute(Command,0,0);
DeleteFile("t:tempfile");
}
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
break;
case SI_ICAD:
SetPointer(window,WaitSprite,26,14,-4,-4);
strcpy(plotname,filename);
strsfn(plotname,def_drive,def_path,def_node,def_extn);
strcat(def_drive,def_path);
strcat(def_node,".iCAD");
OurTask = (struct Process *)FindTask(0L);
old_pr_WindowPtr = (struct Window *)OurTask->pr_WindowPtr;
OurTask->pr_WindowPtr = (APTR)window;
if (get_fname(window,screen,"Save File As...",def_node,def_drive)==NULL)
{
OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
break;
}
OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
strmfp(plotname,def_drive,def_node);
if (To_mCAD(Pict,FALSE))
{
strmfp(convert_tool,StartDir,"txt_2_icad");
sprintf(Command,"\"%s\" t:tempfile \"%s\"",convert_tool,plotname);
Execute(Command,0,0);
DeleteFile("t:tempfile");
}
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
break;
case SI_SAVEDAT:
SetPointer(window,WaitSprite,26,14,-4,-4);
SaveDat(Pict,TRUE);
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
break;
default: break;
}
break;
default: break;
}
break;
case M_EDIT:
switch (ITEMNUM(code)) {
case MI_UNDEL:
if (!Sump) Message(" Nothing deleted to restore");
else {
if (Sump->SelectedPlot) {
for (TempSump=Sump;TempSump;TempSump=TempSump->NextSelection)
{
if (Pict->Plot) {
for (TempPlot=Pict->Plot;TempPlot->NextPlot;TempPlot=TempPlot->NextPlot) ;
TempPlot->NextPlot=TempSump->SelectedPlot;
for (TempPlot=TempPlot->NextPlot;TempPlot->Continued;TempPlot=TempPlot->NextPlot) ;
}
else {
Pict->Plot=TempSump->SelectedPlot;
for (TempPlot=Pict->Plot;TempPlot->Continued;TempPlot=TempPlot->NextPlot) ;
}
TempPlot->NextPlot=NULL;
}
FreeRemember(&SumpKey,TRUE);
Sump=NULL;
}
else if (Sump->SelectedBox) {
for (TempSump=Sump;TempSump;TempSump=TempSump->NextSelection)
{
if (!ExtraText) {
ExtraText=TempSump->SelectedBox;
ExtraText->NextText=NULL;
}
else {
for (TempText=ExtraText;TempText->NextText;TempText=TempText->NextText) ;
TempText->NextText=TempSump->SelectedBox;
TempText->NextText->NextText=NULL;
}
}
FreeRemember(&SumpKey,TRUE);
Sump=NULL;
}
retval=max(retval,REDRAW);
CALC_XMIN=TRUE;
}
break;
case MI_COPY:
if (!Seln) Message(" Nothing selected to copy");
else {
SetPointer(window,WaitSprite,26,14,-4,-4);
ClipCopy(Pict,Seln);
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
}
break;
case MI_PASTE:
SetPointer(window,WaitSprite,26,14,-4,-4);
if (ClipPaste(Pict)) {retval=max(retval,REDRAW); CALC_XMIN=TRUE;}
else {
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
}
break;
case MI_CUT:
if (!Seln) Message(" Nothing selected to cut");
else {
SetPointer(window,WaitSprite,26,14,-4,-4);
if (ClipCopy(Pict,Seln)) {
if (DeleteSeln(Pict,Seln,&SelnKey)) retval=max(retval,REFRESH);
else {
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
}
}
else {
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
}
}
break;
case MI_ADDTEXT:
if (!SelectedPlot)
{
if (ExtraText)
{
for (TempText=ExtraText;TempText->NextText;TempText=TempText->NextText);
if (TempText->NextText=(struct TextBox *) AllocRemember(&Key,(sizeof(struct TextBox)),MEMF_CLEAR))
{
TempText=TempText->NextText;
EditText(TempText->String);
TempText->x=400; TempText->y=200;
TempText->NextText=NULL;
retval = REDRAW;
}
else Message(" Not enough memory for text");
}
else
{
if (ExtraText=(struct TextBox *) AllocRemember(&Key,(sizeof(struct TextBox)),MEMF_CLEAR))
{
TempText=ExtraText;
EditText(TempText->String);
TempText->x=400; TempText->y=200;
TempText->NextText=NULL;
retval = REDRAW;
}
else Message(" Not enough memory for text");
}
}
else
{
EditText(SelectedPlot->Legend->String);
Pict->RMargin=CALC_XMIN=TRUE; retval = REDRAW;
}
break;
case MI_DELETE:
if (DeleteSeln(Pict,Seln,&SelnKey)) retval=max(retval,REFRESH);
else Message(" Nothing selected to delete");
break;
default: break;
}
break;
case M_ACTIONS:
switch (ITEMNUM(code)) {
case MI_MACTION:
switch (SUBNUM(code)) {
case SI_SELECT: MouseAction = SELECT; break;
case SI_ZOOM: MouseAction = REGION; break;
case SI_SLIDE: MouseAction = SLIDE; break;
default: break;
}
CheckMenu(Pict);
break;
case MI_FULLPLOT: retval = max(retval,GETDATALIMITS); break;
case MI_REDRAW: retval = max(retval,REDRAW); break;
case MI_GETHOWTO: CALC_XMIN=TRUE; retval= max(retval,GETHOWTO); break;
case MI_LOCKS:
switch (SUBNUM(code)) {
case SI_LOCKSON:
Pict->XRegionLock=Pict->YRegionLock=TRUE;
AttrOnOff(Pict, SI_XREGION);
AttrOnOff(Pict, SI_YREGION);
break;
case SI_LOCKSOFF:
Pict->XRegionLock=Pict->YRegionLock=FALSE;
AttrOnOff(Pict, SI_XREGION);
AttrOnOff(Pict, SI_YREGION);
break;
case SI_YREGION:
Pict->YRegionLock=!Pict->YRegionLock;
AttrOnOff(Pict, SI_YREGION);
break;
case SI_XREGION:
Pict->XRegionLock=!Pict->XRegionLock;
AttrOnOff(Pict, SI_XREGION);
break;
default: break;
}
break;
default: break;
}
break;
case M_OPTIONS:
switch (ITEMNUM(code)) {
case MI_CROSSHAIR:
if (XHair = !XHair) {GetXHair(&x,&y); x1=x; y1=y;}
else KillXHair(x1,y1);
break;
case MI_RMARGIN:
if (Pict->RMargin) Pict->RMargin=FALSE;
else Pict->RMargin=TRUE;
CALC_XMIN=TRUE;
retval=max(retval,REDRAW);
break;
case MI_ERRBARS:
if (Pict->ErrBar)
{
if (Pict->ShowErr) Pict->ShowErr = FALSE;
else Pict->ShowErr = TRUE;
retval=max(retval,REFRESH);
}
break;
case MI_GRID:
switch (SUBNUM(code)) {
case SI_NONE:
if (Pict->Grid==0){Pict->Grid=1; retval=max(retval,REDRAW);}
if ((Pict->Grid==2)||(Pict->Grid==3)) {Pict->Grid=4; retval=max(retval,REDRAW);}
break;
case SI_TICS:
if ((Pict->Grid==1)||(Pict->Grid==5)){Pict->Grid=0; retval=max(retval,REFRESH);}
if ((Pict->Grid==2)||(Pict->Grid==4)){Pict->Grid=3; retval=max(retval,REFRESH);}
break;
case SI_GRID:
if (Pict->Grid!=2){Pict->Grid=2; retval=max(retval,REFRESH);}
break;
}
break;
case MI_AXES:
switch (SUBNUM(code)) {
case SI_NOAXES:
if (Pict->Grid!=5){Pict->Grid=5; retval=max(retval,REDRAW);}
break;
case SI_BOXAXES:
if (Pict->Grid==0){Pict->Grid=3; retval=max(retval,REFRESH);}
if ((Pict->Grid==1)||(Pict->Grid==5)){Pict->Grid=4; retval=max(retval,REFRESH);}
break;
case SI_STEMNLEAF:
if ((Pict->Grid==2)||(Pict->Grid==3)){Pict->Grid=0; retval=max(retval,REFRESH);}
if ((Pict->Grid==4)||(Pict->Grid==5)){Pict->Grid=1; retval=max(retval,REFRESH);}
break;
}
break;
case MI_PALETTE:
switch (SUBNUM(code)) {
case SI_ALTERCOL:
SetPointer(window,WaitSprite,26,14,-4,-4);
DoColorWindow(screen, 150, 60, 1, TRUE);
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
break;
case SI_SAVECOL:
SetPointer(window,WaitSprite,26,14,-4,-4);
SvColours();
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
break;
default: break;
}
break;
case MI_SCREENTITLE:
if (tit==TRUE) {ShowTitle(screen,FALSE);tit=FALSE;}
else {ShowTitle(screen,TRUE); tit=TRUE;}
break;
default: break;
}
break;
case M_FUNCTIONS:
switch (ITEMNUM(code)) {
case MI_SORT:
if (!SelectedPlot) {Message("A Data Set Must Be Selected");}
else
{
SetPointer(window,WaitSprite,26,14,-4,-4);
if (SortData(Pict,SelectedPlot))
{
CALC_XMIN=CALC_YMIN=TRUE;
retval = max(retval,GETDATALIMITS);
}
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
}
break;
case MI_SMOOTH:
if (!SelectedPlot) {Message("A Data Set Must Be Selected");}
else
{
SetPointer(window,WaitSprite,26,14,-4,-4);
if (SmoothData(Pict,SelectedPlot)) {
retval=max(retval,GETDATALIMITS);
CALC_XMIN=CALC_YMIN=TRUE;
}
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
}
break;
case MI_LINEFIT:
if (!SelectedPlot) {Message("A Data Set Must Be Selected");}
else
{
SetPointer(window,WaitSprite,26,14,-4,-4);
if (FitData(Pict,SelectedPlot)) {
retval = max(retval,GETDATALIMITS);
Pict->RMargin=CALC_XMIN=CALC_YMIN=TRUE;
}
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
}
break;
case MI_LOGFIT:
if (!SelectedPlot) {Message("A Data Set Must Be Selected");}
else
{
SetPointer(window,WaitSprite,26,14,-4,-4);
if (FitLogData(Pict,SelectedPlot)) {
retval=max(retval,GETDATALIMITS);
Pict->RMargin=CALC_XMIN=CALC_YMIN=TRUE;
}
if (XHair) SetPointer(window,InvisPtr,9,9,0,0);
else ClearPointer(window);
}
break;
default: break;
}
break;
default: break;
} /* switch */
item=(struct MenuItem *)ItemAddress(&Project,code);
code=item->NextSelect;
} /* While loop */
} /* if ((class == MENUPICK) ...*/
else if ( class == RAWKEY) {
if (code ==95) ; /* HELP key PRESSED */
else if (code ==69) /* ESCAPE key PRESSED */
{
KEEP_GOING=FALSE;
retval = QUIT;
if (Sump) FreeRemember(&SumpKey,TRUE);
Sump=NULL;
}
else if (code ==70) /* DELETE key PRESSED */
{
if (DeleteSeln(Pict,Seln,&SelnKey)) retval=max(retval,REDRAW);
else Message(" Nothing selected to delete");
}
}
else if (class == MOUSEBUTTONS) {
switch (code) {
case SELECTDOWN:
if (MouseAction==SELECT) { /* Find the Data Set attached to nearest point */
CATCHUP=TRUE; OldChoice=FALSE;
SelectedPlot = GetSelectedPlot(Pict,&count,x,y);
if (SelectedPlot) SelectedTextBox=NULL;
else SelectedTextBox=GetSelectedText(Pict,x,y);
if ((Seln)&&(Seln->SelectedPlot)) { /* If some Plots already selected */
if (!SelectedPlot) {
TempSeln=Seln; /* Dump old Selection */
while ((TempSeln)&&(TempSeln->SelectedPlot))
{
HighlightPlot(Pict,TempSeln->SelectedPlot); /* Unhighlight */
TempSeln=TempSeln->NextSelection;
}
FreeRemember(&SelnKey,TRUE); Seln=NULL;
}
else { /* A selection */
if (qual&SHIFTED) { /* To be added to list */
if (!CheckSeln(Seln,SelectedPlot)) { /* It's a new one */
TempSeln=Seln;
while (TempSeln->NextSelection) TempSeln=TempSeln->NextSelection;
TempSeln->NextSelection = (struct Selection *)AllocRemember(&SelnKey,sizeof(struct Selection),MEMF_CLEAR);
if (TempSeln->NextSelection) {
TempSeln=TempSeln->NextSelection;
TempSeln->SelectedPlot=SelectedPlot; TempSeln->SelectedBox=NULL; TempSeln->NextSelection=NULL;
HighlightPlot(Pict,SelectedPlot);
}
else Message("Not enough memory for selection");
}
else ; /* if Already selected, do nothing */
}
else { /* If not shifted, dump old select, get new */
TempSeln=Seln;
while ((TempSeln)&&(TempSeln->SelectedPlot)) {
if (TempSeln->SelectedPlot==SelectedPlot) OldChoice=TRUE;
else HighlightPlot(Pict,TempSeln->SelectedPlot); /* Unhighlight */
TempSeln=TempSeln->NextSelection;
}
FreeRemember(&SelnKey,TRUE);
Seln = (struct Selection *)AllocRemember(&SelnKey,sizeof(struct Selection),MEMF_CLEAR);
if (Seln) {
if (!OldChoice) HighlightPlot(Pict,SelectedPlot);
Seln->SelectedPlot=SelectedPlot; Seln->SelectedBox=NULL; Seln->NextSelection=NULL;
}
else Message("Not enough memory for selection");
}
}
}
else if ((Seln)&&(Seln->SelectedBox)) {
if (!SelectedTextBox) {
TempSeln=Seln; /* Dump old Selection */
while ((TempSeln)&&(TempSeln->SelectedBox))
{
SlipperyBox(TempSeln->SelectedBox->x1,TempSeln->SelectedBox->y1,TempSeln->SelectedBox->x2,TempSeln->SelectedBox->y2);
TempSeln=TempSeln->NextSelection;
}
FreeRemember(&SelnKey,TRUE); Seln=NULL;
}
else { /* A selection */
if (qual&SHIFTED) { /* To be added to list */
if (!CheckSelnText(Seln,SelectedTextBox)) { /* It's a new one */
TempSeln=Seln;
while (TempSeln->NextSelection) TempSeln=TempSeln->NextSelection;
TempSeln->NextSelection = (struct Selection *)AllocRemember(&SelnKey,sizeof(struct Selection),MEMF_CLEAR);
if (TempSeln->NextSelection) {
TempSeln=TempSeln->NextSelection;
TempSeln->SelectedBox=SelectedTextBox; TempSeln->SelectedPlot=NULL; TempSeln->NextSelection=NULL;
SlipperyBox(SelectedTextBox->x1,SelectedTextBox->y1,SelectedTextBox->x2,SelectedTextBox->y2);
}
else Message("Not enough memory for selection");
}
else ; /* if Already selected, do nothing */
}
else { /* If not shifted, dump old select, get new */
TempSeln=Seln;
while ((TempSeln)&&(TempSeln->SelectedBox)) {
if (TempSeln->SelectedBox==SelectedTextBox) OldChoice=TRUE;
else SlipperyBox(TempSeln->SelectedBox->x1,TempSeln->SelectedBox->y1,TempSeln->SelectedBox->x2,TempSeln->SelectedBox->y2);
TempSeln=TempSeln->NextSelection;
}
FreeRemember(&SelnKey,TRUE);
Seln = (struct Selection *)AllocRemember(&SelnKey,sizeof(struct Selection),MEMF_CLEAR);
if (Seln) {
if (!OldChoice) SlipperyBox(SelectedTextBox->x1,SelectedTextBox->y1,SelectedTextBox->x2,SelectedTextBox->y2);
Seln->SelectedBox=SelectedTextBox; Seln->SelectedPlot=NULL; Seln->NextSelection=NULL;
}
else Message("Not enough memory for selection");
}
SlideBox = TRUE;
}
}
if (!Seln) {
if (SelectedPlot) {
Seln = (struct Selection *)AllocRemember(&SelnKey,sizeof(struct Selection),MEMF_CLEAR);
if (Seln) {
Seln->SelectedPlot=SelectedPlot; Seln->SelectedBox=NULL; Seln->NextSelection=NULL;
HighlightPlot(Pict,SelectedPlot);
}
else Message("Not enough memory for selection");
}
else if (SelectedTextBox) {
Seln = (struct Selection *)AllocRemember(&SelnKey,sizeof(struct Selection),MEMF_CLEAR);
if (Seln) {
Seln->SelectedBox=SelectedTextBox; Seln->SelectedPlot=NULL; Seln->NextSelection=NULL;
SlipperyBox(SelectedTextBox->x1,SelectedTextBox->y1,SelectedTextBox->x2,SelectedTextBox->y2);
SlideBox = TRUE;
}
else Message("Not enough memory for selection");
}
}
} /** end of "if was select" **/
if (DoubleClick(Click_seconds,Click_micros,seconds,micros)
&&PrettyClose(x0,x)&&PrettyClose(y0,y))
{
if (MouseAction==SELECT) /* Find the Data Set attached to nearest point */
{
if ((Seln)&&(Seln->SelectedPlot)) {
if (CustomPlotWindow(Pict,SelectedPlot,count)) {
CALC_XMIN=TRUE; retval= REDRAW;
}
}
else if ((Seln)&&(Seln->SelectedBox)) {
EditText(SelectedTextBox->String);
if (!strlen(SelectedTextBox->String)) {
if (DeleteSeln(Pict,Seln,&SelnKey)) {
CALC_XMIN=TRUE;
retval = REDRAW;
}
}
}
else {
if (y<(MAXVERT-YMAXP)) {
EditText(Pict->Title);
AllowForText(Pict);
retval = REDRAW;
}
else if (y>(MAXVERT-YMINP)) {
EditAxes('x',&Pict->Tics->NX,&Pict->CurrReg->XMin,&Pict->CurrReg->XMax,Pict->Tics->x);
AllowForText(Pict);
retval = REDRAW;
}
if (x<(XMINP)) {
EditAxes('y',&Pict->Tics->NY,&Pict->CurrReg->YMin,&Pict->CurrReg->YMax,Pict->Tics->y);
AllowForText(Pict);
retval = REDRAW;
}
}
}
else /* is Zoom or Slide... */
{ /* zoom out X 2 */
RubberBand = FALSE;
if (MouseAction == REGION)
{
/* RubberBox(x0,y0,x1,y1); */
Reg=Pict->CurrReg;
XMin=Reg->XMin-(Reg->XMax-Reg->XMin)/2;
XMax=Reg->XMax+(Reg->XMin-XMin);
YMin=Reg->YMin-(Reg->YMax-Reg->YMin)/2;
YMax=Reg->YMax+(Reg->YMin-YMin);
if ((!Pict->XRegionLock)&&( ( (FullReg->XMax-FullReg->XMin)/(XMax-XMin) )<100 ))
{Reg->XMin = XMin; Reg->XMax = XMax;}
if ((!Pict->YRegionLock)&&(((FullReg->YMax-FullReg->YMin)/(YMax-YMin))<100))
{Reg->YMin = YMin; Reg->YMax = YMax;}
retval = REPLOT;
}
}
}
if ((x1!=x)||(y1!=y)) {if(XHair) {PutXHair(x1,y1);PutXHair(x,y);}}
x0=x1=x; y0=y1=y;
if (MouseAction && !RubberBand) /* BEGIN RUBBERBAND */
{
RubberBand = TRUE;
if (MouseAction == REGION) {
RubberBox(x0,y0,x,y);
}
else if (MouseAction == SLIDE) {
Move(rp,x,y); Draw(rp,x,y);
}
}
Click_seconds=seconds; Click_micros=micros;
break;
case SELECTUP: /* END RUBBERBAND */
if (RubberBand)
{
RubberBand = FALSE;
if (MouseAction == REGION) {
RubberBox(x0,y0,x1,y1);
Reg = Pict->CurrReg;
if ((abs(x-x0) > 2) && (abs(y-y0) > 2)) {
/* zoom in to new region */
PToU(Pict,min(x0,x),MAXVERT-max(y0,y),&XMin,&YMin);
PToU(Pict,max(x0,x),MAXVERT-min(y0,y),&XMax,&YMax);
if ((!Pict->XRegionLock)&&( ( (FullReg->XMax-FullReg->XMin)/(XMax-XMin) )<100 ))
{Reg->XMin = XMin; Reg->XMax = XMax;}
if ((!Pict->YRegionLock)&&(((FullReg->YMax-FullReg->YMin)/(YMax-YMin))<100))
{Reg->YMin = YMin; Reg->YMax = YMax;}
retval = REPLOT;
}
}
else if (MouseAction == SLIDE) {
Move(rp,x0,y0); Draw(rp,x1,y1);
PToU(Pict,x0,MAXVERT-y0,&XMin,&YMin);
PToU(Pict,x,MAXVERT-y,&XMax,&YMax);
Reg = Pict->CurrReg;
if (!Pict->XRegionLock)
{Reg->XMin += XMin-XMax; Reg->XMax += XMin-XMax;}
if (!Pict->YRegionLock)
{Reg->YMin += YMin-YMax; Reg->YMax += YMin-YMax;}
retval = REPLOT;
}
}
else if (SlideBox)
{
SlideBox=FALSE;
if ((abs(x-x0)>2)||(abs(y-y0)>2)) retval=REFRESH;
}
break;
default: break;
} /* switch (code) */
break;
} /* else if (class == MENUBUTTONS) */
} /* while */
if ((class == MOUSEMOVE) && ((x1!=x)||(y1!=y)) ) {
if (XHair) {PutXHair(x1,y1); PutXHair(x,y);}
if (RubberBand) {
if (MouseAction == REGION)
{RubberBox(x0,y0,x1,y1); RubberBox(x0,y0,x,y);}
else if (MouseAction == SLIDE)
{Move(rp,x0,y0); Draw(rp,x1,y1); Move(rp,x0,y0); Draw(rp,x,y);}
}
else if (SlideBox) {
tempx=x-x1; tempy=y-y1;
for (TempSeln=Seln;TempSeln;TempSeln=TempSeln->NextSelection)
{
SlipperyBox(TempSeln->SelectedBox->x1,TempSeln->SelectedBox->y1,TempSeln->SelectedBox->x2,TempSeln->SelectedBox->y2);
}
for (TempSeln=Seln;TempSeln;TempSeln=TempSeln->NextSelection)
{
TempSeln->SelectedBox->x1+=tempx; TempSeln->SelectedBox->x2+=tempx;
TempSeln->SelectedBox->y1+=tempy; TempSeln->SelectedBox->y2+=tempy;
TempSeln->SelectedBox->x+=tempx; TempSeln->SelectedBox->y-=tempy; /* Remember screen coords upside down */
}
for (TempSeln=Seln;TempSeln;TempSeln=TempSeln->NextSelection)
{
SlipperyBox(TempSeln->SelectedBox->x1,TempSeln->SelectedBox->y1,TempSeln->SelectedBox->x2,TempSeln->SelectedBox->y2);
}
}
x1 = x; y1 = y;
}
if ((retval==NOACTION)&&(!CATCHUP)) Wait(1 << window->UserPort->mp_SigBit);
} while(retval == NOACTION);
if (XHair) PutXHair(x1,y1);
if (SelnKey) { FreeRemember(&SelnKey,TRUE); Seln=NULL;}
SetDrMd(rp, JAM1);
return(retval);
}
struct Plot *GetSelectedPlot(Pict,count,x,y)
struct Pict *Pict;
short x, y, *count;
{
int LOOKING, i;
short *xarray, *yarray;
struct Plot *Plot, *TempPlot;
LOOKING=TRUE;
Plot = Pict->Plot;
*count=0;
while (LOOKING) {
TempPlot=Plot;
do {
if (Plot->Enabled)
{
xarray = TempPlot->xp; yarray = TempPlot->yp;
for (i=0;i<TempPlot->NPts;i++)
{
if (PrettyClose(x,xarray[i])&&PrettyClose(y,MAXVERT-yarray[i]))
return(Plot);
}
}
} while ((TempPlot->Continued)&&(TempPlot=TempPlot->NextPlot));
if (Plot=TempPlot->NextPlot) *count+=1;
else LOOKING=FALSE;
}
return(NULL);
}
HighlightPlot(Pict,Plot)
struct Pict *Pict;
struct Plot *Plot;
{
short i,x,y;
short *xarray, *yarray;
do {
xarray = Plot->xp; yarray = Plot->yp;
for (i=0;i<Plot->NPts;i++)
{
x=xarray[i]; y=MAXVERT-yarray[i];
if (ClipPoint(x,y,XMINP,TMARGIN,XMAXP,MAXVERT-BMARGIN))
{
Move(rp,x-5,y-5); Draw(rp,x+5,y-5);
Draw(rp,x+5,y+5); Draw(rp,x-5,y+5);
Draw(rp,x-5,y-5);
}
}
} while ((Plot->Continued)&&(Plot=Plot->NextPlot));
return(0);
}
PrettyClose(x,y)
int x,y;
{
if ((y>x-5)&&(y<x+5)) return(TRUE);
else return(FALSE);
}
extern struct TextFont *lf;
extern struct TextAttr lfont;
extern struct IntuiText Legend;
extern int CHARWIDTH, CHARHEIGHT;
IsInTextBox(x,y,TextBox,Flag)
short x,y,Flag;
struct TextBox *TextBox;
{
short boxlength, boxheight;
if (lf)
{
Legend.IText=TextBox->String;
boxlength= IntuiTextLength(&Legend);
boxheight= lfont.ta_YSize;
}
else
{
boxlength= (strlen(TextBox->String)*CHARWIDTH);
boxheight= CHARHEIGHT;
}
TextBox->x1=TextBox->x-10;
if (Flag) TextBox->x2=TextBox->x+boxlength+10; /* An extra text */
else TextBox->x2=TextBox->x+boxlength+35; /* A legend */
TextBox->y1=MAXVERT-TextBox->y-boxheight/2-3;
TextBox->y2=MAXVERT-TextBox->y+boxheight/2;
if ((x<TextBox->x2)&&(x>TextBox->x1)&&(y<TextBox->y2)&&(y>TextBox->y1)) return(TRUE);
else return(FALSE);
}
SlipperyBox(x1, y1, x2, y2)
short x1, y1, x2, y2;
{
Move(rp,x1,y1);
Draw(rp,x2,y1);
Draw(rp,x2,y2);
Draw(rp,x1,y2);
Draw(rp,x1,y1);
return(TRUE);
}
CheckSeln(Seln,Plot)
struct Selection *Seln;
struct Plot *Plot;
{
while ((Seln)&&(Seln->SelectedPlot))
{
if (Seln->SelectedPlot==Plot) return(TRUE);
Seln=Seln->NextSelection;
}
return(FALSE);
}
CheckSelnText(Seln,TextBox)
struct Selection *Seln;
struct TextBox *TextBox;
{
while ((Seln)&&(Seln->SelectedBox))
{
if (Seln->SelectedBox==TextBox) return(TRUE);
Seln=Seln->NextSelection;
}
return(FALSE);
}
struct TextBox *GetSelectedText(Pict,x,y)
struct Pict *Pict;
short x, y;
{
struct Plot *Plot;
struct TextBox *TempText;
for (Plot=Pict->Plot;Plot;Plot=Plot->NextPlot) {
if (Plot->Enabled && strlen(Plot->Legend->String) && IsInTextBox(x,y,Plot->Legend,FALSE))
return(Plot->Legend);
}
for (TempText=ExtraText;TempText;TempText=TempText->NextText) {
if (TempText && IsInTextBox(x,y,TempText,TRUE))
return(TempText);
}
return(NULL);
}
DeleteSeln(Pict,Seln,SelnKey)
struct Pict *Pict;
struct Selection *Seln;
struct Remember **SelnKey; /*** Note: Address of pointer passed. cf SumpKey ***/
{
struct Selection *TempSeln, *TempSump;
struct TextBox *GetSelectedText(), *TempText;
struct Plot *Plot, *GetSelectedPlot();
void KillText(), KillPlot();
short legflag;
if ((Seln)&&(Seln->SelectedPlot)) { /* If some Plots selected */
if (Sump) FreeRemember(&SumpKey,TRUE);
Sump=NULL; TempSeln=Seln;
while ((TempSeln)&&(TempSeln->SelectedPlot)) {
KillPlot(Pict,TempSeln->SelectedPlot);
TempSeln=TempSeln->NextSelection;
}
return(TRUE);
}
else if ((Seln)&&(Seln->SelectedBox)) {
if (Sump) FreeRemember(&SumpKey,TRUE);
Sump=NULL; TempSeln=Seln;
while (TempSeln) {
legflag=FALSE;
for (Plot=Pict->Plot;Plot;Plot=Plot->NextPlot) {
if (Plot->Legend==TempSeln->SelectedBox) {
/*** If legend, make a new text box for Plot structure ***/
legflag=TRUE; TempSump=NULL;
if (TempText=(struct TextBox *) AllocRemember(&Key,(sizeof(struct TextBox)),MEMF_CLEAR))
{
TempSump = (struct Selection *)AllocRemember(&SumpKey,sizeof(struct Selection),MEMF_CLEAR);
if (TempSump) {
TempSump->SelectedBox=TempSeln->SelectedBox;
TempSump->SelectedBox->NextText=NULL;
AddSump(TempSump);
}
else Message("Not enough memory for undelete");
Plot->Legend=TempText;
Plot->Legend->NextText=NULL;
}
else Message("Not enough memory for delete");
}
}
if ((!legflag)&&(strlen(TempSeln->SelectedBox->String))) /* Not a legend, not deleted */
{
KillText(TempSeln->SelectedBox);
}
TempSeln=TempSeln->NextSelection;
}
FreeRemember(SelnKey,TRUE);
return(TRUE);
}
else return(FALSE);
}
void KillText(TextBox)
struct TextBox *TextBox;
{
struct TextBox *TempText;
struct Selection *TempSump;
if ((TextBox)&&(ExtraText==TextBox)) /* Check if is the first Text */
{
TempSump = (struct Selection *)AllocRemember(&SumpKey,sizeof(struct Selection),MEMF_CLEAR);
if (TempSump) {
TempSump->SelectedBox=ExtraText;
AddSump(TempSump);
}
else Message("Not enough memory for undelete");
ExtraText=ExtraText->NextText;
}
else if (TextBox) /* Is in the middle of chain */
{
for (TempText=ExtraText;TempText->NextText&&TempText->NextText!=TextBox;TempText=TempText->NextText);
if (TempText->NextText)
{
TempSump = (struct Selection *)AllocRemember(&SumpKey,sizeof(struct Selection),MEMF_CLEAR);
if (TempSump) {
TempSump->SelectedBox=TempText->NextText;
AddSump(TempSump);
}
else Message("Not enough memory for undelete");
TempText->NextText=TempText->NextText->NextText;
}
}
}
void KillPlot(Pict,Plot)
struct Pict *Pict;
struct Plot *Plot;
{
struct Plot *TempPlot;
struct Selection *TempSump;
if (Pict->Plot==Plot) /* Check if is the first data set */
{
TempSump = (struct Selection *)AllocRemember(&SumpKey,sizeof(struct Selection),MEMF_CLEAR);
if (TempSump) {
TempSump->SelectedPlot=Pict->Plot;
AddSump(TempSump);
}
else Message("Not enough memory for undelete");
while (Pict->Plot->Continued) Pict->Plot=Pict->Plot->NextPlot;
Pict->Plot=Pict->Plot->NextPlot;
}
else /* Is in the middle of chain */
{
TempPlot=Pict->Plot;
while (TempPlot->NextPlot!=Plot) TempPlot=TempPlot->NextPlot;
TempSump = (struct Selection *)AllocRemember(&SumpKey,sizeof(struct Selection),MEMF_CLEAR);
if (TempSump) {
TempSump->SelectedPlot=Plot;
AddSump(TempSump);
}
else Message("Not enough memory for undelete");
while (TempPlot->NextPlot->Continued)
TempPlot->NextPlot=TempPlot->NextPlot->NextPlot;
TempPlot->NextPlot=TempPlot->NextPlot->NextPlot;
}
Pict->NPlt--;
}
AddSump(NewSump)
struct Selection *NewSump;
{
struct Selection *TempSump;
if (Sump)
{
for (TempSump=Sump;TempSump->NextSelection; TempSump=TempSump->NextSelection) ;
TempSump->NextSelection=NewSump;
}
else Sump=NewSump;
NewSump->NextSelection=NULL;
return(0);
}