summaryrefslogtreecommitdiff
path: root/app/bin/cmodify.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/bin/cmodify.c')
-rw-r--r--app/bin/cmodify.c153
1 files changed, 134 insertions, 19 deletions
diff --git a/app/bin/cmodify.c b/app/bin/cmodify.c
index 6828ff9..594d742 100644
--- a/app/bin/cmodify.c
+++ b/app/bin/cmodify.c
@@ -1,6 +1,4 @@
-/*
- * $Header: /home/dmarkle/xtrkcad-fork-cvs/xtrkcad/app/bin/cmodify.c,v 1.4 2008-03-06 19:35:05 m_fischer Exp $
- *
+/** \file cmodify.c
* TRACK MODIFY
*/
@@ -22,18 +20,20 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#include "track.h"
+#include <math.h>
+
#include "cjoin.h"
#include "ccurve.h"
+#include "cbezier.h"
+#include "ccornu.h"
#include "cstraigh.h"
+#include "cundo.h"
+#include "fileio.h"
#include "i18n.h"
-
-/*****************************************************************************
- *
- * MODIFY
- *
- */
-
+#include "messages.h"
+#include "param.h"
+#include "track.h"
+#include "utility.h"
static struct {
track_p Trk;
@@ -49,12 +49,73 @@ static struct {
static int log_modify;
+static BOOL_T modifyBezierMode;
+static BOOL_T modifyCornuMode;
+
+/*
+ * Call cbezier.c CmdBezModify to alter Bezier Track and Lines.
+ * Picking a Bezier will allow control point(s) modifications until terminated with "Enter"
+ */
+static STATUS_T ModifyBezier(wAction_t action, coOrd pos) {
+ STATUS_T rc = C_CONTINUE;
+ if (Dex.Trk == NULL) return C_ERROR; //No track picked yet!
+ switch (action&0xFF) {
+ case C_START:
+ case C_DOWN:
+ case C_MOVE:
+ case C_UP:
+ case C_OK:
+ case C_TEXT:
+ rc = CmdBezModify(Dex.Trk, action, pos);
+ break;
+ case C_TERMINATE:
+ rc = CmdBezModify(Dex.Trk, action, pos);
+ Dex.Trk = NULL;
+ modifyBezierMode = FALSE;
+ break;
+ case C_REDRAW:
+ rc = CmdBezModify(Dex.Trk, action, pos);
+ break;
+ }
+ return rc;
+}
+
+/*
+ * Call ccornu.c CmdCornuModify to alter Cornu Track and Lines.
+ * Picking a Cornu will allow end point(s) modifications until terminated with "Enter"
+ */
+static STATUS_T ModifyCornu(wAction_t action, coOrd pos) {
+ STATUS_T rc = C_CONTINUE;
+ if (Dex.Trk == NULL) return C_ERROR; //No track picked yet!
+ switch (action&0xFF) {
+ case C_START:
+ case C_DOWN:
+ case C_MOVE:
+ case C_UP:
+ case C_OK:
+ case C_TEXT:
+ rc = CmdCornuModify(Dex.Trk, action, pos);
+ break;
+ case C_TERMINATE:
+ rc = CmdCornuModify(Dex.Trk, action, pos);
+ Dex.Trk = NULL;
+ modifyCornuMode = FALSE;
+ break;
+ case C_REDRAW:
+ rc = CmdCornuModify(Dex.Trk, action, pos);
+ break;
+ }
+ return rc;
+}
static STATUS_T CmdModify(
wAction_t action,
coOrd pos )
/*
- * Extend a track with a curve or straight.
+ * Extend and alter a track.
+ * Extend a track with a curve or straight and optionally an easement.
+ * Alter a ruler.
+ * Modify a Bezier.
*/
{
@@ -86,10 +147,15 @@ static STATUS_T CmdModify(
/*ChangeParameter( &easementPD );*/
trackGauge = 0.0;
changeTrackMode = modifyRulerMode = FALSE;
+ modifyBezierMode = FALSE;
+ modifyCornuMode = FALSE;
return C_CONTINUE;
case C_DOWN:
- changeTrackMode = modifyRulerMode = FALSE;
+ if (modifyBezierMode)
+ return ModifyBezier(C_DOWN, pos);
+ if (modifyCornuMode)
+ return ModifyCornu(C_DOWN, pos);
DYNARR_SET( trkSeg_t, tempSegs_da, 2 );
tempSegs(0).color = wDrawColorBlack;
tempSegs(0).width = 0;
@@ -107,9 +173,29 @@ static STATUS_T CmdModify(
Dex.Trk = NULL;
return C_CONTINUE;
}
+ if (QueryTrack( Dex.Trk, Q_CAN_MODIFY_CONTROL_POINTS )) { //Bezier
+ modifyBezierMode = TRUE;
+ if (ModifyBezier(C_START, pos) != C_CONTINUE) { //Call Start with track
+ modifyBezierMode = FALSE; //Function rejected Bezier
+ Dex.Trk =NULL;
+ tempSegs_da.cnt = 0;
+ }
+ return C_CONTINUE; //That's it
+ }
+ if (QueryTrack( Dex.Trk, Q_IS_CORNU )) { //Bezier
+ modifyCornuMode = TRUE;
+ if (ModifyCornu(C_START, pos) != C_CONTINUE) { //Call Start with track
+ modifyCornuMode = FALSE; //Function rejected Bezier
+ Dex.Trk =NULL;
+ tempSegs_da.cnt = 0;
+ }
+ return C_CONTINUE; //That's it
+ }
+
+
trackGauge = (IsTrack(Dex.Trk)?GetTrkGauge(Dex.Trk):0.0);
if ( (MyGetKeyState()&WKEY_SHIFT) &&
- QueryTrack( Dex.Trk, Q_CAN_MODIFYRADIUS ) &&
+ QueryTrack( Dex.Trk, Q_CAN_MODIFYRADIUS )&&
(inx=PickUnconnectedEndPoint(pos,Dex.Trk)) >= 0 ) {
trk = Dex.Trk;
while ( (trk1=GetTrkEndTrk(trk,1-inx)) &&
@@ -146,6 +232,10 @@ static STATUS_T CmdModify(
return ModifyRuler( C_MOVE, pos );
if (Dex.Trk == NULL)
return C_CONTINUE;
+ if ( modifyBezierMode )
+ return ModifyBezier(C_MOVE, pos);
+ if ( modifyCornuMode )
+ return ModifyCornu(C_MOVE, pos);
DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack );
tempSegs_da.cnt = 0;
SnapPos( &pos );
@@ -165,6 +255,10 @@ static STATUS_T CmdModify(
return C_CONTINUE;
if ( modifyRulerMode )
return ModifyRuler( C_MOVE, pos );
+ if ( modifyBezierMode )
+ return ModifyBezier( C_UP, pos);
+ if (modifyCornuMode)
+ return ModifyCornu(C_UP, pos);
DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack );
tempSegs_da.cnt = 0;
SnapPos( &pos );
@@ -181,6 +275,8 @@ static STATUS_T CmdModify(
case C_RDOWN:
changeTrackMode = TRUE;
modifyRulerMode = FALSE;
+ modifyBezierMode = FALSE;
+ modifyCornuMode = FALSE;
Dex.Trk = OnTrack( &pos, TRUE, TRUE );
if (Dex.Trk) {
if (!CheckTrackLayer( Dex.Trk ) ) {
@@ -212,10 +308,7 @@ LOG( log_modify, 1, ("extend endPt[%d] = [%0.3f %0.3f] A%0.3f\n",
Dex.first = TRUE;
MainRedraw();
MapRedraw();
-#ifdef LATER
- return C_CONTINUE;
-#endif
-
+ /* no break */
case C_RMOVE:
DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack );
tempSegs_da.cnt = 0;
@@ -226,7 +319,21 @@ LOG( log_modify, 1, ("extend endPt[%d] = [%0.3f %0.3f] A%0.3f\n",
return C_CONTINUE;
Dex.first = FALSE;
Dex.pos01 = Dex.pos00;
- PlotCurve( crvCmdFromEP1, Dex.pos00, Dex.pos00x, pos, &Dex.curveData, TRUE );
+ if (Dex.params.type == curveTypeCornu) { //Restrict Cornu drag out to match end
+ ANGLE_T angle2 = NormalizeAngle(FindAngle(pos, Dex.pos00)-Dex.angle);
+ if (angle2 > 90.0 && angle2 < 270.0) {
+ if (Dex.params.cornuRadius[Dex.params.ep] == 0) {
+ Translate( &pos, Dex.pos00, Dex.angle, FindDistance( Dex.pos00, pos ) );
+ } else {
+ ANGLE_T angle = FindAngle(Dex.params.cornuCenter[Dex.params.ep],pos)-
+ FindAngle(Dex.params.cornuCenter[Dex.params.ep],Dex.pos00);
+ pos=Dex.pos00;
+ Rotate(&pos,Dex.params.cornuCenter[Dex.params.ep],angle);
+ }
+ } else pos = Dex.pos00; //Only out from end
+ PlotCurve( crvCmdFromCornu, Dex.pos00, Dex.pos00x, pos, &Dex.curveData, FALSE );
+ } else
+ PlotCurve( crvCmdFromEP1, Dex.pos00, Dex.pos00x, pos, &Dex.curveData, TRUE );
curveType = Dex.curveData.type;
if ( curveType == curveTypeStraight ) {
Dex.r1 = 0.0;
@@ -382,6 +489,8 @@ LOG( log_modify, 1, ("A0 = %0.3f, A1 = %0.3f\n",
return C_TERMINATE;
case C_REDRAW:
+ if (modifyBezierMode) return ModifyBezier(C_REDRAW, pos);
+ if (modifyCornuMode) return ModifyCornu(C_REDRAW, pos);
if ( (!changeTrackMode) && Dex.Trk && !QueryTrack( Dex.Trk, Q_MODIFY_REDRAW_DONT_UNDRAW_TRACK ) )
UndrawNewTrack( Dex.Trk );
DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack );
@@ -390,9 +499,15 @@ LOG( log_modify, 1, ("A0 = %0.3f, A1 = %0.3f\n",
case C_TEXT:
if ( !Dex.Trk )
return C_CONTINUE;
+ if (modifyBezierMode)
+ return ModifyBezier(action, pos);
+ if (modifyCornuMode)
+ return ModifyCornu(action, pos);
return ModifyTrack( Dex.Trk, action, pos );
default:
+ if (modifyBezierMode) return ModifyBezier(action, pos);
+ if (modifyCornuMode) return ModifyCornu(action, pos);
return C_CONTINUE;
}
}