home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 January
/
Chip_1997-01_cd.bin
/
ms95
/
disk22
/
dir02
/
f014780.re_
/
f014780.re
Wrap
Text File
|
1996-04-02
|
10KB
|
366 lines
/*----------------------------------------------------------------------+
| |
| Copyright (1995) Bentley Systems, Inc., All rights reserved. |
| |
| "MicroStation" is a registered trademark and "MDL" and "MicroCSL" |
| are trademarks of Bentley Systems, Inc. |
| |
| Limited permission is hereby granted to reproduce and modify this |
| copyrighted material provided that the resulting code is used only |
| in conjunction with Bentley Systems products under the terms of the |
| license agreement provided therein, and that this notice is retained |
| in its entirety in any such reproduction or modification. |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| $Logfile: J:/mdl/examples/fence/fencmir.mcv $
| $Workfile: fencmir.mc $
| $Revision: 1.3 $
| $Date: 25 Jul 1995 14:26:36 $
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Function - |
| |
| Fence mirror logic |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Include Files |
| |
+----------------------------------------------------------------------*/
#include <mselems.h>
#include <mdl.h>
#include <global.h>
#include <tcb.h>
#include <userfnc.h>
#include <math.h>
#include <string.h>
#include "mdlfence.h"
#include "fenccmd.h"
#include <msstate.fdf>
#include <msmisc.fdf>
#include <msoutput.fdf>
#include <msrmatrx.fdf>
#include <mstmatrx.fdf>
#include <mslocate.fdf>
#include <msvec.fdf>
/*----------------------------------------------------------------------+
| |
| Local defines |
| |
+----------------------------------------------------------------------*/
#define MIRROR_ORIG 1
#define MIRROR_COPY 2
#define MIRROR_MODE_HORIZONTAL 1
#define MIRROR_MODE_VERTICAL 2
#define MIRROR_MODE_LINE 3
/*----------------------------------------------------------------------+
| |
| Local type definitions |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Private Global variables |
| |
+----------------------------------------------------------------------*/
static int mirrorMode;
/*----------------------------------------------------------------------+
| |
| Public Global variables |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| External variables |
| |
+----------------------------------------------------------------------*/
extern Dpoint3d anchorPoint;
extern int copyMode;
/*----------------------------------------------------------------------+
| |
| Local function declarations |
| |
+----------------------------------------------------------------------*/
Private void startFenceMirror
(
void
);
/*----------------------------------------------------------------------+
| |
| name vMirrorRMatrix |
| |
| author BSI 7/86 |
| |
+----------------------------------------------------------------------*/
Private void vMirrorRMatrix
(
RotMatrix *utrans
)
{
if (mgds_modes.three_d)
{
utrans->form3d[0][0] = -utrans->form3d[0][0];
utrans->form3d[0][1] = -utrans->form3d[0][1];
utrans->form3d[0][2] = -utrans->form3d[0][2];
}
else
{
utrans->form2d[0][0] = -utrans->form2d[0][0];
utrans->form2d[0][1] = -utrans->form2d[0][1];
}
}
/*----------------------------------------------------------------------+
| |
| name hMirrorRMatrix |
| |
| author BSI 7/86 |
| |
+----------------------------------------------------------------------*/
Private void hMirrorRMatrix
(
RotMatrix *utrans
)
{
if (mgds_modes.three_d)
{
utrans->form3d[1][0] = -utrans->form3d[1][0];
utrans->form3d[1][1] = -utrans->form3d[1][1];
utrans->form3d[1][2] = -utrans->form3d[1][2];
}
else
{
utrans->form2d[1][0] = -utrans->form2d[1][0];
utrans->form2d[1][1] = -utrans->form2d[1][1];
}
}
/*----------------------------------------------------------------------+
| |
| name mirrorElement_getTransform |
| |
| author BSI 6/90 |
| |
+----------------------------------------------------------------------*/
Public void mirrorElement_getTransform
(
FenceCopyParams *mp,
int view,
Dpoint3d *point1,
Dpoint3d *point2
)
{
double rotAngle;
Dpoint3d *centerP, tPoint1;
RotMatrix invRMatrix, tRMatrix;
mdlRMatrix_fromView (&tRMatrix, view, FALSE);
mdlRMatrix_invert (&invRMatrix, &tRMatrix);
centerP = point1;
switch (mirrorMode)
{
case MIRROR_MODE_VERTICAL:
vMirrorRMatrix (&tRMatrix);
break;
case MIRROR_MODE_LINE:
mdlVec_subtractPoint (&tPoint1, point1, point2);
mdlRMatrix_rotatePoint (&tPoint1, &tRMatrix);
rotAngle = atan2 (tPoint1.y, tPoint1.x) * fc_2;
mdlRMatrix_rotate (&tRMatrix, &tRMatrix, fc_zero, fc_zero,
-rotAngle);
centerP = point2;
case MIRROR_MODE_HORIZONTAL:
hMirrorRMatrix (&tRMatrix);
break;
}
mdlRMatrix_multiply (&tRMatrix, &invRMatrix, &tRMatrix);
mdlTMatrix_fromRMatrix (&mp->transform, &tRMatrix);
mdlTMatrix_setOrigin (&mp->transform, centerP);
}
/*----------------------------------------------------------------------+
| |
| name mirrorFence - mirror the fence |
| |
| author BSI 7/86 |
| |
+----------------------------------------------------------------------*/
Private void mirrorFence
(
Dpoint3d *point,
int view
)
{
FenceCopyParams mp;
/* erase current fence */
eraseFence ();
mirrorElement_getTransform (&mp, view, point, &anchorPoint);
elementModify_transform (dgnBuf, &mp);
/* re-display the new fence */
redrawFence ();
/* save new anchor point */
anchorPoint = *point;
}
/*----------------------------------------------------------------------+
| |
| name mirrorDynamics |
| |
| author BSI 1/87 |
| |
+----------------------------------------------------------------------*/
Private void mirrorDynamics
(
Dpoint3d *point,
int view
)
{
FenceCopyParams mp;
mirrorElement_getTransform (&mp, view, point, &anchorPoint);
elementModify_transform (dgnBuf, &mp);
}
/*----------------------------------------------------------------------+
| |
| name fenceMirrorDataFunc |
| |
| author BSI 5/90 |
| |
+----------------------------------------------------------------------*/
Private void fenceMirrorDataFunc
(
Dpoint3d *point,
int view
)
{
FenceCopyParams mp;
/* zero out all copy parameters structure */
memset (&mp, 0, sizeof(mp));
mirrorElement_getTransform (&mp, view, point, &anchorPoint);
mdlFence_process (&mp);
/* free memory allocated for graphic group remapping */
mdlModify_freeGGMap ((MdlCopyParams *)&mp);
}
/*----------------------------------------------------------------------+
| |
| name mirrorLine_firstPoint - fence mirror about a line |
| |
| author BSI 7/86 |
| |
+----------------------------------------------------------------------*/
Private void mirrorLine_firstPoint
(
Dpoint3d *point
)
{
/* save anchor point */
anchorPoint = *point;
mdlOutput_rscPrintf (MSG_PROMPT, NULL, MESSAGEID_Messages,
MSGID_MirrorEnter2ndPt);
mdlState_setFunction (STATE_DATAPOINT, fenceMirrorDataFunc);
mdlState_setFunction (STATE_RESET, startFenceMirror);
if (!tcb->wssect)
{
mdlFence_toShape (dgnBuf);
mdlState_dynamicUpdate (mirrorDynamics, 1);
}
}
/*----------------------------------------------------------------------+
| |
| name startFenceMirror |
| |
| author BSI 6/91 |
| |
+----------------------------------------------------------------------*/
Private void startFenceMirror
(
void
)
{
int fenceCommand;
/* set up proper locate criteria depending on copy mode */
if (copyMode)
mdlLocate_allowLocked ();
else
mdlLocate_normal ();
/* set up the Command Number */
fenceCommand = (copyMode ? 120 : 117) + mirrorMode;
mdlState_startFenceCommand
(
(copyMode ? fenceModify_transformCopy: fenceModify_transformOrig),
mirrorFence,
((mirrorMode==MIRROR_MODE_LINE) ? mirrorLine_firstPoint :
fenceMirrorDataFunc),
endFenceCommand,
-fenceCommand,
-132,
(copyMode ? FENCE_CLIP_COPY : FENCE_CLIP_ORIG)
);
/* start dynamics, if appropriate */
if ((mirrorMode != MIRROR_MODE_LINE) && !tcb->wssect)
{
mdlFence_toShape (dgnBuf);
mdlState_dynamicUpdate (mirrorDynamics, 1);
}
}
/*----------------------------------------------------------------------+
| |
| name fenceMirrorCommand |
| |
| author BSI 7/86 |
| |
+----------------------------------------------------------------------*/
Private void fenceMirrorCommand
(
void
)
cmdNumber
CMD_MFENCE_MIRROR_ORIGINAL_HORIZONTAL,
CMD_MFENCE_MIRROR_ORIGINAL_VERTICAL,
CMD_MFENCE_MIRROR_ORIGINAL_LINE,
CMD_MFENCE_MIRROR_COPY_HORIZONTAL,
CMD_MFENCE_MIRROR_COPY_VERTICAL,
CMD_MFENCE_MIRROR_COPY_LINE
{
copyMode = ((mdlCommandNumber & 0xff00) >> 8) == MIRROR_COPY;
mirrorMode = (mdlCommandNumber & 0x00f0) >> 4;
startFenceMirror ();
}