diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2018-03-19 19:55:58 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2018-03-19 19:55:58 +0100 |
commit | d1a8285f818eb7e5c3d6a05709ea21a808490b8c (patch) | |
tree | 326578f0505cbed07cfe60de530022822dc237ac /app/bin/cdraw.c | |
parent | 16e9630b79f0a7a90c6cedb6781175bb8b337dc1 (diff) |
New upstream version 5.1.0upstream/5.1.0
Diffstat (limited to 'app/bin/cdraw.c')
-rw-r--r-- | app/bin/cdraw.c | 204 |
1 files changed, 164 insertions, 40 deletions
diff --git a/app/bin/cdraw.c b/app/bin/cdraw.c index efdb51a..418f32a 100644 --- a/app/bin/cdraw.c +++ b/app/bin/cdraw.c @@ -20,12 +20,22 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "track.h" +#include <math.h> +#include <stdint.h> +#include <string.h> + #include "ccurve.h" +#include "cbezier.h" #include "drawgeom.h" +#include "fileio.h" #include "i18n.h" +#include "messages.h" +#include "param.h" +#include "track.h" +#include "utility.h" +#include "misc.h" -#include <stdint.h> +extern TRKTYP_T T_BZRLIN; extern void wSetSelectedFontSize(int size); @@ -200,14 +210,15 @@ static struct { wIndex_t dimenSize; descPivot_t pivot; wIndex_t fontSizeInx; - char text[STR_SIZE]; - LAYER_T layer; + char text[STR_LONG_SIZE]; + unsigned int layer; + char polyType[STR_SIZE]; } drawData; -typedef enum { E0, E1, CE, RA, LN, AL, A1, A2, VC, LW, CO, BE, OR, DS, TP, TA, TS, TX, PV, LY } drawDesc_e; +typedef enum { E0, E1, CE, RA, LN, AL, A1, A2, VC, LW, CO, BE, OR, DS, TP, TA, TS, TX, PV, LY, PT } drawDesc_e; static descData_t drawDesc[] = { -/*E0*/ { DESC_POS, N_("End Pt 1: X"), &drawData.endPt[0] }, -/*E1*/ { DESC_POS, N_("End Pt 2: X"), &drawData.endPt[1] }, -/*CE*/ { DESC_POS, N_("Center: X"), &drawData.center }, +/*E0*/ { DESC_POS, N_("End Pt 1: X,Y"), &drawData.endPt[0] }, +/*E1*/ { DESC_POS, N_("End Pt 2: X,Y"), &drawData.endPt[1] }, +/*CE*/ { DESC_POS, N_("Center: X,Y"), &drawData.center }, /*RA*/ { DESC_DIM, N_("Radius"), &drawData.radius }, /*LN*/ { DESC_DIM, N_("Length"), &drawData.length }, /*AL*/ { DESC_FLOAT, N_("Angle"), &drawData.angle }, @@ -219,12 +230,13 @@ static descData_t drawDesc[] = { /*BE*/ { DESC_LIST, N_("Lumber"), &drawData.benchChoice }, /*OR*/ { DESC_LIST, N_("Orientation"), &drawData.benchOrient }, /*DS*/ { DESC_LIST, N_("Size"), &drawData.dimenSize }, -/*TP*/ { DESC_POS, N_("Origin: X"), &drawData.endPt[0] }, +/*TP*/ { DESC_POS, N_("Origin: X,Y"), &drawData.endPt[0] }, /*TA*/ { DESC_FLOAT, N_("Angle"), &drawData.angle }, /*TS*/ { DESC_EDITABLELIST, N_("Font Size"), &drawData.fontSizeInx }, -/*TX*/ { DESC_STRING, N_("Text"), &drawData.text }, +/*TX*/ { DESC_TEXT, N_("Text"), &drawData.text }, /*PV*/ { DESC_PIVOT, N_("Pivot"), &drawData.pivot }, /*LY*/ { DESC_LAYER, N_("Layer"), &drawData.layer }, +/*PT*/ { DESC_STRING, N_("Type"), &drawData.polyType }, { DESC_NULL } }; int drawSegInx; @@ -241,14 +253,15 @@ static void UpdateDraw( track_p trk, int inx, descData_p descUpd, BOOL_T final ) struct extraData *xx = GetTrkExtraData(trk); trkSeg_p segPtr; coOrd mid; - const char * text; long fontSize; if ( drawSegInx==-1 ) return; - if ( inx == -1 ) - return; segPtr = &xx->segs[drawSegInx]; + if ( inx == -1 ) { + if (segPtr->type != SEG_TEXT) return; + else inx = TX; //Always look at TextField for SEG_TEXT on "Done" + } MainRedraw(); MapRedraw(); UndrawNewTrack( trk ); @@ -286,7 +299,7 @@ static void UpdateDraw( track_p trk, int inx, descData_p descUpd, BOOL_T final ) if ( segPtr->type != SEG_CRVLIN ) { drawData.length = FindDistance( drawData.endPt[0], drawData.endPt[1] ); } else { - drawData.length = segPtr->u.c.radius*2*M_PI*segPtr->u.c.a1/360.0; + drawData.length = fabs(segPtr->u.c.radius)*2*M_PI*segPtr->u.c.a1/360.0; } drawDesc[LN].mode |= DESC_CHANGE; break; @@ -375,12 +388,14 @@ static void UpdateDraw( track_p trk, int inx, descData_p descUpd, BOOL_T final ) segPtr->u.t.fontSize = fontSize; break; case TX: - text = wStringGetValue( (wString_p)drawDesc[TX].control0 ); - if ( text && text[0] && strcmp( segPtr->u.t.string, text ) != 0 ) { + if ( wTextGetModified((wText_p)drawDesc[TX].control0 )) { + int len = wTextGetSize((wText_p)drawDesc[TX].control0); MyFree( segPtr->u.t.string ); - segPtr->u.t.string = MyStrdup( text ); - /*(char*)drawDesc[TX].valueP = segPtr->u.t.string;*/ + segPtr->u.t.string = (char *)MyMalloc(len+1); + wTextGetText((wText_p)drawDesc[TX].control0, segPtr->u.t.string, len+1); + segPtr->u.t.string[len] = '\0'; //Make sure of null term } + break; case LY: SetTrkLayer( trk, drawData.layer); @@ -400,6 +415,7 @@ static void DescribeDraw( track_p trk, char * str, CSIZE_T len ) trkSeg_p segPtr; int inx; char * title = NULL; + char * polyType = NULL; DistanceSegs( xx->orig, xx->angle, xx->segCnt, xx->segs, &pos, &drawSegInx ); @@ -462,7 +478,7 @@ static void DescribeDraw( track_p trk, char * str, CSIZE_T len ) break; case SEG_CRVLIN: REORIGIN( drawData.center, segPtr->u.c.center, xx->angle, xx->orig ); - drawData.radius = segPtr->u.c.radius; + drawData.radius = fabs(segPtr->u.c.radius); drawDesc[CE].mode = drawDesc[RA].mode = 0; if ( segPtr->u.c.a1 >= 360.0 ) { @@ -479,7 +495,7 @@ static void DescribeDraw( track_p trk, char * str, CSIZE_T len ) break; case SEG_FILCRCL: REORIGIN( drawData.center, segPtr->u.c.center, xx->angle, xx->orig ); - drawData.radius = segPtr->u.c.radius; + drawData.radius = fabs(segPtr->u.c.radius); drawDesc[CE].mode = drawDesc[RA].mode = 0; drawDesc[LW].mode = DESC_IGNORE; @@ -488,21 +504,37 @@ static void DescribeDraw( track_p trk, char * str, CSIZE_T len ) case SEG_POLY: drawData.pointCount = segPtr->u.p.cnt; drawDesc[VC].mode = DESC_RO; - title = _("Poly Line"); + drawDesc[PT].mode = DESC_RO; + switch (segPtr->u.p.polyType) { + case RECTANGLE: + polyType = _("Rectangle"); + break; + default: + polyType = _("Freeform"); + } + strncpy( drawData.polyType, polyType, sizeof drawData.polyType ); + title = _("Polygonal Line"); break; case SEG_FILPOLY: drawData.pointCount = segPtr->u.p.cnt; drawDesc[VC].mode = DESC_RO; drawDesc[LW].mode = DESC_IGNORE; + drawDesc[PT].mode = DESC_RO; + switch (segPtr->u.p.polyType) { + case RECTANGLE: + polyType =_("Rectangle"); + break; + default: + polyType = _("Freeform"); + } + strncpy( drawData.polyType, polyType, sizeof drawData.polyType ); title = _("Polygon"); break; case SEG_TEXT: REORIGIN( drawData.endPt[0], segPtr->u.t.pos, xx->angle, xx->orig ); - //drawData.angle = NormalizeAngle( segPtr->u.t.angle ); drawData.angle = NormalizeAngle( xx->angle ); strncpy( drawData.text, segPtr->u.t.string, sizeof drawData.text ); - /*drawData.fontSize = segPtr->u.t.fontSize;*/ - /*(char*)drawDesc[TX].valueP = segPtr->u.t.string;*/ + drawData.text[sizeof drawData.text-1] ='\0'; drawDesc[TP].mode = drawDesc[TS].mode = drawDesc[TX].mode = @@ -541,7 +573,7 @@ static void DescribeDraw( track_p trk, char * str, CSIZE_T len ) static void DrawDraw( track_p t, drawCmd_p d, wDrawColor color ) { struct extraData * xx = GetTrkExtraData(t); - if ( (d->options&DC_QUICK) == 0 ) + if ( (d->funcs->options&DC_QUICK) == 0 ) DrawSegs( d, xx->orig, xx->angle, xx->segs, xx->segCnt, 0.0, color ); } @@ -668,7 +700,7 @@ static ANGLE_T GetAngleDraw( pos.x -= xx->orig.x; pos.y -= xx->orig.y; Rotate( &pos, zero, -xx->angle ); - angle = GetAngleSegs( xx->segCnt, xx->segs, pos, NULL ); + angle = GetAngleSegs( xx->segCnt, xx->segs, &pos, NULL, NULL, NULL, NULL, NULL); if ( ep0 ) *ep0 = -1; if ( ep1 ) *ep1 = -1; return NormalizeAngle( angle + xx->angle ); @@ -767,7 +799,69 @@ EXPORT BOOL_T OnTableEdgeEndPt( track_p trk, coOrd * pos ) return FALSE; } +EXPORT BOOL_T GetClosestEndPt( track_p trk, coOrd * pos) +{ + struct extraData *xx; + + if (GetTrkType(trk) == T_DRAW) { + ignoredTableEdge = NULL; + xx = GetTrkExtraData(trk); + if (xx->segCnt < 1) + return FALSE; + DIST_T dd0,dd1; + coOrd p00,p0,p1; + p00 = *pos; + if (GetTrkType(trk) == T_DRAW) { + Rotate(&p00,xx->orig,-xx->angle); + p00.x -= xx->orig.x; + p00.y -= xx->orig.y; + switch (xx->segs[0].type) { + case SEG_CRVLIN: + PointOnCircle( &p0, xx->segs[0].u.c.center, fabs(xx->segs[0].u.c.radius), xx->segs[0].u.c.a0 ); + dd0 = FindDistance( p00, p0); + PointOnCircle( &p1, xx->segs[0].u.c.center, fabs(xx->segs[0].u.c.radius), xx->segs[0].u.c.a0 + xx->segs[0].u.c.a1); + dd1 = FindDistance( p00, p1); + break; + case SEG_STRLIN: + dd0 = FindDistance( p00, xx->segs[0].u.l.pos[0]); + p0 = xx->segs[0].u.l.pos[0]; + dd1 = FindDistance( p00, xx->segs[0].u.l.pos[1]); + p1 = xx->segs[0].u.l.pos[1]; + break; + case SEG_BEZLIN: + dd0 = FindDistance( p00, xx->segs[0].u.b.pos[0]); + p0 = xx->segs[0].u.b.pos[0]; + dd1 = FindDistance( p00, xx->segs[0].u.b.pos[3]); + p1 = xx->segs[0].u.b.pos[3]; + break; + default: + return FALSE; + } + p0.x += xx->orig.x; + p0.y += xx->orig.y; + Rotate(&p0,xx->orig,xx->angle); + p1.x += xx->orig.x; + p1.y += xx->orig.y; + Rotate(&p1,xx->orig,xx->angle); + } else if (GetTrkType(trk) == T_BZRLIN) { + coOrd p0,p1; + xx = GetTrkExtraData(trk); + p0 = xx->segs[0].u.b.pos[0]; + p1 = xx->segs[0].u.b.pos[3]; + dd0 = FindDistance(p00,p0); + dd1 = FindDistance(p00,p1); + } else return FALSE; + if (dd0>dd1) { + * pos = p1; + return TRUE; + } else { + * pos = p0; + return TRUE; + } + } + return FALSE; +} static void DrawRedraw(void); @@ -783,15 +877,13 @@ static void DrawRedraw( void ) MapRedraw(); } - static wIndex_t benchChoice; static wIndex_t benchOrient; static wIndex_t dimArrowSize; -static wDrawColor lineColor; +wDrawColor lineColor = 1; +long lineWidth = 0; static wDrawColor benchColor; -#ifdef LATER -static wIndex_t benchInx; -#endif + static paramIntegerRange_t i0_100 = { 0, 100, 25 }; static paramData_t drawPLs[] = { @@ -802,7 +894,11 @@ static paramData_t drawPLs[] = { #define drawBenchColorPD (drawPLs[2]) { PD_COLORLIST, &benchColor, "benchcolor", PDO_NORECORD, NULL, N_("Color") }, #define drawBenchChoicePD (drawPLs[3]) - { PD_DROPLIST, &benchChoice, "benchlist", PDO_NOPREF|PDO_NORECORD|PDO_LISTINDEX, (void*)80, N_("Lumber Type") }, +#ifdef WINDOWS + { PD_DROPLIST, &benchChoice, "benchlist", PDO_NOPREF|PDO_NORECORD|PDO_LISTINDEX, (void*)120, N_("Lumber Type") }, +#else + { PD_DROPLIST, &benchChoice, "benchlist", PDO_NOPREF|PDO_NORECORD|PDO_LISTINDEX, (void*)145, N_("Lumber Type") }, +#endif #define drawBenchOrientPD (drawPLs[4]) #ifdef WINDOWS { PD_DROPLIST, &benchOrient, "benchorient", PDO_NOPREF|PDO_NORECORD|PDO_LISTINDEX, (void*)45, "", 0 }, @@ -832,6 +928,7 @@ static char * objectName[] = { N_("Filled Circle"), N_("Filled Box"), N_("Polygon"), + N_("Bezier Line"), NULL}; static STATUS_T CmdDraw( wAction_t action, coOrd pos ) @@ -842,6 +939,8 @@ static STATUS_T CmdDraw( wAction_t action, coOrd pos ) char * labels[3]; static char labelName[40]; + wAction_t act2 = (action&0xFF) | (bezCmdCreateLine<<8); + switch (action&0xFF) { case C_START: @@ -870,6 +969,7 @@ static STATUS_T CmdDraw( wAction_t action, coOrd pos ) case OP_CIRCLE3: case OP_BOX: case OP_POLY: + case OP_BEZLIN: controls[0] = drawWidthPD.control; controls[1] = drawColorPD.control; controls[2] = NULL; @@ -879,6 +979,7 @@ static STATUS_T CmdDraw( wAction_t action, coOrd pos ) InfoSubstituteControls( controls, labels ); drawWidthPD.option &= ~PDO_NORECORD; drawColorPD.option &= ~PDO_NORECORD; + lineWidth = drawCmdContext.Width; break; case OP_FILLCIRCLE2: case OP_FILLCIRCLE3: @@ -935,12 +1036,17 @@ static STATUS_T CmdDraw( wAction_t action, coOrd pos ) infoSubst = FALSE; } ParamGroupRecord( &drawPG ); + if (drawCmdContext.Op == OP_BEZLIN) return CmdBezCurve(act2, pos); DrawGeomMouse( C_START, pos, &drawCmdContext ); return C_CONTINUE; case wActionLDown: ParamLoadData( &drawPG ); + if (drawCmdContext.Op == OP_BEZLIN) { + act2 = action | (bezCmdCreateLine<<8); + return CmdBezCurve(act2, pos); + } if ( drawCmdContext.Op == OP_BENCH ) { drawCmdContext.benchOption = GetBenchData( (long)wListGetItemContext((wList_p)drawBenchChoicePD.control, benchChoice ), benchOrient ); drawCmdContext.Color = benchColor; @@ -963,22 +1069,29 @@ static STATUS_T CmdDraw( wAction_t action, coOrd pos ) case wActionRUp: case wActionText: case C_CMDMENU: - SnapPos( &pos ); + if (drawCmdContext.Op == OP_BEZLIN) return CmdBezCurve(act2, pos); + if (!((MyGetKeyState() & WKEY_SHIFT) != 0)) { + SnapPos( &pos ); + } return DrawGeomMouse( action, pos, &drawCmdContext ); case C_CANCEL: InfoSubstituteControls( NULL, NULL ); + if (drawCmdContext.Op == OP_BEZLIN) return CmdBezCurve(act2, pos); return DrawGeomMouse( action, pos, &drawCmdContext ); case C_OK: + if (drawCmdContext.Op == OP_BEZLIN) return CmdBezCurve(act2, pos); return DrawGeomMouse( (0x0D<<8|wActionText), pos, &drawCmdContext ); /*DrawOk( NULL );*/ case C_FINISH: + if (drawCmdContext.Op == OP_BEZLIN) return CmdBezCurve(act2, pos); return DrawGeomMouse( (0x0D<<8|wActionText), pos, &drawCmdContext ); /*DrawOk( NULL );*/ case C_REDRAW: + if (drawCmdContext.Op == OP_BEZLIN) return CmdBezCurve(act2, pos); return DrawGeomMouse( action, pos, &drawCmdContext ); default: @@ -1004,6 +1117,7 @@ static STATUS_T CmdDraw( wAction_t action, coOrd pos ) #include "bitmaps/dfilbox.xpm" #include "bitmaps/dpoly.xpm" #include "bitmaps/dfilpoly.xpm" +#include "bitmaps/dbezier.xpm" typedef struct { char **xpm; @@ -1023,7 +1137,8 @@ static drawData_t dcurveCmds[] = { { dcurve1_xpm, OP_CURVE1, N_("Curve End"), N_("Draw Curve from End"), "cmdDrawCurveEndPt", ACCL_DRAWCURVE1 }, { dcurve2_xpm, OP_CURVE2, N_("Curve Tangent"), N_("Draw Curve from Tangent"), "cmdDrawCurveTangent", ACCL_DRAWCURVE2 }, { dcurve3_xpm, OP_CURVE3, N_("Curve Center"), N_("Draw Curve from Center"), "cmdDrawCurveCenter", ACCL_DRAWCURVE3 }, - { dcurve4_xpm, OP_CURVE4, N_("Curve Chord"), N_("Draw Curve from Chord"), "cmdDrawCurveChord", ACCL_DRAWCURVE4 } }; + { dcurve4_xpm, OP_CURVE4, N_("Curve Chord"), N_("Draw Curve from Chord"), "cmdDrawCurveChord", ACCL_DRAWCURVE4 }, + { dbezier_xpm, OP_BEZLIN, N_("Bezier Curve"), N_("Draw Bezier"), "cmdDrawBezierCurve", ACCL_DRAWBEZLINE } }; static drawData_t dcircleCmds[] = { /*{ dcircle1_xpm, OP_CIRCLE1, "Circle Fixed Radius", "Draw Fixed Radius Circle", "cmdDrawCircleFixedRadius", ACCL_DRAWCIRCLE1 },*/ { dcircle2_xpm, OP_CIRCLE3, N_("Circle Tangent"), N_("Draw Circle from Tangent"), "cmdDrawCircleTangent", ACCL_DRAWCIRCLE2 }, @@ -1052,12 +1167,11 @@ static drawStuff_t drawStuff[4]; static drawStuff_t drawStuff[4] = { { "cmdDrawLineSetCmd", N_("Straight Objects"), N_("Draw Straight Objects"), 4, dlineCmds }, - { "cmdDrawCurveSetCmd", N_("Curved Lines"), N_("Draw Curved Lines"), 4, dcurveCmds }, + { "cmdDrawCurveSetCmd", N_("Curved Lines"), N_("Draw Curved Lines"), 5, dcurveCmds }, { "cmdDrawCircleSetCmd", N_("Circle Lines"), N_("Draw Circles"), 4, dcircleCmds }, { "cmdDrawShapeSetCmd", N_("Shapes"), N_("Draw Shapes"), 4, dshapeCmds} }; - static void ChangeDraw( long changes ) { wIndex_t choice, orient; @@ -1079,6 +1193,15 @@ static void DrawDlgUpdate( int inx, void * valueP ) { + if (drawCmdContext.Op == OP_BEZLIN) { + if ( (inx == 0 && pg->paramPtr[inx].valueP == &drawCmdContext.Width) || + (inx == 1 && pg->paramPtr[inx].valueP == &lineColor)) + { + lineWidth = drawCmdContext.Width; + UpdateParms(lineColor, lineWidth); + } + } + if ( inx >= 0 && pg->paramPtr[inx].valueP == &benchChoice ) BenchUpdateOrientationList( (long)wListGetItemContext( (wList_p)drawBenchChoicePD.control, (wIndex_t)*(long*)valueP ), (wList_p)drawBenchOrientPD.control ); } @@ -1108,9 +1231,7 @@ EXPORT void InitCmdDraw( wMenu_p menu ) ParamRegister( &drawPG ); RegisterChangeNotification( ChangeDraw ); -#ifdef LATER - InitCommand( cmdDraw, N_("Draw"), draw_bits, LEVEL0_50, IC_POPUP|IC_CMDMENU, ACCL_DRAW ); -#endif + } @@ -1168,7 +1289,6 @@ EXPORT track_p NewText( return trk; } - EXPORT BOOL_T ReadText( char * line ) { coOrd pos; @@ -1190,6 +1310,10 @@ EXPORT BOOL_T ReadText( char * line ) return FALSE; } + char * old = text; + text = ConvertFromEscapedText(text); + MyFree(old); + trk = NewText( index, pos, angle, text, textSize, color ); SetTrkLayer( trk, layer ); MyFree(text); |