home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 January
/
Chip_1997-01_cd.bin
/
ms95
/
disk21
/
dir03
/
f014790.re_
/
f014790.re
Wrap
Text File
|
1996-04-02
|
19KB
|
714 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. |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| $Workfile: fencscl.mc $
| $Revision: 1.5 $
| $Date: 25 Jul 1995 14:26:24 $
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Function - |
| |
| Fence scale/spin 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>
#include <mselemen.fdf>
/*----------------------------------------------------------------------+
| |
| Local defines |
| |
+----------------------------------------------------------------------*/
#define SPIN_ORIG 1
#define SPIN_COPY 2
#define ROTATE_ORIG 1
#define ROTATE_COPY 2
#define SCALE_ORIG 1
#define SCALE_COPY 2
/*----------------------------------------------------------------------+
| |
| Local type definitions |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Private Global variables |
| |
+----------------------------------------------------------------------*/
static int fenceCommandView;
/*----------------------------------------------------------------------+
| |
| Public Global variables |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| External variables |
| |
+----------------------------------------------------------------------*/
extern Dpoint3d anchorPoint;
extern int copyMode;
/*----------------------------------------------------------------------+
| |
| Local function declarations |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| ROTATE FENCE functions |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| name rotateElement_getTransform |
| |
| author BSI 5/90 |
| |
+----------------------------------------------------------------------*/
Public void rotateElement_getTransform
(
Transform *trans,
int view,
double angle,
Dpoint3d *point
)
{
Dpoint3d tPoint;
RotMatrix tRMatrix, iRMatrix;
mdlRMatrix_fromView (&tRMatrix, view, FALSE);
mdlRMatrix_invert (&iRMatrix, &tRMatrix);
mdlRMatrix_rotate (&tRMatrix, &tRMatrix, fc_zero, fc_zero, angle);
mdlRMatrix_multiply (&tRMatrix, &iRMatrix, &tRMatrix);
mdlTMatrix_fromRMatrix (trans, &tRMatrix);
mdlTMatrix_setOrigin (trans, point);
}
/*----------------------------------------------------------------------+
| |
| name rotateFenceDataFunc |
| |
| author BSI 6/91 |
| |
+----------------------------------------------------------------------*/
Private void rotateFenceDataFunc
(
Dpoint3d *point,
int view
)
{
FenceCopyParams cp;
/* zero out all copy parameters structure */
memset (&cp, 0, sizeof(cp));
fenceCommandView = view;
rotateElement_getTransform (&cp.transform, view,
tcb->actangle * fc_piover180, point);
mdlFence_process (&cp);
/* free memory allocated for graphic group remapping */
mdlModify_freeGGMap ((MdlCopyParams *)&cp);
}
/*----------------------------------------------------------------------+
| |
| name rotateElement |
| |
| author BSI 6/91 |
| |
+----------------------------------------------------------------------*/
Private void rotateElement
(
MSElementUnion *el,
Dpoint3d *point,
int view
)
{
Transform transform;
rotateElement_getTransform (&transform, view,
tcb->actangle * fc_piover180, point);
mdlElement_transform (dgnBuf, dgnBuf, &transform);
}
/*----------------------------------------------------------------------+
| |
| name rotateDynamics |
| |
| author BSI 6/91 |
| |
+----------------------------------------------------------------------*/
Public void rotateDynamics
(
Dpoint3d *point,
int view
)
{
rotateElement (dgnBuf, point, view);
}
/*----------------------------------------------------------------------+
| |
| name rotateFence |
| |
| author BSI 6/91 |
| |
+----------------------------------------------------------------------*/
Private void rotateFence
(
Dpoint3d *point
)
{
eraseFence ();
rotateElement (dgnBuf, point, fenceCommandView);
redrawFence();
}
/*----------------------------------------------------------------------+
| |
| name startFenceRotate |
| |
| author BSI 6/91 |
| |
+----------------------------------------------------------------------*/
Private void startFenceRotate
(
void
)
{
int fenceCommand, clipMode, (*contentFunc)();
/* set up proper locate criteria depending on copy mode */
if (copyMode)
{
contentFunc = fenceModify_transformCopy;
fenceCommand = 115;
clipMode = FENCE_CLIP_COPY;
mdlLocate_allowLocked ();
}
else
{
contentFunc = fenceModify_transformOrig;
fenceCommand = 114;
clipMode = FENCE_CLIP_ORIG;
mdlLocate_normal ();
}
mdlState_startFenceCommand
(
contentFunc,
rotateFence,
rotateFenceDataFunc,
endFenceCommand,
-fenceCommand,
-132,
clipMode
);
if (!tcb->wssect)
{
mdlFence_toShape (dgnBuf);
mdlState_dynamicUpdate (rotateDynamics, 1);
}
}
/*----------------------------------------------------------------------+
| |
| name fenceRotate |
| |
| author BSI 7/86 |
| |
+----------------------------------------------------------------------*/
Public void fenceRotate
(
char *unparsedP
)
cmdNumber CMD_MFENCE_ROTATE_ORIGINAL,
CMD_MFENCE_ROTATE_COPY
{
copyMode = ((mdlCommandNumber & 0xff00) >> 8) == ROTATE_COPY;
startFenceRotate ();
}
/*----------------------------------------------------------------------+
| |
| SCALE FENCE functions |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| name scaleRMatrix |
| |
| author BSI 10/86 |
| |
+----------------------------------------------------------------------*/
Public void scaleRMatrix
(
RotMatrix *t,
double xs,
double ys,
double zs
)
{
int i;
if (mgds_modes.three_d)
{
for (i=0; i<3; i++)
{
t->form3d[0][i] *= xs;
t->form3d[1][i] *= ys;
t->form3d[2][i] *= zs;
}
}
else
{
for (i=0; i<2; i++)
{
t->form2d[0][i] *= xs;
t->form2d[1][i] *= ys;
}
}
}
/*----------------------------------------------------------------------+
| |
| name scaleElement_getTransform |
| |
| author BSI 5/90 |
| |
+----------------------------------------------------------------------*/
Public void scaleElement_getTransform
(
Transform *trans,
int view,
Dpoint3d *point,
double xScale,
double yScale,
double zScale
)
{
Dpoint3d tPoint;
RotMatrix tRMatrix, invRMatrix;
mdlRMatrix_fromView (&tRMatrix, view, FALSE);
mdlRMatrix_invert (&invRMatrix, &tRMatrix);
scaleRMatrix (&tRMatrix, xScale, yScale, zScale);
mdlRMatrix_multiply (&tRMatrix, &invRMatrix, &tRMatrix);
mdlTMatrix_fromRMatrix (trans, &tRMatrix);
mdlTMatrix_setOrigin (trans, point);
}
/*----------------------------------------------------------------------+
| |
| name scaleElement |
| |
| author BSI 7/86 |
| |
+----------------------------------------------------------------------*/
Public void scaleElement
(
MSElementUnion *element, /* <=> element to be scaled */
Dpoint3d *scalePoint, /* => point to scale about */
double xs,
double ys,
double zs,
int view
)
{
Transform transform;
scaleElement_getTransform (&transform, view, scalePoint, xs, ys, zs);
mdlElement_transform (element, element, &transform);
}
/*----------------------------------------------------------------------+
| |
| name scaleDynamics |
| |
| author BSI 1/87 |
| |
+----------------------------------------------------------------------*/
Public void scaleDynamics
(
Dpoint3d *point,
int view
)
{
scaleElement (dgnBuf, point, tcb->xactscle, tcb->yactscle,
tcb->zactscle, view);
}
/*----------------------------------------------------------------------+
| |
| name scaleFenceDataFunc |
| |
| author BSI 6/91 |
| |
+----------------------------------------------------------------------*/
Private void scaleFenceDataFunc
(
Dpoint3d *point,
int view
)
{
FenceCopyParams cp;
/* zero out all copy parameters structure */
memset (&cp, 0, sizeof(cp));
fenceCommandView = view;
scaleElement_getTransform (&cp.transform, view, point,
tcb->xactscle, tcb->yactscle, tcb->zactscle);
mdlFence_process (&cp);
/* free memory allocated for graphic group remapping */
mdlModify_freeGGMap ((MdlCopyParams *)&cp);
}
/*----------------------------------------------------------------------+
| |
| name scaleFence - scale the fence |
| |
| author BSI 7/86 |
| |
+----------------------------------------------------------------------*/
Private void scaleFence
(
Dpoint3d *point
)
{
eraseFence ();
scaleElement (dgnBuf, point, tcb->xactscle,
tcb->yactscle, tcb->zactscle, fenceCommandView);
redrawFence();
}
/*----------------------------------------------------------------------+
| |
| name startFenceScale |
| |
| author BSI 5/90 |
| |
+----------------------------------------------------------------------*/
Private void startFenceScale
(
void
)
{
int fenceCommand, clipMode, (*contentFunc)();
/* set up proper locate criteria depending on copy mode */
if (copyMode)
{
contentFunc = fenceModify_transformCopy;
fenceCommand = 117;
clipMode = FENCE_CLIP_COPY;
mdlLocate_allowLocked ();
}
else
{
contentFunc = fenceModify_transformOrig;
fenceCommand = 116;
clipMode = FENCE_CLIP_ORIG;
mdlLocate_normal ();
}
mdlState_startFenceCommand
(
contentFunc,
scaleFence,
scaleFenceDataFunc,
endFenceCommand,
-fenceCommand,
-132,
clipMode
);
if (!tcb->wssect)
{
mdlFence_toShape (dgnBuf);
mdlState_dynamicUpdate (scaleDynamics, 1);
}
}
/*----------------------------------------------------------------------+
| |
| name fenceScale - parse input for the fence scale cmd |
| |
| author BSI 7/86 |
| |
+----------------------------------------------------------------------*/
Public void fenceScale
(
void
)
cmdNumber CMD_MFENCE_SCALE_ORIGINAL,
CMD_MFENCE_SCALE_COPY
{
copyMode = ((mdlCommandNumber & 0xff00) >> 8) == SCALE_COPY;
startFenceScale ();
}
/*----------------------------------------------------------------------+
| |
| SPIN FENCE functions |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| name spinElement_getTransform |
| |
| author BSI 5/90 |
| |
+----------------------------------------------------------------------*/
Public int spinElement_getTransform
(
Transform *trans,
int view,
Dpoint3d *point
)
{
Dpoint3d vec;
double angle;
RotMatrix rMatrix;
if (mdlVec_pointEqual (&anchorPoint, point))
return ERROR;
mdlVec_subtractPoint (&vec, point, &anchorPoint);
mdlRMatrix_fromView (&rMatrix, view, FALSE);
mdlRMatrix_rotatePoint (&vec, (RotMatrix *)tcb->view[view].transmatrx);
angle = atan2 (vec.y, vec.x);
rotateElement_getTransform (trans, view, angle, &anchorPoint);
return SUCCESS;
}
/*----------------------------------------------------------------------+
| |
| name spin_element |
| |
| author BSI 10/87 |
| |
+----------------------------------------------------------------------*/
Public int spinElement
(
MSElementUnion *element, /* <=> element to be spun */
Dpoint3d *rotPoint /* => point to spin about */
)
{
Transform transform;
if (spinElement_getTransform (&transform, fenceCommandView, rotPoint)
== ERROR)
return SUCCESS;
return mdlElement_transform (element, element, &transform);
}
/*----------------------------------------------------------------------+
| |
| name spinFence - moves the fence to a new position |
| |
| author BSI 10/87 |
| |
+----------------------------------------------------------------------*/
Private void spinFence
(
Dpoint3d *point
)
{
if (tcb->wssect)
return;
eraseFence();
if (spinElement (dgnBuf, point))
{
mdlOutput_rscPrintf (MSG_ERROR, NULL, MESSAGEID_Messages,
MSGID_OffDesignPlane);
return;
}
redrawFence();
}
/*----------------------------------------------------------------------+
| |
| name fenceSpinDataFunc |
| |
| author BSI 5/90 |
| |
+----------------------------------------------------------------------*/
Private void fenceSpinDataFunc
(
Dpoint3d *point,
int view
)
{
FenceCopyParams cp;
/* zero out all copy parameters structure */
memset (&cp, 0, sizeof(cp));
spinElement_getTransform (&cp.transform, view, point);
mdlFence_process (&cp);
/* free memory allocated for graphic group remapping */
mdlModify_freeGGMap ((MdlCopyParams *)&cp);
}
/*----------------------------------------------------------------------+
| |
| name spinDynamics |
| |
| author BSI 10/87 |
| |
+----------------------------------------------------------------------*/
Public void spinDynamics
(
Dpoint3d *point
)
{
spinElement (dgnBuf, point);
}
/*----------------------------------------------------------------------+
| |
| name fenceSpin_firstPoint - define point for spin origin |
| |
| author BSI 10/87 |
| |
+----------------------------------------------------------------------*/
Private void fenceSpin_firstPoint
(
Dpoint3d *point,
int view
)
{
anchorPoint = *point;
fenceCommandView = view;
if (!tcb->wssect)
{
mdlFence_toShape (dgnBuf);
mdlState_dynamicUpdate (spinDynamics, 1);
}
/* change data point function to one that processes fence */
mdlState_setFunction (STATE_DATAPOINT, fenceSpinDataFunc);
mdlOutput_rscPrintf (MSG_PROMPT, NULL, MESSAGEID_Messages,
MSGID_ProcessFence);
}
/*----------------------------------------------------------------------+
| |
| name startFenceSpin |
| |
| author BSI 6/91 |
| |
+----------------------------------------------------------------------*/
Private void startFenceSpin
(
void
)
{
int fenceCommand, clipMode, (*contentFunc)();
/* set up proper locate criteria depending on copy mode */
if (copyMode)
{
contentFunc = fenceModify_transformCopy;
fenceCommand = 323;
clipMode = FENCE_CLIP_COPY;
mdlLocate_allowLocked ();
}
else
{
contentFunc = fenceModify_transformOrig;
fenceCommand = 322;
clipMode = FENCE_CLIP_ORIG;
mdlLocate_normal ();
}
mdlState_startFenceCommand
(
contentFunc,
spinFence,
fenceSpin_firstPoint,
startFenceSpin,
-fenceCommand,
-355,
clipMode
);
}
/*----------------------------------------------------------------------+
| |
| name fenceSpin - parse input for the fence spin cmd |
| |
| author BSI 10/87 |
| |
+----------------------------------------------------------------------*/
Private void fenceSpin
(
void
) cmdNumber
CMD_MFENCE_SPIN_ORIGINAL,
CMD_MFENCE_SPIN_COPY
{
copyMode = ((mdlCommandNumber & 0xff00) >> 8) == SPIN_COPY;
startFenceSpin ();
}