home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 January
/
Chip_1997-01_cd.bin
/
ms95
/
disk21
/
dir03
/
f013560.re_
/
f013560.re
Wrap
Text File
|
1996-04-02
|
16KB
|
584 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: cellpick.mc $
| $Revision: 1.10 $
| $Date: 18 Dec 1995 16:50:26 $
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Function - |
| |
| Example MDL program for picking cells |
| |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| |
| Public Routine Summary - |
| |
| cellPick_cellButtonHook - Cell button hook |
| cellPick_drawButton - Handle draw event processing |
| cellPick_drawCell - Draw cell in window |
| cellPick_getCellUorRange - Get cell range block |
| cellPick_initCellInfo - Initialize cell information |
| cellPick_loadLibraryIfNeeded - Load cell library |
| cellPick_reloadFunction - Application reload function |
| cellPick_showCell - Draw cell in dialog box |
| main - main entry point |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Include Files |
| |
+----------------------------------------------------------------------*/
#include <mdl.h>
#include <mselems.h>
#include <dlogitem.h>
#include <userfnc.h>
#include <tcb.h>
#include <cmdlist.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "cellpick.h" /* Need to know the dialog id to open */
#include <msfile.fdf>
#include <msview.fdf>
#include <mssystem.fdf>
#include <msrmatrx.fdf>
#include <msrsrc.fdf>
#include <msvec.fdf>
#include <mselmdsc.fdf>
#include <mscell.fdf>
#include <mscnv.fdf>
#include <dlogman.fdf>
/*----------------------------------------------------------------------+
| |
| Local type declarations |
| |
+----------------------------------------------------------------------*/
typedef struct cellbuttoninfo
{
char cellName[7];
char libName[MAXFILELENGTH];
boolean libAvailable;
}
CellButtonInfo;
/*----------------------------------------------------------------------+
| |
| Local function declarations |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Private Global variables |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| name cellpick_checkCellLibrary |
| |
| author BSI 11/95 |
| |
+----------------------------------------------------------------------*/
Private int cellpick_checkCellLibrary
(
boolean *isThreeD, /* <= TRUE if file is 3d */
char *fileName /* => filename */
)
{
int status=SUCCESS;
FILE *fp;
short firstWord;
short element, dimens;
if ((NULL == fileName) || (!isThreeD))
return MDLERR_BADARG;
if (NULL != (fp = fopen (fileName, "rb")))
{
fread (&firstWord, 1, sizeof(firstWord), fp);
/* get the fread status */
status = ferror(fp);
if (SUCCESS != status)
{
fclose (fp);
return MDLERR_READFAILED;
}
# if !defined (BIG_ENDIAN)
element = (firstWord & 0xff00) >> 8;
dimens = (firstWord & 0x00c0) >> 6;
# else
element = (firstWord & 0xff);
dimens = (firstWord & 0xc000);
# endif
/* check if the elment type is cell library header */
if (GROUP_DATA_ELM == element)
{
if (0 != dimens)
*isThreeD = TRUE;
else
*isThreeD = FALSE;
}
else
{
status = MDLERR_BADFILETYPE;
}
fclose (fp);
return status;
}
else
{
return MDLERR_CANNOTOPENFILE;
}
return status;
}
/*----------------------------------------------------------------------+
| |
| name cellPick_getCellUorRange |
| |
| author BSI 7/90 |
| |
+----------------------------------------------------------------------*/
Private void cellPick_getCellUorRange
(
Dvector3d *cellRange,
MSElement *cellHeader
)
{
long iCellRange[6];
int i;
memcpy (iCellRange, &cellHeader->ehdr.xlow, sizeof(iCellRange));
for (i=0; i<6; i++)
iCellRange[i] = mdlCnv_fromScanFormat (iCellRange[i]);
cellRange->org.x = (double) iCellRange[0];
cellRange->org.y = (double) iCellRange[1];
cellRange->org.z = (double) iCellRange[2];
cellRange->end.x = (double) iCellRange[3];
cellRange->end.y = (double) iCellRange[4];
cellRange->end.z = (double) iCellRange[5];
}
/*----------------------------------------------------------------------+
| |
| name cellPick_initCellInfo |
| |
| author BSI 6/91 |
| |
+----------------------------------------------------------------------*/
Private void cellPick_initCellInfo
(
char *labelField,
char *libName,
char *cellName,
boolean *libAvailable
)
{
int status;
char libFile[MAXFILELENGTH];
int libFileLength;
boolean isThreeD;
*libAvailable = TRUE;
if (libFileLength = strcspn (labelField, ";"))
{
strncpy (libFile, labelField, libFileLength);
libFile[libFileLength] = '\0';
strncpy (cellName, labelField + libFileLength +1, 6);
cellName[6] = '\0';
if (mdlFile_find (libName, libFile, "MS_CELL", "cel"))
{
*libName = '\0';
*libAvailable = FALSE;
return;
}
/* check if the file is a cell library & get its dimension*/
status = cellpick_checkCellLibrary (&isThreeD, libName);
if (SUCCESS == status)
{
/* check for a dimension mismatch (2d dgn file & 3d cell library)*/
if ((FALSE == mgds_modes.three_d) && (TRUE == isThreeD))
{
*libAvailable = FALSE;
# if defined (DEBUG_PRINT)
printf("For cell %s, cell library %s is 3D & dgn file is 2D\n",
cellName, libName);
# endif
}
}
else
{
*libAvailable = FALSE;
}
}
else
{
strncpy (cellName, labelField, 6);
cellName[6] = *libName = '\0';
*libAvailable = FALSE;
}
}
/*----------------------------------------------------------------------+
| |
| name cellPick_loadLibraryIfNeeded |
| |
| author BSI 6/91 |
| |
+----------------------------------------------------------------------*/
Private int cellPick_loadLibraryIfNeeded
(
char *libToLoad,
boolean *libAvailable
)
{
int status = SUCCESS;
char libName[MAXFILELENGTH];
boolean isThreeD;
if (*libToLoad)
{
if (0 == strcmp (libToLoad, tcb->celfilenm))
{
*libAvailable = TRUE;
return status;
}
/* check if the file is a cell library & get its dimension*/
status = cellpick_checkCellLibrary (&isThreeD, libToLoad);
if (SUCCESS == status)
{
/* check for a dimension mismatch (2d dgn file & 3d cell library)*/
if ((FALSE == mgds_modes.three_d) && (TRUE == isThreeD))
{
*libAvailable = FALSE;
}
else
{
status=mdlCell_attachLibrary (libName, libToLoad, NULL, TRUE);
if (SUCCESS == status)
{
*libAvailable = TRUE;
}
else
{
*libAvailable = FALSE;
}
}
}
else
{
*libAvailable = FALSE;
}
}
return status;
}
/*----------------------------------------------------------------------+
| |
| name cellPick_drawCell |
| |
| author BSI 7/90 |
| |
+----------------------------------------------------------------------*/
Private int cellPick_drawCell
(
DialogBox *dbP,
Rectangle *displayRectP,
MSElementDescr *edP,
Dvector3d *cellRangeP,
int stdViewNum,
int threeD
)
{
RotMatrix rotMatrix;
Dpoint3d cellExtent, origin;
Dvector3d localRange = *cellRangeP;
Viewflags viewflags;
mdlView_getStandard (&rotMatrix, stdViewNum);
mdlRMatrix_rotateRange (&localRange.org, &localRange.end, &rotMatrix);
memset (&viewflags, 0, sizeof(viewflags));
viewflags.patterns = 1;
viewflags.ed_fields = 1;
viewflags.on_off = 1;
viewflags.points = 1;
viewflags.constructs = 1;
viewflags.dimens = 1;
mdlVec_subtractPoint (&cellExtent, &localRange.end, &localRange.org);
mdlRMatrix_unrotatePoint (&localRange.org, &rotMatrix);
return (mdlElmdscr_displayToWindow (dbP, displayRectP, &viewflags, edP,
&rotMatrix, &localRange.org, &cellExtent, threeD, -1));
}
/*----------------------------------------------------------------------+
| |
| name cellPick_showCell |
| |
| author BSI 6/89 |
| |
+----------------------------------------------------------------------*/
Private void cellPick_showCell
(
DialogBox *dbP,
char *cellName,
Rectangle *cellRect,
int threeD
)
{
Rectangle displayRect;
Rectangle quadRect;
Dvector3d cellUorRange;
Point2d center;
int whichView;
MSElementDescr *cellDescrP;
/* figure out the area available for our rectangle */
displayRect = *cellRect;
mdlDialog_rectInset (&displayRect, 3, 3);
if (cellName == NULL || !mdlCell_existsInLibrary (cellName))
return;
/* get the cell element */
if (mdlCell_getElmDscr (&cellDescrP, NULL, NULL, NULL, NULL,
NULL, NULL, 0, FALSE, cellName))
return;
mdlElmdscr_validate (cellDescrP, CELL_LIB);
cellPick_getCellUorRange (&cellUorRange, &cellDescrP->el);
if (threeD)
whichView = STDVIEW_ISO;
else
whichView = STDVIEW_TOP;
cellPick_drawCell (dbP, &displayRect, cellDescrP, &cellUorRange,
whichView, threeD);
/* free the element descriptor */
mdlElmdscr_freeAll (&cellDescrP);
}
/*----------------------------------------------------------------------+
| |
| name cellPick_drawButton |
| |
| author BSI 6/90 |
| |
+----------------------------------------------------------------------*/
Private void cellPick_drawButton
(
RawItemHdr *rihP,
char *cellName,
int eraseFirst
)
{
DialogBox *db = rihP->ownerDialogP;
Rectangle *itemRectP = &rihP->diP->rect;
if (eraseFirst)
mdlWindow_rectClear (db, itemRectP, NULL);
mdlDialog_rectDrawBeveled (db, itemRectP,
!rihP->highlightOn, TRUE);
cellPick_showCell(db, cellName, itemRectP, tcb->fbfdcn.library3d);
}
/*----------------------------------------------------------------------+
| |
| name cellPick_cellButtonHook |
| |
| author BSI 6/90 |
| |
+----------------------------------------------------------------------*/
Private void cellPick_cellButtonHook
(
DialogItemMessage *dimP
)
{
DialogItem *diP = dimP->dialogItemP;
RawItemHdr *rihP = dimP->dialogItemP->rawItemP;
CellButtonInfo *cellInfoP = rihP->userDataP;
dimP->msgUnderstood = TRUE;
switch (dimP->messageType)
{
case DITEM_MESSAGE_CREATE:
diP->attributes.acceptsKeystrokes = FALSE;
break;
case DITEM_MESSAGE_INIT:
{
cellInfoP = calloc (1, sizeof (CellButtonInfo));
if (NULL == cellInfoP)
{
dimP->u.init.initFailed = TRUE;
break;
}
cellPick_initCellInfo (rihP->labelP, cellInfoP->libName,
cellInfoP->cellName, &cellInfoP->libAvailable);
rihP->userDataP = cellInfoP;
}
break;
case DITEM_MESSAGE_DRAW:
if (SUCCESS ==
cellPick_loadLibraryIfNeeded (cellInfoP->libName,
&cellInfoP->libAvailable))
{
if (TRUE == cellInfoP->libAvailable)
{
/* Set the text of the label displaying the name of the cell,
this label follows immediately after the cell button
in the dialog definition in the .r file */
mdlDialog_itemSetLabel (dimP->db, dimP->itemIndex+1,
cellInfoP->cellName);
cellPick_drawButton (rihP, cellInfoP->cellName,
dimP->u.draw.eraseFirst);
}
else
{
mdlDialog_itemSetLabel (dimP->db, dimP->itemIndex+1, "");
}
}
break;
case DITEM_MESSAGE_HIGHLIGHT:
/* If the cell library is not available then break */
if (FALSE == cellInfoP->libAvailable)
break;
mdlDialog_rectDrawBeveled (dimP->db, &diP->rect,
!dimP->u.highlight.highlightOn, TRUE);
break;
case DITEM_MESSAGE_BUTTON:
if ((dimP->u.button.buttonNumber != DATAPNT) ||
(dimP->u.button.buttonTrans != BUTTONTRANS_UP))
break;
/* If the cell library is not available then break */
if (FALSE == cellInfoP->libAvailable)
break;
/* If the user lets up on the mouse button, make the button look
like it popped back up... */
mdlDialog_rectDrawBeveled (dimP->db, &diP->rect,
TRUE, TRUE);
/* make sure the correct library is attached.*/
if (SUCCESS == cellPick_loadLibraryIfNeeded (cellInfoP->libName,
&cellInfoP->libAvailable))
{
if (TRUE == cellInfoP->libAvailable)
/* and fire off a command to change the active cell. */
mdlDialog_cmdNumberQueue (FALSE, rihP->itemHookArg,
cellInfoP->cellName, FALSE);
}
break;
default:
dimP->msgUnderstood = FALSE;
break;
}
}
/*----------------------------------------------------------------------+
| |
| name cellPick_reloadFunction |
| |
| author BSI 9/90 |
| |
+----------------------------------------------------------------------*/
Private void cellPick_reloadFunction
(
void
)
{
/* Open the dialog */
mdlDialog_open (NULL, DIALOGID_CellPicker);
}
/*----------------------------------------------------------------------+
| |
| name main |
| |
| author BSI 8/89 |
| |
+----------------------------------------------------------------------*/
static DialogHookInfo uHooks[] =
{
{HOOKITEMID_CellButton, cellPick_cellButtonHook},
};
Public int main
(
int argc,
char *argv[]
)
{
char *setP;
RscFileHandle rfHandle;
/* Open our file for access to dialog */
mdlResource_openFile (&rfHandle, NULL, RSC_READ);
/* Publish the dialog item hooks */
mdlDialog_hookPublish (sizeof(uHooks)/sizeof(DialogHookInfo), uHooks);
/* If user tries to load the application when it's already loaded,
bring the dialog back up. */
mdlSystem_setFunction (SYSTEM_RELOAD_PROGRAM, cellPick_reloadFunction);
cellPick_reloadFunction();
return SUCCESS;
}