diff options
Diffstat (limited to 'app/bin/cparalle.c')
-rw-r--r-- | app/bin/cparalle.c | 363 |
1 files changed, 185 insertions, 178 deletions
diff --git a/app/bin/cparalle.c b/app/bin/cparalle.c index 6825aea..533b9d5 100644 --- a/app/bin/cparalle.c +++ b/app/bin/cparalle.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "ccurve.h" @@ -30,10 +30,10 @@ #include "common-ui.h" static struct { - track_p Trk; - coOrd orig; - track_p anchor_Trk; - } Dpa; + track_p Trk; + coOrd orig; + track_p anchor_Trk; +} Dpa; static DIST_T parSeparation = 1.0; static double parSepFactor = 0.0; @@ -57,146 +57,150 @@ static paramGroup_t parSepPG = { "parallel", 0, parSepPLs, COUNT( parSepPLs ) }; static STATUS_T CmdParallel(wAction_t action, coOrd pos) { - DIST_T d; - track_p t=NULL; - coOrd p; - static coOrd p0, p1; - ANGLE_T a; - track_p t0, t1; - EPINX_T ep0=-1, ep1=-1; - wControl_p controls[4]; - char * labels[3]; - static DIST_T parRFactor; + DIST_T d; + track_p t=NULL; + coOrd p; + static coOrd p0, p1; + ANGLE_T a; + track_p t0, t1; + EPINX_T ep0=-1, ep1=-1; + wControl_p controls[4]; + char * labels[3]; + static DIST_T parRFactor; - parType = VP2L(commandContext); + parType = VP2L(commandContext); - switch (action&0xFF) { + switch (action&0xFF) { - case C_START: - if (parSepPLs[0].control==NULL) { - ParamCreateControls(&parSepPG, NULL); - } - if (parType == PAR_TRACK) { - sprintf(message, "parallel-separation-%s", curScaleName); - parSeparation = ceil(13.0*12.0/curScaleRatio); - } else { - sprintf(message, "parallel-line-separation-%s", curScaleName); - parSeparation = 5.0*12.0/curScaleRatio; - } - wPrefGetFloat("misc", message, &parSeparation, parSeparation); - ParamLoadControls(&parSepPG); - ParamGroupRecord(&parSepPG); - parSepPD.option |= PDO_NORECORD; + case C_START: + if (parSepPLs[0].control==NULL) { + ParamCreateControls(&parSepPG, NULL); + } + if (parType == PAR_TRACK) { + sprintf(message, "parallel-separation-%s", curScaleName); + parSeparation = ceil(13.0*12.0/curScaleRatio); + } else { + sprintf(message, "parallel-line-separation-%s", curScaleName); + parSeparation = 5.0*12.0/curScaleRatio; + } + wPrefGetFloat("misc", message, &parSeparation, parSeparation); + ParamLoadControls(&parSepPG); + ParamGroupRecord(&parSepPG); + parSepPD.option |= PDO_NORECORD; parFactorPD.option |= PDO_NORECORD; - controls[0] = parSepPD.control; - if (parType == PAR_TRACK) - controls[1] = parFactorPD.control; - else - controls[1] = NULL; - controls[2] = NULL; - labels[0] = N_("Separation"); - labels[1] = N_("Radius Factor"); - InfoSubstituteControls(controls, labels); - parSepPD.option &= ~PDO_NORECORD; - parFactorPD.option &= ~PDO_NORECORD; - Dpa.anchor_Trk = NULL; - tempSegs_da.cnt = 0; - SetAllTrackSelect( FALSE ); - return C_CONTINUE; + controls[0] = parSepPD.control; + if (parType == PAR_TRACK) { + controls[1] = parFactorPD.control; + } else { + controls[1] = NULL; + } + controls[2] = NULL; + labels[0] = N_("Separation"); + labels[1] = N_("Radius Factor"); + InfoSubstituteControls(controls, labels); + parSepPD.option &= ~PDO_NORECORD; + parFactorPD.option &= ~PDO_NORECORD; + Dpa.anchor_Trk = NULL; + DYNARR_RESET( trkSeg_t, tempSegs_da ); + SetAllTrackSelect( FALSE ); + return C_CONTINUE; - case wActionMove: - tempSegs_da.cnt = 0; - Dpa.anchor_Trk = NULL; - if (parType == PAR_TRACK) - Dpa.anchor_Trk = OnTrack(&pos, FALSE, TRUE); - else - Dpa.anchor_Trk = OnTrack(&pos, FALSE, FALSE); + case wActionMove: + DYNARR_RESET( trkSeg_t, tempSegs_da ); + Dpa.anchor_Trk = NULL; + if (parType == PAR_TRACK) { + Dpa.anchor_Trk = OnTrack(&pos, FALSE, TRUE); + } else { + Dpa.anchor_Trk = OnTrack(&pos, FALSE, FALSE); + } - if (!Dpa.anchor_Trk) { - return C_CONTINUE; - } - if (Dpa.anchor_Trk && !CheckTrackLayerSilent(Dpa.anchor_Trk)) { - Dpa.anchor_Trk = NULL; - return C_CONTINUE; - } - if (!QueryTrack(Dpa.anchor_Trk, Q_CAN_PARALLEL)) { - Dpa.anchor_Trk = NULL; - return C_CONTINUE; - } - break; - case C_DOWN: - Dpa.anchor_Trk = NULL; - tempSegs_da.cnt = 0; - if (parSeparation < 0.0) { - ErrorMessage(MSG_PARALLEL_SEP_GTR_0); - return C_ERROR; - } + if (!Dpa.anchor_Trk) { + return C_CONTINUE; + } + if (Dpa.anchor_Trk && !CheckTrackLayerSilent(Dpa.anchor_Trk)) { + Dpa.anchor_Trk = NULL; + return C_CONTINUE; + } + if (!QueryTrack(Dpa.anchor_Trk, Q_CAN_PARALLEL)) { + Dpa.anchor_Trk = NULL; + return C_CONTINUE; + } + break; + case C_DOWN: + Dpa.anchor_Trk = NULL; + DYNARR_RESET( trkSeg_t, tempSegs_da ); + if (parSeparation < 0.0) { + ErrorMessage(MSG_PARALLEL_SEP_GTR_0); + return C_ERROR; + } - controls[0] = parSepPD.control; - controls[1] = parFactorPD.control; - controls[2] = NULL; - labels[0] = N_("Separation"); - labels[1] = N_("Radius factor"); - InfoSubstituteControls(controls, labels); - ParamLoadData(&parSepPG); - Dpa.orig = pos; - if (parType == PAR_TRACK) + controls[0] = parSepPD.control; + controls[1] = parFactorPD.control; + controls[2] = NULL; + labels[0] = N_("Separation"); + labels[1] = N_("Radius factor"); + InfoSubstituteControls(controls, labels); + ParamLoadData(&parSepPG); + Dpa.orig = pos; + if (parType == PAR_TRACK) { Dpa.Trk = OnTrack(&pos, FALSE, TRUE); - else - Dpa.Trk = OnTrack(&pos, FALSE, FALSE); //Also lines for line - if (!Dpa.Trk) { - return C_CONTINUE; - } - if (!QueryTrack(Dpa.Trk, Q_CAN_PARALLEL)) { - Dpa.Trk = NULL; - InfoMessage(_(" Track/Line doesn't support parallel")); - wBeep(); - return C_CONTINUE; - } + } else { + Dpa.Trk = OnTrack(&pos, FALSE, FALSE); //Also lines for line + } + if (!Dpa.Trk) { + return C_CONTINUE; + } + if (!QueryTrack(Dpa.Trk, Q_CAN_PARALLEL)) { + Dpa.Trk = NULL; + InfoMessage(_(" Track/Line doesn't support parallel")); + wBeep(); + return C_CONTINUE; + } - parRFactor = (2864.0*(double)parSepFactor)/curScaleRatio; + parRFactor = (2864.0*(double)parSepFactor)/curScaleRatio; - if ((parType == PAR_TRACK) && (parSeparation == 0.0)) { - DIST_T orig_gauge = GetTrkGauge(Dpa.Trk); - DIST_T new_gauge = GetScaleTrackGauge(GetLayoutCurScale()); - if (orig_gauge == new_gauge) { - ErrorMessage(MSG_PARALLEL_SEP_GTR_0); - return C_ERROR; - } - parSeparation = fabs(orig_gauge/2-new_gauge/2); - parRFactor = 0.0; - } else if (parType != PAR_TRACK) - parRFactor = 0.0; - /* in case query has changed things (eg joint) */ - /* - * this seems to cause problems so I commented it out - * until further investigation shows the necessity - */ - //Dpa.Trk = OnTrack( &Dpa.orig, TRUE, TRUE ); - tempSegs_da.cnt = 0; - /* no break */ + if ((parType == PAR_TRACK) && (parSeparation == 0.0)) { + DIST_T orig_gauge = GetTrkGauge(Dpa.Trk); + DIST_T new_gauge = GetScaleTrackGauge(GetLayoutCurScale()); + if (orig_gauge == new_gauge) { + ErrorMessage(MSG_PARALLEL_SEP_GTR_0); + return C_ERROR; + } + parSeparation = fabs(orig_gauge/2-new_gauge/2); + parRFactor = 0.0; + } else if (parType != PAR_TRACK) { + parRFactor = 0.0; + } + /* in case query has changed things (eg joint) */ + /* + * this seems to cause problems so I commented it out + * until further investigation shows the necessity + */ + //Dpa.Trk = OnTrack( &Dpa.orig, TRUE, TRUE ); + DYNARR_RESET( trkSeg_t, tempSegs_da ); + /* no break */ - case C_MOVE: - if (Dpa.Trk == NULL) { - return C_CONTINUE; - } - tempSegs_da.cnt = 0; - if (!MakeParallelTrack(Dpa.Trk, pos, parSeparation, parRFactor, NULL, &p0, &p1, - parType == PAR_TRACK)) { - Dpa.Trk = NULL; - return C_CONTINUE; - } - return C_CONTINUE; + case C_MOVE: + if (Dpa.Trk == NULL) { + return C_CONTINUE; + } + DYNARR_RESET( trkSeg_t, tempSegs_da ); + if (!MakeParallelTrack(Dpa.Trk, pos, parSeparation, parRFactor, NULL, &p0, &p1, + parType == PAR_TRACK)) { + Dpa.Trk = NULL; + return C_CONTINUE; + } + return C_CONTINUE; - case C_UP: - Dpa.anchor_Trk = NULL; - if (Dpa.Trk == NULL) { - return C_CONTINUE; - } - t0=t1=NULL; - if (parType == PAR_TRACK) { + case C_UP: + Dpa.anchor_Trk = NULL; + if (Dpa.Trk == NULL) { + return C_CONTINUE; + } + t0=t1=NULL; + if (parType == PAR_TRACK) { p = p0; - tempSegs_da.cnt = 0; + DYNARR_RESET( trkSeg_t, tempSegs_da ); if ((t0=OnTrack(&p, FALSE, TRUE)) != NULL) { ep0 = PickEndPoint(p, t0); if (ep0 < 0 || GetTrkEndTrk(t0,ep0) != NULL) { @@ -222,23 +226,23 @@ static STATUS_T CmdParallel(wAction_t action, coOrd pos) } } } - } - UndoStart(_("Create Parallel Track"), "newParallel"); - if (!MakeParallelTrack(Dpa.Trk, pos, parSeparation, parRFactor, &t, NULL, NULL, - parType == PAR_TRACK)) { - tempSegs_da.cnt = 0; - return C_TERMINATE; - } - if (parType == PAR_TRACK) { - if (GetTrkGauge(Dpa.Trk)> parSeparation) { - SetTrkNoTies(t, TRUE); - } - //CopyAttributes( Dpa.Trk, t ); Don't force scale or track width or Layer - SetTrkBits(t,(GetTrkBits(t)&TB_HIDEDESC) | (GetTrkBits(Dpa.Trk)&~TB_HIDEDESC)); + } + UndoStart(_("Create Parallel Track"), "newParallel"); + if (!MakeParallelTrack(Dpa.Trk, pos, parSeparation, parRFactor, &t, NULL, NULL, + parType == PAR_TRACK)) { + DYNARR_RESET( trkSeg_t, tempSegs_da ); + return C_TERMINATE; + } + if (parType == PAR_TRACK) { + if (GetTrkGauge(Dpa.Trk)> parSeparation) { + SetTrkNoTies(t, TRUE); + } + //CopyAttributes( Dpa.Trk, t ); Don't force scale or track width or Layer + SetTrkBits(t,(GetTrkBits(t)&TB_HIDEDESC) | (GetTrkBits(Dpa.Trk)&~TB_HIDEDESC)); if (t0) { a = NormalizeAngle(GetTrkEndAngle(t0, ep0) - GetTrkEndAngle(t, - 0) + (180.0+connectAngle/2.0)); + 0) + (180.0+connectAngle/2.0)); if (a < connectAngle) { DrawEndPt(&mainD, t0, ep0, wDrawColorWhite); ConnectTracks(t0, ep0, t, 0); @@ -247,55 +251,58 @@ static STATUS_T CmdParallel(wAction_t action, coOrd pos) } if (t1) { a = NormalizeAngle(GetTrkEndAngle(t1, ep1) - GetTrkEndAngle(t, - 1) + (180.0+connectAngle/2.0)); + 1) + (180.0+connectAngle/2.0)); if (a < connectAngle) { DrawEndPt(&mainD, t1, ep1, wDrawColorWhite); ConnectTracks(t1, ep1, t, 1); DrawEndPt(&mainD, t1, ep1, wDrawColorBlack); } } - } - DrawNewTrack(t); - UndoEnd(); - InfoSubstituteControls(NULL, NULL); - if (parType == PAR_TRACK) - sprintf(message, "parallel-separation-%s", curScaleName); - else - sprintf(message, "parallel-line-separation-%s", curScaleName); - wPrefSetFloat("misc", message, parSeparation); - tempSegs_da.cnt = 0; - return C_TERMINATE; + } + DrawNewTrack(t); + UndoEnd(); + InfoSubstituteControls(NULL, NULL); + if (parType == PAR_TRACK) { + sprintf(message, "parallel-separation-%s", curScaleName); + } else { + sprintf(message, "parallel-line-separation-%s", curScaleName); + } + wPrefSetFloat("misc", message, parSeparation); + DYNARR_RESET( trkSeg_t, tempSegs_da ); + return C_TERMINATE; - case C_REDRAW: - if (Dpa.anchor_Trk) { + case C_REDRAW: + if (Dpa.anchor_Trk) { DrawTrack(Dpa.anchor_Trk,&tempD, - wDrawColorPreviewSelected); //Special color means THICK3 as well - } - if (tempSegs_da.cnt>0) { - DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, - wDrawColorBlack ); - } - return C_CONTINUE; + wDrawColorPreviewSelected); //Special color means THICK3 as well + } + DrawSegsDA( &tempD, NULL, zero, 0.0, &tempSegs_da, trackGauge, wDrawColorBlack, + 0 ); + return C_CONTINUE; - case C_CANCEL: - Dpa.anchor_Trk = NULL; - tempSegs_da.cnt = 0; - InfoSubstituteControls(NULL, NULL); - return C_TERMINATE; + case C_CANCEL: + Dpa.anchor_Trk = NULL; + DYNARR_RESET( trkSeg_t, tempSegs_da ); + InfoSubstituteControls(NULL, NULL); + return C_TERMINATE; - } - return C_CONTINUE; + } + return C_CONTINUE; } -#include "bitmaps/parallel.xpm" -#include "bitmaps/parallel-line.xpm" +#include "bitmaps/parallel.xpm3" +#include "bitmaps/parallel-line.xpm3" EXPORT void InitCmdParallel( wMenu_p menu ) { ButtonGroupBegin( _("Parallel"), "cmdParallelSetCmd", _("Parallel") ); - AddMenuButton( menu, CmdParallel, "cmdParallelTrack", _("Parallel Track"), wIconCreatePixMap(parallel_xpm[iconSize]), LEVEL0_50, IC_STICKY|IC_POPUP|IC_WANT_MOVE, ACCL_PARALLEL, I2VP(0) ); - AddMenuButton( menu, CmdParallel, "cmdParallelLine", _("Parallel Line"), wIconCreatePixMap(parallel_line_xpm[iconSize]), LEVEL0_50, IC_STICKY|IC_POPUP|IC_WANT_MOVE, ACCL_PARALLEL, I2VP(1) ); + AddMenuButton( menu, CmdParallel, "cmdParallelTrack", _("Parallel Track"), + wIconCreatePixMap(parallel_xpm3[iconSize]), LEVEL0_50, + IC_STICKY|IC_POPUP|IC_WANT_MOVE, ACCL_PARALLEL, I2VP(0) ); + AddMenuButton( menu, CmdParallel, "cmdParallelLine", _("Parallel Line"), + wIconCreatePixMap(parallel_line_xpm3[iconSize]), LEVEL0_50, + IC_STICKY|IC_POPUP|IC_WANT_MOVE, ACCL_PARALLEL, I2VP(1) ); ButtonGroupEnd(); ParamRegister( &parSepPG ); } |