home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 January
/
Chip_1997-01_cd.bin
/
ms95
/
disk22
/
dir03
/
f016080.re_
/
f016080.re
Wrap
Text File
|
1996-04-02
|
7KB
|
229 lines
/*----------------------------------------------------------------------+
| |
| Copyright (1985-95) 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/meshsurf/meshsurf.mcv $
| $Workfile: meshsurf.mc $
| $Revision: 1.3 $
| $Date: 26 Jul 1995 07:55:52 $
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Include Files |
| |
+----------------------------------------------------------------------*/
#include <mdl.h>
#include <mdlbspln.h>
#include <mselems.h>
#include <rscdefs.h>
#include "msurfcmd.h"
#include <msparse.fdf>
#include <msoutput.fdf>
#include <msstate.fdf>
#include <mslocate.fdf>
#include <mselemen.fdf>
#include <mswindow.fdf>
#include <msrsrc.fdf>
#include <mselmdsc.fdf>
#include <msbsplin.fdf>
#include <msview.fdf>
/*----------------------------------------------------------------------+
| |
| Private Global variables |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Local function declarations |
| |
+----------------------------------------------------------------------*/
/*ff Major Public Code Section */
/*----------------------------------------------------------------------+
| |
| Major Public Code Section |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| name meshSurface_meshFunction |
| |
| author BSI 12/92 |
| |
+----------------------------------------------------------------------*/
Private int meshSurface_meshFunction
(
Dpoint3d *pointP,
Dpoint3d *normalP,
Dpoint2d *paramP,
int nColumns,
int nRows,
void *userDataP
)
{
int iRow, iColumn;
Dpoint3d shapePoints[5];
MSElement element;
for (iRow=0; iRow<nRows-1; iRow++)
for (iColumn=0; iColumn<nColumns-1; iColumn++)
{
shapePoints[0] = shapePoints[4] = pointP[iRow * nColumns + iColumn];
shapePoints[1] = pointP[iRow * nColumns + iColumn + 1];
shapePoints[2] = pointP[(iRow+1) * nColumns + iColumn + 1];
shapePoints[3] = pointP[(iRow+1) * nColumns + iColumn];
mdlShape_create (&element, NULL, shapePoints, 5, -1);
mdlElement_add (&element);
mdlElement_display (&element, NORMALDRAW);
}
return SUCCESS;
}
/*----------------------------------------------------------------------+
| |
| name meshSurface_triangleFunction |
| |
| author BSI 12/92 |
| |
+----------------------------------------------------------------------*/
Private int meshSurface_triangleFunction
(
Dpoint3d *pointP,
Dpoint3d *normalP,
Dpoint2d *paramP,
int nPoints,
void *userDataP
)
{
int i;
Dpoint3d shapePoints[4];
MSElement element;
for (i=2; i<nPoints; i++)
{
shapePoints[0] = shapePoints[3] = pointP[i-2];
shapePoints[1] = pointP[i-1];
shapePoints[2] = pointP[i];
mdlShape_create (&element, NULL, shapePoints, 4, -1);
mdlElement_add (&element);
mdlElement_display (&element, NORMALDRAW);
}
return SUCCESS;
}
/*----------------------------------------------------------------------+
| |
| name meshSurface_accept |
| |
| author BSI 6/90 |
| |
+----------------------------------------------------------------------*/
Private void meshSurface_accept
(
Dpoint3d *pointP,
int view
)
{
int currFile;
double viewScale, uorTolerance;
Dpoint3d delta;
MSWindow *windowP;
Rectangle contentRect;
ULong filePos;
MSElementDescr *edP;
MSBsplineSurface surface;
/* Set the tolerance to be the size of 5 pixels on the screen */
windowP = mdlWindow_viewWindowGet (view);
mdlWindow_contentRectGetGlobal (&contentRect, windowP);
mdlView_getParameters (NULL, NULL, &delta, NULL, NULL, view);
/* Scale from pixels to uors */
viewScale = delta.x / (double) (contentRect.corner.x - contentRect.origin.x);
uorTolerance = 5.0 * viewScale;
filePos = mdlElement_getFilePos (FILEPOS_CURRENT, &currFile);
if (mdlElmdscr_read (&edP, filePos, currFile, FALSE, NULL))
{
if (! mdlBspline_convertToSurface (&surface, edP))
{
mdlBspline_meshSurface (meshSurface_meshFunction,
meshSurface_triangleFunction,
uorTolerance, STROKETOL_ChoordHeight,
NULL, NULL, 0.0, NULL, &surface, FALSE, FALSE, NULL);
mdlBspline_freeSurface (&surface);
}
mdlElmdscr_freeAll (&edP);
}
mdlState_restartCurrentCommand();
}
/*----------------------------------------------------------------------+
| |
| name meshSurface |
| |
| author BSI 11/90 |
| |
+----------------------------------------------------------------------*/
Public void meshSurface
(
void
)
cmdNumber CMD_MESH_SURFACE
{
/* tell MicroStation we want to start a "modification" command */
mdlLocate_allowLocked ();
mdlState_startModifyCommand (meshSurface, meshSurface_accept, NULL,
NULL, NULL, 1, 0, TRUE, FALSE);
/* set the internal locate pointers to start at beginning of file */
mdlLocate_init ();
}
/*----------------------------------------------------------------------+
| |
| name main |
| |
| author BSI 6/90 |
| |
+----------------------------------------------------------------------*/
Public int main
(
void
)
{
RscFileHandle rfHandle;
/* Open our file for access to command table */
mdlResource_openFile (&rfHandle, NULL, FALSE);
/* Load the command table */
if (mdlParse_loadCommandTable (NULL) == NULL)
mdlOutput_error ("Unable to load command table.");
return SUCCESS;
}