/* DISTANCE (STD) -- Distance Query */ /* DISTANCE (STD) -- Distanzabfrage */ /* // Copyright (c) 1997-2012 Oliver Bartels F+E, Muenchen // Author: Manfred Baumeister // Changes History: // rl (120427) RELEASED FOR BAE V7.8. // rl (101019) RELEASED FOR BAE V7.6. // rl (091020) RELEASED FOR BAE V7.4. // rl (081014) RELEASED FOR BAE V7.2. // rl (071029) RELEASED FOR BAE V7.0. // rl (060829) RELEASED FOR BAE V6.8. // rl (050906) RELEASED FOR BAE V6.6. // rl (040811) RELEASED FOR BAE V6.4. // rl (030912) RELEASED FOR BAE V6.2. // rl (021210) RELEASED FOR BAE V6.0. // rl (021210) BUGFIX: // Fixed problem with double interactions during 'p' key usage. // rl (020726) ENHANCEMENT: // Added display of pick position coordinates and temporary // distance marker. // rl (020618) RELEASED FOR BAE V5.4. // rl (010625) RELEASED FOR BAE V5.0. // rl (000616) RELEASED FOR BAE V4.6. // rl (990625) RELEASED FOR BAE V4.4. // rl (980910) RELEASED FOR BAE V4.2. // mb (980710) ENHANCEMENT: // Dynamic multi-language support introduced. // rl (980420) IMPROVEMENT: // Allow for use in CAM View. // rl (970929) RELEASED FOR BAE V4.0. // mb (970711) IMPROVEMENT: // Included angle display with distance report. // mb (970422) ORIGINAL CODING. // // DESCRIPTION // // The distance User Language program displays absolute, horizontal (X), // and vertical (Y) distances and the angle between two interactively // selectable points. The length units for the distance display are // initially retrieved from the current coordinate display mode and // may be changed on request. */ // Includes #include "pop.ulh" // User Language popup utilities // Enforce standard caller type #pragma ULCALLERSTD // Disable undo state request #pragma ULCALLERNOUNDO // Messages string UPRABORT = M_UPRABORT(); string REPDISTHD = M("Distanzabfrage :","Distance Query :" ); string REPDISTA = M(" Distanz absolut = %12.*f %s", " Distance Absolute = %12.*f %s"); string REPDISTH = M(" Distanz horizontal = %12.*f %s", " Distance Horizontal = %12.*f %s"); string REPDISTV = M(" Distanz vertikal = %12.*f %s", " Distance Vertical = %12.*f %s"); string REPPOS1 = M(" Position 1: X %.*f %s, Y %.*f %s", " Position 1: X %.*f %s, Y %.*f %s"); string REPPOS2 = M(" Position 2: X %.*f %s, Y %.*f %s", " Position 2: X %.*f %s, Y %.*f %s"); string REPANGLE = M(" Winkel = %12.3f [DEG]", " Angle = %12.3f [DEG]"); string UPRDPOS1 = M("Distanz-Startposition waehlen!", "Select Distance Start Position!"); string UPRDPOS2 = M("Distanz-Endposition waehlen!", "Select Distance End Position!"); string UPRMPOS1 = M("Marker Startposition waehlen!", "Select Distance Start Position!"); string UPRMPOS2 = M("Marker Endposition waehlen!", "Select Distance End Position!"); string UPRDONE = M("&Fertig","&Done"); string UPRCONT = M("&Weiter","&Continue"); string UPRJUMPREL = M("%Sprung relati&v","%Jump Relati&ve"); string UPRJUMPABS = M("&Sprung absolut","&Jump Absolute"); string UPRMARKLINE = M("%&Markerlinie setzen","%Set &Marker Line"); string POPBUTCONT = M("[Weiter]","[Continue]"); string POPBUTABORT = M("[Abbruch]","[Abort]"); // INI file parameter name definitions #define PAR_DPRECM "DPRECM_STD" // m dist. digits after decimal point #define PAR_DPRECINCH "DPRECINCH_STD" // Inch dist. digits after dec. point #define PAR_DPRECMM "DPRECMM_STD" // mm dist. digits after decimal point #define PAR_DPRECMIL "DPRECMIL_STD" // mil dist. digits after dec. point #define PAR_DPRECUM "DPRECUM_STD" // um dist. digits after decimal point #define PAR_DISTDLAY "DISTDLAY_GED" // Layout distance documentary layer // Distance measure declarations #define ITMM "[m]" // m units item #define ITMMM "[mm]" // mm units item #define ITMINCH "[Inch]" // Inch units item #define ITMMIL "[Mil]" // Mil units item #define ITMUM "[um]" // um units item #define DITMM "m" // m units dialog box item #define DITMMM "&mm" // mm units dialog box item #define DITMINCH "&Inch" // Inch units dialog box item #define DITMMIL "Mi&l" // Mil units dialog box item #define DITMUM "&um" // um units dialog box item #define UNITSM 0 // m units code #define UNITSINCH 1 // Inch units code #define UNITSMM 2 // mm units code #define UNITSMIL 3 // mil units code #define UNITSUM 4 // um units code int PRECM = bae_iniintval(PAR_DPRECM,7); // m units precision int PRECINCH = bae_iniintval(PAR_DPRECINCH,5); // Inch units precision int PRECMM = bae_iniintval(PAR_DPRECMM,3); // mm units precision int PRECMIL = bae_iniintval(PAR_DPRECMIL,2); // mil units precision int PRECUM = bae_iniintval(PAR_DPRECUM,3); // um units precision int dlayer = bae_iniintval(PAR_DISTDLAY,1025); // Distance vector layer index L_FIGURE lmfig /* Layout marker figure list index */; index C_FIGURE smfig /* Schematic marker fig. list index */; int laymarkpoly = 0 /* Layout marker polygon flag */; int scmmarkpoly = 0 /* Schematic marker polygon flag */; int firstmark = 1 /* First marker polygon flag */; int infodisp /* Information display mode */; int callertype = uliptype() /* Calling environment type */; int rutactive = 0 /* Autorouter active flag */; int unsavedplan = bae_plannotsaved() /* Unsaved plan flag */; // Main program void main() { // Abort if invalid plan class if (bae_planddbclass()==DDBCLUNDEF) error_class(); // Perform the distance query distquery(); } // Distance query routines static void distquery() /* // Perform distance query, display distance info with popup */ { double x1,y1 /* Distance start coordinates */; double x2,y2 /* Distance end coordinates */; int unitcode /* Units code */; int anglock /* Angle lock flag */; int danglock = 0 /* Desired angle lock flag */; int gridlock /* Grid lock flag */; int dgridlock = 0 /* Desired grid lock flag */; int newdist = 1 /* New dist. query request flag */; int abort = 0 /* Abort flag */; // Init units code according to current coordinate display mode unitcode= bae_getcoorddisp() ? UNITSINCH : callertype==ULIPCED ? UNITSUM : UNITSMM; if (callertype==ULIPGED) { if (ged_getintpar(3,infodisp)) infodisp=0; if (ged_getintpar(107,rutactive)) rutactive=0; } else { infodisp=1; } // Store the old grid and angle lock modes gridlock=bae_getgridlock(); anglock=bae_getanglelock(); // Loop until abort request while (!abort) { // Check if new distance query required if (newdist) { // Set desired grid and angle lock bae_setgridlock(dgridlock); bae_setanglelock(danglock); // Select distance start and end coordinates bae_promptdialog(UPRDPOS1); if (bae_inpointmenu(bae_planwsnx(),bae_planwsny(), x1,y1,0,inpdatafunc) || (bae_promptdialog(UPRDPOS2), bae_inpoint(x1,y1,x2,y2,infodisp ? 4 : 2))) { // Restore the grid and angle lock and abort bae_setgridlock(gridlock); bae_setanglelock(anglock); // Delete any marker line if (laymarkpoly) ged_delelem(lmfig); if (scmmarkpoly) scm_delelem(smfig); bae_postprocess(); bae_setintpar(21,unsavedplan); error_abort(); } // Get the desired grid and angle lock modes dgridlock=bae_getgridlock(); danglock=bae_getanglelock(); // Restore the grid and angle lock bae_setgridlock(gridlock); bae_setanglelock(anglock); // Delete any marker line if (laymarkpoly) { ged_delelem(lmfig); laymarkpoly=0; } if (scmmarkpoly) { scm_delelem(smfig); scmmarkpoly=0; } bae_postprocess(); bae_setintpar(21,unsavedplan); // Reset the new distance query request flag newdist=0; } // Display distance query popup switch (distancepopup(unitcode,x1,y1,x2,y2)) { // Continue with new distance query case POPBUTCONT : newdist=1; break; // Switch to Inch units case ITMINCH : unitcode=UNITSINCH; break; // Switch to mil units case ITMMIL : unitcode=UNITSMIL; break; // Switch to millimetre units case ITMMM : unitcode=UNITSMM; break; // Switch to metre units case ITMM : unitcode=UNITSM; break; // Switch to micrometre units case ITMUM : unitcode=UNITSUM; break; // Abort on default default : abort=1; } } } static string units(int unitcode) /* // Get units identifier from units code // Return value : // units identifier/item string or empty string on inv. units code // Parameters : // int unitcode : Units code */ { // Check for valid units code; return the units item switch (unitcode) { case UNITSINCH : return(ITMINCH); case UNITSMIL : return(ITMMIL); case UNITSMM : return(ITMMM); case UNITSUM : return(ITMUM); case UNITSM : return(ITMM); } // Assume invalid units code return(""); } static int precision(int unitcode) /* // Get units-specific precision // Return value : // units-specific precision or mm precision on inv. units code // Parameters : // int unitcode : Units code */ { // Check for valid units code; return the precision switch (unitcode) { case UNITSINCH : return(PRECINCH); case UNITSMIL : return(PRECMIL); case UNITSMM : return(PRECMM); case UNITSUM : return(PRECUM); case UNITSM : return(PRECM); } // Assume invalid units code return(PRECMM); } double getangle(double sx,double sy,double ex,double ey) /* // Get a segment angle // Return value : // resulting angle value (in radians; 0..2*PI) // Parameters : // double sx : Segment start point X coordinate // double sy : Segment start point Y coordinate // double ex : Segment end point X coordinate // double ey : Segment end point Y coordinate */ { double res /* Result value */; // Check if degenerated segment if (ey==sy && ex==sx) return(0.0); // Get arc tangent of angle defined by segment vector res=atan2(ey-sy,ex-sx); // Test the result if (res<0.0) // Get the "absolute" angle value res+=2*cvtangle(180.0,1,2); // Return the result value return(res); } static string distancepopup(int unit, double sx,double sy,double ex,double ey) /* // Display the distance query popup // Return value : // answer string // Parameters : // int unit : Units code // double sx : Distance start point X coordinate // double sy : Distance start point Y coordinate // double ex : Distance end point X coordinate // double ey : Distance end point Y coordinate */ { // Define color values #define COLOR_PDBACK 1 // Pulldown menu background color #define COLOR_MSG 15 // Standard info display color index L_FIGURE lfig /* Layout figure list index */; index C_FIGURE sfig /* Schematic figure list index */; int row /* Popup row */; int col /* Popup column */; double height /* Popup percentage height */; double width /* Popup percentage width */; double mlx,mly /* Popup window lower percentage */; double mux,muy /* Popup window upper percentage */; double hd = fabs(ex-sx) /* Horizontal distance */; double vd = fabs(ey-sy) /* Vertical distance */; string s1,s2,s3,s4,s5,s6,s7 /* Popup message string buffers */; string un /* Units item string */; string answer /* Answer string */; int prec /* Units-specific precision */; int maxlen /* Maximum message length */; string msg /* Message buffer */; double cy /* Dialog box current y coordinate */; int repflag /* Dialog box repeat flag */; int dellaypoly = 0 /* Delete layout polygon flag */; int delscmpoly = 0 /* Delete schematic polygon flag */; // Create marker lines in editor environments if (callertype==ULIPGED && !rutactive) { bae_clearpoints(); bae_storepoint(sx,sy,0); bae_storepoint(ex,ey,0); if (ged_storepoly(dlayer,L_POLYDOCLINE,"",0)==0 && lay_lastfigelem(lfig)==0) dellaypoly=1; } else if (callertype==ULIPSCM) { bae_clearpoints(); bae_storepoint(sx,sy,0); bae_storepoint(ex,ey,0); if (scm_storepoly(C_POLYDOCLINE)==0 && cap_lastfigelem(sfig)==0) delscmpoly=1; } // Get the user coordinates sx-=bae_planwsnx(); sy-=bae_planwsny(); ex-=bae_planwsnx(); ey-=bae_planwsny(); // Build the distance display messages sprintf(s1,REPDISTHD); un=units(unit); prec=precision(unit); sprintf(s2,REPDISTA,prec,cvtlength(sqrt(hd*hd+vd*vd),0,unit),un); sprintf(s3,REPDISTH,prec,cvtlength(hd,0,unit),un); sprintf(s4,REPDISTV,prec,cvtlength(vd,0,unit),un); sprintf(s5,REPANGLE,cvtangle(getangle(sx,sy,ex,ey),2,1)); sprintf(s6,REPPOS1, prec,cvtlength(sx,0,unit),un,prec,cvtlength(sy,0,unit),un); sprintf(s7,REPPOS2, prec,cvtlength(ex,0,unit),un,prec,cvtlength(ey,0,unit),un); // Check if dialog box support if (bae_dialclr()) { // Get the maximum message length maxlen=maxint( maxint(strlen(s1),strlen(s2)),maxint( maxint(strlen(s3),strlen(s4)),maxint(strlen(s7),strlen(s6)))); // Enlarge maximum message length for buttons to fit maxlen=maxint(maxlen, 7+strlen(POPBUTCONT)+strlen(POPBUTABORT)+ strlen(ITMINCH)+strlen(ITMMIL)+ strlen(ITMMM)+strlen(ITMUM)+strlen(ITMM)); // Get popup rows count row=12; // Get popup columns count col=maxlen+7; // Calculate the popup height height=calcpopheight(row); // Calculate the popup width width=calcpopwidth(col); // Set popup menu lower boundaries for center alignment mlx=(1.0-width)/2.0; mly=(1.0-height)/2.0; // Set the upper popup menu boundaries mux=mlx+width; muy=mly+height; // Display the popup menu bae_popshow(row,col,mlx,mly,mux,muy); // Re-init the start position row=col=0; // Display the message type denoter bae_popcolbar(row,col,row+6,col+4,COLOR_PDBACK); // Issue standard info (draw 'i') bae_popcolbar(row+1,col+2,row+1,col+2,COLOR_MSG); bae_popcolbar(row+3,col+1,row+3,col+1,COLOR_MSG); bae_popcolbar(row+3,col+2,row+5,col+2,COLOR_MSG); bae_popcolbar(row+5,col+3,row+5,col+3,COLOR_MSG); // Display the message bae_poptext(row+0,col+6,s1); bae_poptext(row+2,col+6,s2); bae_poptext(row+3,col+6,s3); bae_poptext(row+4,col+6,s4); bae_poptext(row+5,col+6,s5); bae_poptext(row+7,col+6,s6); bae_poptext(row+8,col+6,s7); // Set the row and column numbers row+=10; col+=7; // Display the continue button bae_poptextchoice(row,col,POPBUTCONT,POPBUTCONT); col+=1+strlen(POPBUTCONT); // Display the abort button bae_poptextchoice(row,col,POPBUTABORT,POPBUTABORT); col+=1+strlen(POPBUTABORT); // Display the Inch button if (unit!=UNITSINCH) bae_poptextchoice(row,col,ITMINCH,ITMINCH); else bae_poptext(row,col,ITMINCH); col+=1+strlen(ITMINCH); // Display the mil button if (unit!=UNITSMIL) bae_poptextchoice(row,col,ITMMIL,ITMMIL); else bae_poptext(row,col,ITMMIL); col+=1+strlen(ITMMIL); // Display the m button if (unit!=UNITSM) bae_poptextchoice(row,col,ITMM,ITMM); else bae_poptext(row,col,ITMM); col+=1+strlen(ITMM); // Display the mm button if (unit!=UNITSMM) bae_poptextchoice(row,col,ITMMM,ITMMM); else bae_poptext(row,col,ITMMM); col+=1+strlen(ITMMM); // Display the um button if (unit!=UNITSUM) bae_poptextchoice(row,col,ITMUM,ITMUM); else bae_poptext(row,col,ITMUM); col+=1+strlen(ITMUM); // Get the answer string answer=bae_readtext("",MAXKEYLEN); // Restore the popup area bae_poprestore(); } else { // Build the message string msg= s1+"\n\n"+s2+"\n"+s3+"\n"+s4+"\n"+s5+"\n\n"+s6+"\n"+s7+"\n"; bae_prtdialog(""); // Init. the y coordinate cy=DIAL_TOPMARG; bae_dialaddcontrol(PA_ACT,0,0,0,0.0,0.0,0.0,"", 0,DIAL_LEFTMARG,cy+5.4+1.4,0.0,UPRCONT); bae_dialadvcontrol(PA_STR|PA_NOEDIT|PA_FNTFIX|PA_HBRDREL, 0,0,0,0.0,0.0,0.0,msg,2.0*strlen(msg), DIAL_LEFTMARG,cy,DIAL_RIGHTSMARG,5.0,""); cy+=5.4; // Store format controls bae_dialaddcontrol(PA_RBF,1,1,unit,0.0,0.0,0.0, "",0,DIAL_LEFTMARG,cy,0.0,DITMINCH); bae_dialaddcontrol(PA_RBN,3,2,0,0.0,0.0,0.0, "",0,DIAL_LEFTMARG+10.0,cy,0.0,DITMMIL); bae_dialaddcontrol(PA_RBN,0,3,0,0.0,0.0,0.0, "",0,DIAL_LEFTMARG+20.0,cy,0.0,DITMM); bae_dialaddcontrol(PA_RBN,2,4,0,0.0,0.0,0.0, "",0,DIAL_LEFTMARG+30.0,cy,0.0,DITMMM); bae_dialaddcontrol(PA_RBN,4,5,0,0.0,0.0,0.0, "",0,DIAL_LEFTMARG+40.0,cy,0.0,DITMUM); // Store the OK and abort button with seperator cy+=1.4; bae_dialaddcontrol(PA_ABORT,0,0,0,0.0,0.0,0.0,"", 0,DIAL_LEFTMARG+8.0,cy,0.0,""); bae_dialaddcontrol(PA_HSEP|PA_HBRDREL,0,0,0,0.0,0.0,0.0,"", 0,0.0,cy-0.4,DIAL_RIGHTSMARG,""); // Perform the dialog input loop repflag=1; do { // Call the dialog function bae_setintpar(16,5003); switch (bae_dialaskparams( " ",0,DIAL_LEFTMARG+51.7,cy+1.6)) { // Next distance case 0 : answer=POPBUTCONT; repflag=0; break; // Units inch case 1 : answer=ITMINCH; repflag=0; break; // Units mil case 2 : answer=ITMMIL; repflag=0; break; // Units m case 3 : answer=ITMM; repflag=0; break; // Units mm case 4 : answer=ITMMM; repflag=0; break; // Units um case 5 : answer=ITMUM; repflag=0; break; // Fail/abort case (-1) : default : // Delete any marker line if (dellaypoly) ged_delelem(lfig); if (delscmpoly) scm_delelem(sfig); bae_postprocess(); bae_setintpar(21,unsavedplan); error_abort(); } // Stop if no further repeat requests } while (repflag); } // Delete any marker line if (dellaypoly) ged_delelem(lfig); if (delscmpoly) scm_delelem(sfig); bae_postprocess(); bae_setintpar(21,unsavedplan); // Return the answer return(answer); } int inpdatafunc(double x,double y) /* // RMB input callback function // Return value : // 1 to continue, 0 to set coordinates or (-1) on error // Parameters : // double x, y : Mouse coordinates */ { double sx, sy /* Marker start coordinates */; double ex, ey /* Marker end coordinates */; // Evaluate the selection switch (bae_askmenu(6,UPRDONE,UPRCONT,UPRJUMPREL, UPRJUMPABS,UPRMARKLINE,UPRABORT)) { // Done case 0 : return(0); // Continue case 1 : break; // Jump. relative case 2 : x=bae_planwsnx(); y=bae_planwsny(); if (askcoord(x,y,0)) error_abort(); return(0); // Jump. absolute case 3 : x=bae_planwsnx(); y=bae_planwsny(); if (askcoord(x,y,1)) error_abort(); return(0); // Set marker line case 4 : // Delete any old marker line if (laymarkpoly) { ged_delelem(lmfig); laymarkpoly=0; } if (scmmarkpoly) { scm_delelem(smfig); scmmarkpoly=0; } bae_postprocess(); bae_setintpar(21,unsavedplan); // Select marker start and end coordinates bae_promptdialog(UPRMPOS1); if (bae_inpoint(bae_planwsnx(),bae_planwsny(),sx,sy,0) || (bae_promptdialog(UPRMPOS2), bae_inpoint(sx,sy,ex,ey,infodisp ? 4 : 2))) break; if (callertype==ULIPGED && !rutactive) { // Save current state for undo if (firstmark) { bae_callmenu(MNU_BAESAVESTATE); firstmark=0; } bae_clearpoints(); bae_storepoint(sx,sy,0); bae_storepoint(ex,ey,0); if (ged_storepoly(dlayer,L_POLYDOCLINE,"",0)==0 && lay_lastfigelem(lmfig)==0) laymarkpoly=1; } else if (callertype==ULIPSCM) { // Save current state for undo if (firstmark) { bae_callmenu(MNU_BAESAVESTATE); firstmark=0; } bae_clearpoints(); bae_storepoint(sx,sy,0); bae_storepoint(ex,ey,0); if (scm_storepoly(C_POLYDOCLINE)==0 && cap_lastfigelem(smfig)==0) scmmarkpoly=1; } break; // Abort case 5 : default : return(-1); } // Continue bae_promptdialog(UPRDPOS1); return(1); } // User Language program end