// vischer@science.uva.nl //14.11.13 14:43 includes dialog to change species and range var lastObj, lastCX, lastCY, lastRad, lastState, running=false, theTool =-102;//102 or 15 macro "Init [F1]"{ ojRequires("0.93x"); ojShowTools(); li = ojImageLink(); if (li > 0) ojShowImage(li); ojSetTool(theTool); // ojSetTool(15); lastState = 0; lastObj = 0; run("Select None"); } macro "Abort [F2]"{ if (lastObj>0 && lastObj <= ojNObjects()) ojDeleteObject(lastObj); ojSetTool(theTool); lastState = 0; lastObj = 0; run("Select None"); } macro "Calc + Show Results [F3]"{ for (obj = 1; obj <=ojNObjects(); obj++) calc(obj); ojSetColumnProperty("SpPhi", "visible", 0); ojSetColumnProperty("StPhi", "visible", 0); ojShowResults(); } macro "Properties of current object [F4]"{ obj = ojSelectedObject(); if (obj == 0) obj = getNumber("Enter object to edit", 0); if (obj == 0) exit; ojSelectObject(obj); dia = ojResult("Dia", obj); oil = ojResult("Oil", obj); name = ojResultString("Fname", obj); species = ojResult("Species", obj); stage = ojResult("Stage", obj); dia = ojResult("Dia", obj); Dialog.create("Egg Properties"); Dialog.addMessage("Image Name: "+ name); Dialog.addMessage("Object #: "+ obj); Dialog.addMessage("Dia: " + dia); Dialog.addMessage("Oil: " + oil); Dialog.addNumber("Species:", species); Dialog.addNumber("Stage:", stage); Dialog.show(); newSpecies = Dialog.getNumber();; newStage = Dialog.getNumber(); ojSelectItem("Peri", 1); centerX = ojXPos(6); //6 o'clock centerY = ojYPos(9); //9 o'clock; rad = ojXPos(3) - centerX;//3 oclock - center if (newSpecies != species) changeSpecOrStage(obj, centerX, centerY, rad, "Species", newSpecies); if (newStage != stage) changeSpecOrStage(obj, centerX, centerY, rad, "Stage", newStage); } macro "Number 1 [1]"{ setSpeciesOrStage(1);} macro "Number 2 [2]"{ setSpeciesOrStage(2);} macro "Number 3 [3]"{ setSpeciesOrStage(3);} macro "Number 4 [4]"{ setSpeciesOrStage(4);} macro "Number 5 [5]"{ setSpeciesOrStage(5);} macro "Number 6 [6]"{ setSpeciesOrStage(6);} macro "Number 7 [7]"{ setSpeciesOrStage(7);} macro "Number 8 [8]"{ setSpeciesOrStage(8);} macro "Number 9 [9]"{ setSpeciesOrStage(9);} macro "Number 10 [0]"{ setSpeciesOrStage(10);} function setSpeciesOrStage(nnn){ while (running); running = true; if (lastState == 0){ getCursorLoc(lastCX, lastCY, z, flags); markCircle(lastCX, lastCY, 35, 11); //r=35, clock with 11 points lastObj = ojGetOpenObject(); lastRad = 70; lastState = 7; } obj = lastObj; ojOpenObject(obj); if (lastState <= 2){ ojSwitchToItem("Species"); start = 0.5; lastState = 2; } if (lastState == 3){ ojSwitchToItem("Stage"); start = 0.75; } if (lastState == 7){ ojSwitchToItem("Species"); start = 0.5; } beta = PI/6*(nnn-3); xinner= lastCX + start*lastRad*cos(beta); yinner= lastCY + start*lastRad*sin(beta); xouter= lastCX + lastRad*cos(beta); youter= lastCY + lastRad*sin(beta); ojSetMarker(xinner, yinner); ojSetMarker(xouter, youter); ojCloseObject(); calc(obj); lastState++; if (lastState >3){ ojSetTool(theTool); lastState = 0; lastObj = 0; run("Select None"); } running = false; } macro "Dummy Tool - "{ } macro "Egg Tool - C00fO22dd"{ doTrack(); } function doTrack(){ while(running); running = true; leftButton=16; rightButton=4; shift=1; ctrl=2; alt=8; rad0 = 55; getCursorLoc(x0, y0, z, flags); if (lastState > 0){ ojOpenObject(lastObj); rad0 = 7; } makeOval(x0 - rad0, y0, rad0*2, rad0*2); x1 =x0; y1=y0; offx = 0; rad = rad0; while (flags & leftButton != 0){ getCursorLoc(x2, y2, z, flags); if (x2 != x1 || y2 != y1 ){ dx = x2 - x0; dy = y2 - y0; rad = rad0 + 0.2 * dy; offx = dx * 0.25; makeOval(x0 + offx - rad, y0 , rad*2, rad*2); } x0=x1; y0=y1; } if (lastState == 0){ ojSwitchToItem("Peri"); nPoints = 12; } else{ ojSwitchToItem("Oil"); nPoints = 6; } markCircle(x0 + offx, y0+rad, rad, nPoints); //run("Select None"); if (lastState == 0){ lastObj = ojGetOpenObject(); lastCX = x0 + offx; lastCY = y0 + rad; lastRad = rad; } if (lastState <=1) ojSetTool(theTool); lastState++; makeRectangle(lastCX - lastRad, lastCY - lastRad, lastRad*2, lastRad*2); running = false; } function markCircle(xc, yc, rad, nPoints){ for (bb = 10; bb < 10+nPoints; bb++ ){ denum = nPoints; if (denum == 11) denum = 12; phi = -bb * 2*PI/denum; xx = xc + rad *cos(phi); yy = yc - rad *sin(phi); ojSetMarker(xx, yy); //ojCloseObject(); } } function calc(obj){ phi = ojResult("StPhi", obj); num = 15 - round(phi/30); if (num > 12) num -=12; if (isNaN(phi)) num = NaN; ojSetResult("Stage", obj, num); phi = ojResult("SpPhi", obj); num = 15 - round(phi/30); if (num > 12) num -=12; if (isNaN(phi)) num = NaN; ojSetResult("Species", obj, num); } function changeSpecOrStage(obj, cx, cy, rad, itemType, nnn){ if (lastState <= 2){ ojSwitchToItem(itemType); if (itemType == "Stage") start = 0.75; if (itemType == "Species") start = 0.5; } beta = PI/6*(nnn-3); xinner= cx + start*rad*cos(beta); yinner= cy + start*rad*sin(beta); xouter= cx + rad*cos(beta); youter= cy + rad*sin(beta); ojSelectObject(obj); if (ojNItems(itemType) > 0){ ojSelectItem(itemType, 1); if (nnn == 0) ojDeleteItem(itemType, 1); else{ ojMovePoint(1, xinner, yinner, -1); ojMovePoint(2, xouter, youter, -1); } } else{ ojShowObject(obj); ojOpenObject(obj); ojSwitchToItem(itemType); ojSetMarker(xinner, yinner); ojSetMarker(xouter, youter); ojCloseObject(); } ojSelectObject(obj); calc(obj); }