Surfcam 2005 API
Surfcam 2005 API
Dat ab ase F u n ct io n s
T o o l L ib rary F u n ct io n s
SURF CAM L ist b o x Dialo g F u n ct io n s
T o o lp at h F u n ct io n s
TSH/v 5-11
SURFCAM 2005 • API Documentation Table of Contents
iii
SURFCAM 2005 • API Documentation Table of Contents
Contents
Preface ......................................................................................................................................................... xi
i
Table of Contents SURFCAM 2005 • API Documentation
View Functions...................................................................................................................29
Vector Functions ................................................................................................................30
Point Functions...................................................................................................................32
Line Functions ....................................................................................................................33
Polyline Functions ..............................................................................................................33
Line Mesh Functions ..........................................................................................................34
Arc Functions .....................................................................................................................34
Conic Functions..................................................................................................................35
NURB Curve Functions .....................................................................................................35
NURB Surface Functions ...................................................................................................37
ii
SURFCAM 2005 • API Documentation Table of Contents
scDist_FpointFpoint......................................................................................................... 70
scDist_FpointFpoint2d..................................................................................................... 72
scDist_PointPoint ............................................................................................................ 67
scDist_PointPoint2dVec .................................................................................................. 68
scElement_DeleteElement ............................................................................................... 69
scElement_Final............................................................................................................... 70
scElement_GetArc ........................................................................................................... 71
scElement_GetColorAttrib .............................................................................................. 72
scElement_GetCount ....................................................................................................... 73
scElement_GetLayer........................................................................................................ 74
scElement_GetLayerAttrib ............................................................................................. 75
scElement_GetLine.......................................................................................................... 76
scElement_GetLmesh ...................................................................................................... 77
scElement_GetNurbCurve ............................................................................................... 78
scElement_GetNurbSurface............................................................................................. 79
scElement_GetPline......................................................................................................... 80
scElement_GetPoint......................................................................................................... 81
scElement_GetText...........................................................................................................??
scElement_GetType......................................................................................................... 82
scElement_GetTypeFromHandle..................................................................................... 83
scElement_GetVector ...................................................................................................... 84
scElement_GetView ........................................................................................................ 85
scElement_GetVisibleAttrib............................................................................................ 86
scElement_InitHandle...................................................................................................... 87
scElement_NextHandle ................................................................................................... 88
scElement_SetColorAttrib ............................................................................................... 89
scElement_SetColorAttribEx ........................................................................................ 102
scElement_SetLayerAttrib ............................................................................................... 91
scElement_SetLayerAttribEx........................................................................................... 92
scElement_ValidHandle .................................................................................................. 93
scElement_WriteToDB.................................................................................................... 94
scFVec_Add................................................................................................................... 229
scFVec_FPointFPoint .................................................................................................... 246
scFVec_Magnitude ........................................................................................................ 242
scFVec_Normalize......................................................................................................... 246
scFVec_Scale................................................................................................................. 252
scLayer_AllocMem.......................................................................................................... 95
scLayer_FindFreeLayer.................................................................................................... 96
scLayer_FindNextAllocLayer.......................................................................................... 97
scLayer_FindNextFreeLayer............................................................................................ 98
scLayer_GetAttrib............................................................................................................ 99
scLayer_GetFromHandle ............................................................................................... 106
scLayer_GetLayerFromHandle ...................................................................................... 100
iii
Table of Contents SURFCAM 2005 • API Documentation
scLayer_GetName ..........................................................................................................101
scLayer_SetLayerVisibility ..............................................................................................56
scLayer_WriteToDB.......................................................................................................102
scLine_AllocMem ..........................................................................................................103
scLine_WriteToDB ........................................................................................................104
scList_BackWalk............................................................................................................105
scList_Concat .................................................................................................................106
scList_Final ....................................................................................................................107
scList_GetHead ..............................................................................................................108
scList_GetNext ...............................................................................................................109
scList_GetPrev ...............................................................................................................110
scList_GetTail ................................................................................................................111
scList_Init .......................................................................................................................112
scList_InsertElement ......................................................................................................113
scList_InsertHead ...........................................................................................................114
scList_InsertTail .............................................................................................................115
scList_IsEmpty ...............................................................................................................116
scList_MoveElement......................................................................................................117
scList_MoveHead...........................................................................................................118
scList_MoveTail.............................................................................................................119
scList_NumElements......................................................................................................120
scList_Reinit...................................................................................................................142
scList_RemoveAll ..........................................................................................................121
scList_RemoveElement..................................................................................................122
scList_RemoveHead.......................................................................................................123
scList_RemoveTail.........................................................................................................124
scList_Sort......................................................................................................................125
scList_Walk....................................................................................................................126
scLmesh_AllocMem.......................................................................................................127
scLmesh_GetPoints ........................................................................................................128
scLmesh_WriteToDB.....................................................................................................129
scMat_GetRotation.........................................................................................................130
scMat_Identity................................................................................................................131
scMat_Inverse.................................................................................................................132
scMat_InverseTransform................................................................................................133
scMat_InverseTransform2d............................................................................................134
scMat_Multiply ..............................................................................................................135
scMat_OrthoInverse .......................................................................................................136
scMat_SetColumn ..........................................................................................................137
scMat_Transform ...........................................................................................................138
scMat_Transform2d .......................................................................................................139
scMat_Transpose............................................................................................................140
scMem_Alloc .................................................................................................................141
scMem_CheckAlloc .......................................................................................................142
iv
SURFCAM 2005 • API Documentation Table of Contents
v
Table of Contents SURFCAM 2005 • API Documentation
scNsurf_GetNormalDirectionAttrib ...............................................................................176
scNsurf_GetNumberOfULinesAttrib .............................................................................177
scNsurf_GetNumberOfVLinesAttrib .............................................................................178
scNsurf_GetPolyDisplayAttrib.......................................................................................179
scNsurf_GetSpan............................................................................................................180
scNsurf_GetRange..........................................................................................................190
scNsurf_GetRationalAttrib.............................................................................................181
scNsurf_IsDegeneratedClosed........................................................................................195
scNsurf_NurbGrid ..........................................................................................................182
scNsurf_NurbListAutoSort.............................................................................................183
scNsurf_Offset................................................................................................................195
scNsurf_ProjectPoint………………………………………………………………….. 187
scNsurf_ProjectPointParam............................................................................................188
scNsurf_ProjectPointSide...............................................................................................215
scNsurf_RemoveKnots...................................................................................................184
scNsurf_Revolution........................................................................................................185
scNsurf_Ruled ................................................................................................................186
scNsurf_SetArrowDisplayAttrib ....................................................................................187
scNsurf_SetArrowPositionAttrib ...................................................................................188
scNsurf_SetCutDirectionAttrib ......................................................................................189
scNsurf_SetNormalDirectionAttrib................................................................................190
scNsurf_SetNumberOfULinesAttrib ..............................................................................191
scNsurf_SetNumberOfVLinesAttrib ..............................................................................192
scNsurf_SetPolyDisplayAttrib .......................................................................................193
scNsurf_SetRange ..........................................................................................................194
scNsurf_SetRationalAttrib .............................................................................................195
scNsurf_WriteToDB.......................................................................................................196
scPlane_VectorPoint ......................................................................................................197
scPline_AllocMem .........................................................................................................198
scPline_ElementToPline ................................................................................................199
scPline_WriteToDB .......................................................................................................200
scPoint_AllocMem.........................................................................................................201
scPoint_ArcEnd..............................................................................................................202
scPoint_GetMinMax ......................................................................................................227
scPoint_OppositeSideOfLine .........................................................................................203
scPoint_OppositeSideOfVector......................................................................................204
scPoint_PointVecParam .................................................................................................211
scPoint_ProjectToLine ...................................................................................................205
scPoint_ProjectToPlane..................................................................................................206
scPoint_WriteToDB .......................................................................................................207
scSafe_acos.....................................................................................................................208
scSafe_atof .....................................................................................................................209
scSafe_atoi......................................................................................................................210
scSafe_sprintf .................................................................................................................211
vi
SURFCAM 2005 • API Documentation Table of Contents
vii
Table of Contents SURFCAM 2005 • API Documentation
scXForm_TranslateAbs..................................................................................................297
scXForm_Rotate….........................................................................................................298
scXForm_Scale...............................................................................................................299
scXForm_ScaleXYZ ......................................................................................................300
scXForm_Mirror.............................................................................................................301
scXForm_TranslateRelUI...............................................................................................302
scXForm_TranslateAbsUI..............................................................................................303
scXForm_RotateUI.........................................................................................................304
scXForm_ScaleUI ..........................................................................................................305
scXForm_ScaleXYZUI ..................................................................................................306
scXForm_MirrorUI ........................................................................................................307
scXForm_TranslateRelUISel..........................................................................................308
scXForm_TranslateAbsUISel.........................................................................................309
scXForm_RotateUISel ...................................................................................................310
scXForm_ScaleUISel .....................................................................................................311
scXForm_ScaleXYZUISel .............................................................................................312
scXForm_MirrorUISel ...................................................................................................313
scXForm_ToViewUISel.................................................................................................314
viii
SURFCAM 2005 • API Documentation Table of Contents
ix
Table of Contents SURFCAM 2005 • API Documentation
x
SURFCAM 2005 • API Documentation Table of Contents
xi
Table of Contents SURFCAM 2005 • API Documentation
xii
SURFCAM 2005 • API Documentation Table of Contents
Preface
This volume contains the full documentation for three separate SURFCAM
application programming interfaces (APIs) in three parts. Part I documents the
SURFCAM Database API, which allows access to SURFCAM’s geometry
functions and element database. Part II documents the SURFCAM Listbox dialog
API. Part III contains information on the SURFCAM Tool and Materials Library
API.
SURFCAM also provides access to the tool and materials library through the API.
The tools and materials in the tool and materials library can be retrieved as data
structures, or retrieved through the graphical user interface provided in the tool
library Dynamic Link Library (DLL). More complete management of the tool and
materials databases can be provided by standard ODBC software tools.
xiii
Table of Contents SURFCAM 2005 • API Documentation
xiv
SURFCAM 2005 • API Documentation Table of Contents
Part I
xv
Table of Contents SURFCAM 2005 • API Documentation
xvi
SURFCAM 2005 • API Documentation Chapter 9 Toolpath API
Chapter 1
Introduction
The scope of the database API functions focuses on creating, retrieving, and
manipulating elements in the database of SURFCAM geometric entities. After
first constructing or retrieving a database of SURFCAM elements, the elements
(such as points, lines, splines, and NURB surfaces) can be scaled, mirrored, and
transformed in various ways. There are functions that retrieve and modify the
layer and color properties of elements, that measure the distances between points
in space and control points of a NURB surface, that determine the slope of a
NURB surface at a particular location. SURFCAM’s API provides functions to
easily manage the list of elements in the database, allowing functions to be
applied to specified elements in the list.
1
Chapter 1 Introduction SURFCAM 2005 • API Documentation
WHAT IS REQUIRED?
In order to take advantage of SURFCAM’s API, the programmer will require a
licensed copy of SURFCAM V7.0A Build 106 or higher. The programmer will
also require four header files: expfunc.h, dllstrct.h, dllelems.h, and stackdll.h.
2
SURFCAM 2005 • API Documentation Chapter 1 Introduction
MISCELLANEOUS FUNCTIONS
The API also has a group of functions to create and manipulate general lists and
general stacks. After initializing a list, the list as accessed through its handle.
Functions to add and remove list elements manipulate the list contents, and
operations such as sort and reverse can be performed on the list. Stacks are
simpler forms of lists, with only push, pop, and peek operations.
There are also “safe” functions in the API. These functions are versions of their
standard counterparts with extended error checking, preventing runtime errors and
allowing wider ranges of input values.
3
Chapter 2 Step-By-Step Tutorial SURFCAM 2005 • API Documentation
Chapter 2
Step-By-Step
Tutorial on Creating
a Custom DLL
A Dynamic Link Library (DLL) must satisfy several conditions in order to take
advantage of the SURFCAM API. The SURFCAM API functions are based on
the C computer language, therefore a C or C++ development environment is
recommended. DLLs created using the API functions are accessible only through
SURFCAM’s FileOpen and FileSaveAs dialogs. The required steps necessary to
create a DLL using the SURFCAM API are as follows:
SURFCAM will not recognize nor call any custom DLL without an entry in the
SURFCAM.INI file. Open this file and examine the last section, headed by the
string “[FileOpenSave]”.
[FileOpenSave]
DSN=DSN Files(*.DSN), "*.dsn;*.tle;*.tlm;*.tmp",,,dsnread,dsnwrite,C:\surfcam\dsn,APPEND_FALSE
...
IGS=IGS Files(*.IGS),
"*.igs",igs2dsn.dll,dsn2igs.dll,SurfcamDllEntryPoint,SurfcamDllEntryPoint,C:\surfcam\igs,APPEND_FALSE
...
4
SURFCAM 2005 • API Documentation Chapter 2 Step-By-Step Tutorial
Each file type is associated with a “key”, which identifies each entry to
SURFCAM. Each key holds eight different entries.
1. The file type entry as it will appear in the FileOpen or FileSaveAs dialog.
2. The extension of the file type, which filters the files shown in the FileOpen or FileSaveAs
dialog.
3. The DLL called by SURFCAM after selecting a file in FileOpen.
4. The DLL called by SURFCAM after selecting a file in FileSaveAs.
5. The name of the entry function called first by SURFCAM (see Step 2 below) in the DLL
called after FileOpen.
6. The name of the entry function called first by SURFCAM (see Step 2 below) in the DLL
called after FileSaveAs.
7. The default directory for the FileOpen or FileSaveAs dialog.
8. The default value for the Append flag in the FileOpen dialog. Append preserves the existing
database of elements.
The IGES file type, for example, has the key “IGS”. SURFCAM is instructed to
call the DLL igs2dsn.dll after the FileOpen dialog, and the DLL dsn2igs.dll after
the FileSaveAs dialog. The name of the entry function in igs2dsn.dll is
SurfcamDllEntryPoint. The name of the entry function in dsn2igs.dll is also
SurfcamDllEntryPoint. IGES files are normally stored in the C:\surfcam\igs
directory.
The form for any custom DLL must be similar. For example, a DLL to take
existing geometry and create a family of parts using settings stored in files of type
“.fam” or “.txt” would only be used after a FileOpen. A valid addition to the INI
file would be similar to the following:
FAM=FAM Files(*.fam), “*.fam;*.txt”,family.dll,,MyDllEntryFunction,,C:\MyDirectory,APPEND_TRUE
SURFCAM calls the entry function within the custom DLL from the FileOpen or
FileSaveAs dialogs. SURFCAM knows the name of the entry function from the
SURFCAM.INI file, so the name of the entry function will correspond to that
character string. SURFCAM passes three arguments to this function; the
arguments for this function MUST be the following (in this order):
5
Chapter 2 Step-By-Step Tutorial SURFCAM 2005 • API Documentation
The coded section name consists of the section in the INI file and the file type key
associated with the DLL call – this key is appended after the section name. In the
IGES translator, for example, the passed section name string would be
“FileOpenSave_IGS”.
The following is an example of the most basic entry function. Note that the
character strings were not used in this particular example.
#if defined(__cplusplus)
extern "C"
{
#endif
__declspec(dllexport) int
MyDllEntryFunction(char *ini_file_name,
char *section_name,
char *file_name)
{
MyMainFunction(); // Main function
return(TRUE);
}
#if defined(__cplusplus)
}
#endif
Although Steps 1 and 2 provide all the steps necessary to access the API
functions, the functions will have minimal utility without access to the
SURFCAM database of elements. The API provides both the function and the
handle variable to permit the DLL to both read from and write to the database.
The handle type is HSC_DB. Use the function scDB_GetHandle( ) to retrieve
the SURFCAM database handle. The database handle is used for all functions
involving reading from and writing to the database.
6
SURFCAM 2005 • API Documentation Chapter 2 Step-By-Step Tutorial
HSC_DB hSurfcamDatabase;
hSurfcamDatabase = scDB_GetHandle();
Retrieving the handle to the SURFCAM window uses a similar process. The
window handle is used for Win32 API functions for Windows 95 and Windows
NT environments.
HWND hSurfcamWindow;
hSurfcamWindow = scApp_GetWindowHandle();
The elements in the database can be accessed through their handles. At present,
the program must use two functions to retrieve element handles:
scElement_InitHandle and scElement_NextHandle. In order to walk through
the entire database of elements, a loop such as the following is recommended.
HSC_Element hSurfcamElement;
This loop will iterate the element handle for every element in the database. The
element handle may either be stored in a list, or the element data may be read
from the handle within the loop.
Reading the element data from the element handle requires two steps: the type of
element must be determined, then the data must be read into the appropriate
element data structure.
if(scElement_GetTypeFromHandle(hSurfcamElement) == SC_Point) {
SC_Point *Point;
Point = scElement_GetPoint(hSurfcamElement);
...
}
7
Chapter 2 Step-By-Step Tutorial SURFCAM 2005 • API Documentation
Elements in the SURFCAM database possess information beyond that in the basic
data structures. Each element also has color and layer assignment data; therefore,
writing just the element data structure to the database is insufficient. In order to
create an element that contains this information, the AllocMem functions must be
used.
pPoint = scPoint_AllocMem();
rather than:
SC_Point Point;
Elements created using AllocMem may be properly written to the database using
WriteToDB functions.
Each file that uses SURFCAM API functions must include the expfunc.h header
file. The files expfunc.h, stackdll.h, dllstrct.h and dllelems.h must reside in the
compiler include directory. The linker must link to the API library.
8
SURFCAM 2005 • API Documentation Chapter 3 SURFCAM Symbols and Structures
Chapter 3
SURFCAM Symbols
and Structures
9
Chapter 3 SURFCAM Symbols and Structures SURFCAM 2005 • API Documentation
10
SURFCAM 2005 • API Documentation Chapter 3 SURFCAM Symbols and Structures
1
HSC_DB is an unsigned long
11
Chapter 3 SURFCAM Symbols and Structures SURFCAM 2005 • API Documentation
12
SURFCAM 2005 • API Documentation Chapter 3 SURFCAM Symbols and Structures
13
Chapter 3 SURFCAM Symbols and Structures SURFCAM 2005 • API Documentation
2
Table 2.20 SC_Conic Structure Members
2
Note that SC_Conic elements can only be defined in the X-Y plane. To define a conic element
outside of the X-Y plane, the conic element must first be defined in the X-Y plane, and then
transformed.
14
SURFCAM 2005 • API Documentation Chapter 3 SURFCAM Symbols and Structures
15
Chapter 4 Function Summary Tables SURFCAM 2005 • API Documentation
Chapter 4
Function Summary
Tables
16
SURFCAM 2005 • API Documentation Chapter 4 Function Summary Tables
17
Chapter 4 Function Summary Tables SURFCAM 2005 • API Documentation
List Functions
List memory allocation functions
scList_Init Allocates memory and initializes the list. 112
scList_Final Deletes the list and free the memory used by the list. 107
18
SURFCAM 2005 • API Documentation Chapter 4 Function Summary Tables
19
Chapter 4 Function Summary Tables SURFCAM 2005 • API Documentation
Safe Functions
Safe functions
scSafe_acos Returns the arc-cosine of a number, returning acos(1) for 209
numbers greater than 1 and acos(-1) for numbers less than -1.
scSafe_atof Returns a floating point decimal, clipping excess characters. 210
scSafe_atoi Returns an integer, clipping excess characters. 211
scSafe_sprintf Prints a string to a buffer, clipping excess characters. 212
scSafe_sqrt Returns the square-root of a number or zero. 213
scSafe_strcat Concatenates two strings, clipping excess characters. 214
scSafe_strcpy Copies two strings, clipping excess characters. 215
20
SURFCAM 2005 • API Documentation Chapter 4 Function Summary Tables
Select functions
scApp_SelectionInit Provides SURFCAM selector options (masks, selections, etc.). 51
scApp_SelectionFinal Must follow scApp_SelectionInit. 50
21
Chapter 4 Function Summary Tables SURFCAM 2005 • API Documentation
Convert elements
scNcurve_ElementToNurb Converts an element to a NURB curve. 154
scPline_ElementToPline Converts an element to a polyline. 199
22
SURFCAM 2005 • API Documentation Chapter 4 Function Summary Tables
Evaluation Functions
Memory-level Evaluation
scMem_CheckAlloc Checks to see if memory was allocated by SURFCAM at a 140
specified address.
scMem_CheckAllocList Checks the validity of the “malloc” allocated list (i.e. checks 141
all the memory blocks allocated by SURFCAM).
scMem_CountAllocList Counts the number of memory allocations made by 142
SURFCAM.
scStack_Peek Checks the value of the top of the stack. 218
Application-level Evaluation
scApp_GetCurrentColor Gets the current color from SURFCAM. 41
scApp_GetCurrentLayer Gets the current layer from SURFCAM. 42
scApp_GetIniFileName Get Surfcam ini file name ??
scApp_GetInstanceHandle Gets the DLL handle from SURFCAM. 43
scApp_GetNumLayers Gets the number of layers. 44
scApp_GetTitle Reads in the window title from SURFCAM. 45
scApp_GetUnikKnots Get the list of unique knot vector 49
scApp_GetUnitType Get Surfcam unit type 50
scApp_GetWindowHandle Gets the window handle from SURFCAM. 46
scApp_LayerActive Checks to see whether a specified layer is active. 47
scApp_LayerAlloc Checks to see whether a specified layer is allocated. 48
scApp_LayerVisible Checks to see whether a specified layer is visible. 49
scView_GetCview Retrieves the construction view. 248
scView_GetView Retrieves the current view. 249
Database Evaluation
scElement_GetCount Retrieves the total number of elements from the database. 73
scLayer_FindFreeLayer Finds the first free (unallocated) layer. 96
scLayer_FindNextAllocLayer Finds the first allocated layer above a specified layer. 97
scLayer_FindNextFreeLayer Finds the first free (unallocated) layer with a reference 98
number higher than that of a specified layer.
Element Evaluation
scElement_GetType Determines the type of an element (arc, line, point, etc.) from 82
the element pointer.
scElement_GetTypeFromHandle Determines the type of an element (arc, line, point, etc.) from 83
the element handle.
scElement_GetColorAttrib Retrieves the color of an element from the database. 72
scElement_GetLayerAttrib Retrieves the layer of an element from the database. 75
23
Chapter 4 Function Summary Tables SURFCAM 2005 • API Documentation
Layer Evaluation
scLayer_GetAttrib Gets the attributes for a specified layer. 99
scLayer_GetFromHandle Gets the layer number from the current element handle. 106
scLayer_GetLayerFromHandle Gets the layer number from the current element handle. 100
scLayer_GetName Gets the name for a specified layer. 101
View Evaluation
scView_Compare Compares two specified views for homogeneity within a 247
specified tolerance (checks to see if the views are identical).
Point Evaluation
scDist_FpointFpoint Evaluates the linear distance between two points. 70
scDist_FpointFpoint2d Evaluates the 2-d distance between two points. 72
scDist_PointPoint Evaluates the linear distance between two points. 67
scDist_PointPoint2dVec Evaluates the 2-d distance between two points. 68
scPoint_OppositeSideOfVector Determines if two points lie on opposite sides of a given 204
vector.
Curve Evaluation
scCurve_EvalLengthInit Evaluates the length of an arc or curve. 62
scCurve_EvalLengthFinal Must follow scCurve_EvalLengthInit. 61
scCurve_Eval Evaluates a point on a curve at a specified curve parameter. 60
scCurve_GetRange Determines the span range given the curve parameters. 63
scNcurve_GetPolyDisplayAttrib Determines if the polygon is displayed for a NURB curve. 159
scNcurve_GetRationalAttrib Determines if the NURB curve is rational. 160
24
SURFCAM 2005 • API Documentation Chapter 4 Function Summary Tables
25
Chapter 4 Function Summary Tables SURFCAM 2005 • API Documentation
Element-to-polyline
scPline_ElementToPline Converts an element to a polyline. 199
Curves-to-loop
scNcurve_ChainNurbs Converts a set of curves to a curve chain (a loop). 149
NURB surface-to-polygon
scNsurf_ConvertToPolygon Converts a NURB surface to an approximated surface 169
composed of polygons (triangles).
26
SURFCAM 2005 • API Documentation Chapter 4 Function Summary Tables
Transformation Functions
Matrix transformation functions
scMat_GetRotation Constructs a matrix given a specified vector. 130
scMat_Identity Converts a matrix into an identity matrix. 131
scMat_Inverse Calculates the inverse of a specified matrix. 132
scMat_InverseTransform Calculates the inverse transform of a specified transform 133
matrix.
scMat_InverseTransform2d Calculates the inverse transform (using x and y axes only) of a 134
specified transform matrix.
scMat_Multiply Calculates the product of two specified matrices. 135
scMat_OrthoInverse Calculates the orthogonal inverse of a specified matrix. 136
scMat_SetColumn Set column of the matrix 137
scMat_Transform Transforms a three dimensional point given a matrix. 138
scMat_Transform2d Transform a 2D point 139
scMat_Transpose Calculates the transpose of a specified matrix. 140
Element transformations
scConic_TransformToStandard Transforms the position and orientation of a conic in space to 59
standard position and orientation.
scNcurve_Reverse Reverses the direction of a NURB curve. 164
scXForm_Element Transform element 295
scXForm_TranslateRel Translate element by relative distance 296
scXForm_TranslateAbs Translate element to absolute location 297
scXForm_Rotate Rotate element around a point 298
scXForm_Scale Scale a vector 299
scXForm_ScaleXYZ Scale an element by two points 300
scXForm_Mirror Mirror transformation along the line defined by two points 301
scXForm_TranslateRelUI Translate element by relative distance with UI 302
scXForm_TranslateAbsUI Translate element to absolute location with UI 303
scXForm_RotateUI Rotate element with UI 304
scXForm_ScaleUI Scale a vector with UI 305
scXForm_ScaleXYZUI Scale an element with UI 306
scXForm_MirrorUI Mirror transformation with UI 307
scXForm_TranslateRelUISel Translate element by relative distance with UI and selection 308
scXForm_TranslateAbsUISel Translate element to absolute location with UI and selection 309
scXForm_RotateUISel Rotate element with UI and selection 310
scXForm_ScaleUISel Scale a vector with UI and selection 311
scXForm_ScaleXYZUISel Scale an element with UI and selection 312
scXForm_MirrorUISel Mirror transformation with UI and selection 313
scXForm_ToViewUISel Transform to view with UI and selection 314
27
Chapter 4 Function Summary Tables SURFCAM 2005 • API Documentation
World-to-view
scView_WorldToView Converts a point to view coordinates using a matrix. 251
28
SURFCAM 2005 • API Documentation Chapter 4 Function Summary Tables
Layer Functions
Allocate Memory
scLayer_AllocMem Allocates memory for a layer. 95
Set Layer
scApp_SetCurrentLayer Sets the current layer for SURFCAM. 54
scLayer_SetLayerVisibility Sets the given layer Visible/Invisible 56
Find layers
scLayer_FindFreeLayer Finds the first free (unallocated) layer. 96
scLayer_FindNextAllocLayer Finds the first allocated layer above a specified layer. 97
scLayer_FindNextFreeLayer Finds the first free (unallocated) layer above a specified layer. 98
29
Chapter 4 Function Summary Tables SURFCAM 2005 • API Documentation
View Functions
Allocate memory
scView_AllocMem Allocates memory for a view. 244
Initialize view
scView_InitStandardView Initializes the standard view. 250
Retrieve view
scView_GetCview Retrieves the construction view. 248
scView_GetView Retrieves the current view. 249
Compare views
scView_Compare Compares two views within a specified tolerance. 247
Set a view
scView_ArbitraryAxis Sets the view to an arbitrary axis using a single vector. 245
scView_Arc Returns the view parallel to the normal vector of an arc. 246
scView_WorldToView Converts a point or vector to view coordinates using a matrix. 251
30
SURFCAM 2005 • API Documentation Chapter 4 Function Summary Tables
Vector Functions
Vector database functions
scElement_GetVector Retrieves a vector from the database. 84
31
Chapter 4 Function Summary Tables SURFCAM 2005 • API Documentation
32
SURFCAM 2005 • API Documentation Chapter 4 Function Summary Tables
Point Functions
Allocate memory
scPoint_AllocMem Allocates memory for a point. 201
33
Chapter 4 Function Summary Tables SURFCAM 2005 • API Documentation
Line Functions
Allocate memory
scLine_AllocMem Allocates memory for a line. 103
Polyline Functions
Allocate memory
scPline_AllocMem Allocates memory for a polyline. 198
34
SURFCAM 2005 • API Documentation Chapter 4 Function Summary Tables
Arc Functions
Allocate memory
scArc_AllocMem Allocates memory for an arc. 56
35
Chapter 4 Function Summary Tables SURFCAM 2005 • API Documentation
Conic Functions
Allocate memory
scConic_AllocMem Allocates memory for a conic. 58
36
SURFCAM 2005 • API Documentation Chapter 4 Function Summary Tables
37
Chapter 4 Function Summary Tables SURFCAM 2005 • API Documentation
38
SURFCAM 2005 • API Documentation Chapter 4 Function Summary Tables
39
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
40
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
Chapter 5
Function
Descriptions
41
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
42
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scApp_GetCurrentColor
ARGUMENTS: <None>
43
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scApp_GetCurrentLayer
ARGUMENTS: <None>
44
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scApp_GetIniFileName
ARGUMENTS: <None>
45
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scApp_GetInstanceHandle
ACTION: Returns the handle for the Dynamic Link Library (DLL) associated
with the SURFCAM API.
ARGUMENTS: <None>
46
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scApp_SetElemHandle
RETURN: void
47
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scApp_GetNumOfLayers
48
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scApp_GetTitle
ACTION: Reads in the text of the titlebar of the SURFCAM window and
copies it to caller supplied buffer. The text includes the currently
open file. If the length of the string exceeds maxlength, the string
is truncated.
RETURN: 0 Success
~0 Fail
INPUT and
OUTPUT ARGUMENTS: char * szTitle Pointer to the character buffer
that receives the title string
49
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scApp_GetUnikKnots
RETURN: 0 Success
~0 Fail
INPUT and
OUTPUT ARGUMENTS: double ** unik_knots Returned unique knot vector
Int* unik_num Unique knot vector size
50
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scApp_GetUnitType
INPUT and
OUTPUT ARGUMENTS: None
51
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scApp_GetWindowHandle
ARGUMENTS: <None>
52
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scApp_LayerActive
53
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scApp_LayerAlloc
54
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scApp_LayerVisible
55
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scApp_ProcessDigtFile
RETURN: 0 Success
~0 Fail
56
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scApp_ScanViewTable
RETURN: 0 Success
~0 Fail
57
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scApp_SelectionFinal
RETURN: 0 Success
~0 Fail
ARGUMENTS: <None>
58
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scApp_SelectionInit
ACTION: Provides SURFCAM selector options. The function sets the type
of selection and the selection masks. The element and color
masks are defined in a two-byte register by bit values, with each
bit representing a given color or element to be masked. A value
of TRUE for the iTrimSurf flag selects trimmed surfaces only.
This function must be followed by scApp_SelectionFinal.
SAMPLE CODE:
unsigned nColorMask;
unsigned nElementMask;
59
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scApp_SetCurrentColor
RETURN: <None>
60
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scApp_SetCurrentLayer
ACTION: Sets a specified layer to be the current layer. Note that the
referenced layer must be first allocated before it can be set as
the current layer.
RETURN: <None>
61
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scApp_SetModifiedFlag
RETURN: <None>
62
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scLayer_SetLayerVisibility
RETURN: 0 Success
~0 Fail
63
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scArc_AllocMem
ARGUMENTS: <None>
64
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scArc_WriteToDB
65
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scArc_3Points
ACTION: Defines an arc using three points. The iFullCircle flag controls
whether a full circle is to be defined or an arc with endpoints at
the proper points.
RETURN: 0 Success
~0 Fail
66
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scConic_AllocMem
ARGUMENTS: <None>
67
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scConic_TransformToStandard
RETURN: 0 Success
~0 Fail
68
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scCurve_Eval
RETURN: 0 Success
~0 Fail
SC_Gcrv_param_type *
Parameter Curve parameter (such as
distance along curve in curve
space)
69
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scCurve_EvalCurvature
PROTOTYPE: double
scCurve_EvalCurvature( SC_Element Curve,
UINT iDirection,
SC_Gcrv_param_type * Param )
SC_Gcrv_param_type *
Parameter Curve parameter (such as
distance along curve in curve
space)
70
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scCurve_EvalLengthFinal
RETURN: 0 Success
~0 Fail
71
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scCurve_EvalLengthInit
ACTION: Evaluates the length of a curve. This function maps out the curve
along the u-dimension (in curve space) and returns the total
length of the curve. In addition, the spans between adjacent
knots of the original curve are divided into iNumSpans number of
spans. Note that this function must be followed by
scCurve_EvalLengthFinal in order to free the memory
used to map out the curve.
RETURN: 0 Success
~0 Fail
72
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scCurve_GetSpan
RETURN: 0 Success
~0 Fail
73
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scDB_GetHandle
ARGUMENTS: <None>
SAMPLE CODE:
// This code demonstrates how to manipulate the SURFCAM database
// The following routine will read through the entire database
// and assign any points to layer 30 and any lines to layer 40
HSC_DB hDatabase;
HSC_Element hElementTemp;
SC_Element * pElement;
int iType, iReturn, iLayer;
74
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scDB_GetHeader
ACTION: Gets the header from the current SURFCAM database. The
header information is written into a structure SC_Header. The
header contains information on the version of SURFCAM, the
author, and the title of the file.
RETURN: <None>
75
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scDB_WriteHeader
ACTION: Writes the title and author information to the header to the
database.
RETURN: <None>
76
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scDist_PointPoint
77
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scDist_FpointFpoint
78
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scDist_PointPoint2dVec
79
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scDist_FpointFpoint2d
80
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scElement_DeleteElement
RETURN: <None>
81
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scElement_Final
RETURN: <None>
82
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scElement_GetArc
83
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scElement_GetColorAttrib
84
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scElement_GetColorAttribEx
85
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scElement_GetCount
SAMPLE CODE:
// This code demonstrates how to retrieve information from the SURFCAM database
// The following routine will read through the entire database to count the
// number of elements, comparing that result to the number returned by the
// function scElement_GetCount().
HSC_DB hDatabase;
HSC_Element hElementTemp;
int iCount1, iCount2;
iCount1 = 0;
iCount2 = 0;
iCount1 = scElement_GetCount(hDatabase);
iCount2++;
}
86
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scElement_GetLayer
ACTION: Retrieves a layer from the element handle and defines the layer
as an SC_Layer structure. If the element is a layer, the function
creates a layer (SC_Layer) and returns the pointer to the created
layer. If the element is not a layer, the function returns a NULL
and no layer is created.
87
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scElement_GetLayerAttrib
88
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scElement_GetLine
ACTION: Retrieves a line from the element handle and defines the line as a
SC_Line structure. If the element is a line, the function creates a
line (SC_Line) and returns the pointer to the created line. If the
element is not a line, the function returns a NULL and no line is
created.
89
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scElement_GetLmesh
PROTOTYPE: SC_Lmesh *
scElement_GetLmesh(HSC_Element hElement )
ACTION: Retrieves a line mesh from the element handle and defines the
line mesh as an SC_LMesh structure. If the element is a line
mesh, the function creates a line mesh (SC_LMesh) and returns
the pointer to the created line mesh. If the element is not a line
mesh, the function returns a NULL and no line mesh is created.
90
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scElement_GetNurbCurve
PROTOTYPE: SC_NurbCurve *
scElement_GetNurbCurve(HSC_Element hElement )
ACTION: Retrieves a NURB curve from the element handle and defines it
as a SC_NurbCurve structure. If the element is a NURB curve,
the function creates a NURB curve (SC_NurbCurve) and returns
the pointer to the created NURB curve. If the element is not a
NURB curve, the function returns a NULL and no NURB curve is
created.
91
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scElement_GetNurbSurface
PROTOTYPE: SC_NurbSurface *
scElement_GetNurbSurface(HSC_Element hElement )
ACTION: Retrieves a NURB surface from the element handle and defines it
as a SC_NurbSurface structure. If the element is a NURB
surface, the function creates a NURB surface (SC_NurbSurface)
and returns the pointer to the created NURB surface. If the
element is not a NURB surface, the function returns a NULL and
no NURB surface is created.
92
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scElement_GetPline
93
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scElement_GetPoint
94
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scElement_GetText
ACTION: // To Do By Anil
RETURN: // To Do By Anil
95
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scElement_GetType
ACTION: Returns the type of a given element from the element pointer.
96
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scElement_GetTypeFromHandle
PROTOTYPE: int
scElement_GetTypeFromHandle(HSC_Element handle)
97
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scElement_GetVector
PROTOTYPE: SC_Vector *
scElement_GetVector(HSC_Element hElement )
98
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scElement_GetView
99
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scElement_GetVisibleAttrib
100
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scElement_InitHandle
SAMPLE CODE:
// This code demonstrates how to manipulate the SURFCAM database
// The following routine will read through the entire database
// and assign any points to layer 30 and any lines to layer 40
HSC_DB hDatabase;
HSC_Element hElementTemp;
SC_Element * pElement;
int iType, iReturn, iLayer;
101
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scElement_NextHandle
PROTOTYPE: HSC_Element
scElement_NextHandle(HSC_Element hElement )
ACTION: Returns the next element handle from the database. If the next
element is invalid or there is no next element, the hEl member of
the returned HSC_Element is set to INVALID_HANDLE.
SAMPLE CODE:
// This code demonstrates how to read through the SURFCAM database
HSC_DB hDatabase;
HSC_Element hElementTemp;
int iType;
SC_Point * pPoint;
SC_Lmesh * pLMesh;
SC_Arc * pArc;
switch (iType) {
case SC_POINT:
pPoint = scElement_GetPoint(hElementTemp); // Get the point
break;
case SC_LMESH:
pLMesh = scElement_GetLmesh(hElementTemp); // Get the line mesh
break;
case SC_ARC:
pArc = scElement_GetArc(hElementTemp); // Get the arc
break;
}
}
102
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scElement_SetColorAttribEx
RETURN: 0 Success
~0 Fail
103
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scElement_SetColorAttrib
RETURN: 0 Success
~0 Fail
104
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scElement_SetLayerAttribEx
RETURN: 0 Success
~0 Fail
SAMPLE CODE:
// This code demonstrates how to manipulate the SURFCAM database
// The following routine will read through the entire database
// and assign any points to layer 30 and any lines to layer 40
HSC_DB hDatabase;
HSC_Element hElementTemp;
int iType, iReturn, iLayer;
105
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scElement_SetLayerAttrib
RETURN: 0 Success
~0 Fail
SAMPLE CODE:
// This code demonstrates how to manipulate the SURFCAM database
// The following routine will read through the entire database
// and assign any points to layer 30 and any lines to layer 40
HSC_DB hDatabase;
HSC_Element hElementTemp;
SC_Element * pElement;
int iType, iReturn, iLayer;
106
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scElement_ValidHandle
107
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scElement_WriteToDB
108
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scLayer_AllocMem
ARGUMENTS: <None>
109
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scLayer_FindFreeLayer
ACTION: Checks to see if there is a free layer available. If one exists, the
function returns the lowest layer reference number.
ARGUMENTS: <None>
110
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scLayer_FindNextAllocLayer
ACTION: Checks to see if there is a layer that has been allocated memory
with a reference number higher than iMinimum. If one exists, the
function returns the lowest layer reference number.
111
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scLayer_FindNextFreeLayer
112
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scLayer_GetAttrib
ACTION: Gets the attributes for a specified layer. The value filled for
Attributes [0] indicates whether the layer has been allocated in
SURFCAM. The value filled in Attributes [1] indicates whether
the layer is visible. The value filled in Attributes [2] indicates
whether the layer is active. The values can be TRUE or FALSE.
RETURN: <None>
113
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scLayer_GetFromHandle
114
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scLayer_GetLayerFromHandle
115
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scLayer_GetName
ACTION: Gets the name of a layer when given a layer reference number.
The name is written into a character buffer sBuffer with length
iBufferSize.
RETURN: 0 Success
~0 Fail
OUTPUT ARGUMENTS: char * sBuffer Buffer that stores the layer name
116
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scLayer_WriteToDB
117
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scLine_AllocMem
ARGUMENTS: <None>
118
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scLine_WriteToDB
119
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scList_BackWalk
RETURN: 0 Success
~0 Fail
120
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scList_Concat
ACTION: Concatenates two lists into one. The second list is destroyed
after being concatenated with the first list.
121
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scList_Final
ACTION: Frees up the memory allocated for the list, destroying the list.
RETURN: <None>
122
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scList_GetHead
ACTION: Retrieves the element at the head (top) of the list, also retrieving
the size of the element.
INPUT and
OUTPUT ARGUMENTS: int * iSize Pointer to the integer that will
receive the size of the element,
or NULL if the caller does not
wish to receive the element size.
123
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scList_GetNext
ACTION: Retrieves the next element in the list, also getting the size of the
element.
INPUT and
OUTPUT ARGUMENTS: int * iSize Pointer to the integer that will
receive the size of the element,
or NULL if the caller does not
wish to receive the element size.
124
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scList_GetPrev
ACTION: Retrieves the previous element in the list, also retrieving the size
of the element.
INPUT and
OUTPUT ARGUMENTS: int * iSize Pointer to the integer that will
receive the size of the element,
or NULL if the caller does not
wish to receive the element size.
125
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scList_GetTail
ACTION: Retrieves the element at the tail (bottom) of the list, also retrieving
the size of the element.
INPUT and
OUTPUT ARGUMENTS: int * iSize Pointer to the integer that will
receive the size of the element,
or NULL if the caller does not
wish to receive the element size.
126
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scList_Init
ARGUMENTS: <None>
127
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scList_InsertElement
ACTION: Inserts an element into the list in front of the element Pos.
128
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scList_InsertHead
129
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scList_InsertTail
130
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scList_IsEmpty
131
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scList_MoveElement
132
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scList_MoveHead
133
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scList_MoveTail
134
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scList_NumElements
135
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scList_Reinit
RETURN: void
136
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scList_RemoveAll
RETURN: <None>
137
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scList_RemoveElement
RETURN: 0 Success
~0 Fail
138
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scList_RemoveHead
RETURN: 0 Success
~0 Fail
139
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scList_RemoveTail
RETURN: 0 Success
~0 Fail
140
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scList_Sort
ACTION: Sorts the list according to the specified function. For example, a
pre-defined function HIGH (SC_Point *, SC_Point *) could be
used to sort a point list from highest point to lowest point. The
sorting function must return an integer.
RETURN: 0 Success
~0 Fail
141
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scList_Walk
ACTION: Walks forward through the specified list, passing each list
element to the function pFunction.
RETURN: 0 Success
~0 Fail
142
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scLmesh_AllocMem
ACTION: Allocate memory for a line mesh of iRows rows and iColumns
columns, defining the address in the computer’s memory. Use
scElement_Final to free the allocated memory, and
scMem_Free to free the array of points associated with the line
mesh.
143
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scLmesh_GetPoints
ACTION: Returns the mesh points for a given surface element. Note that
this function allocates memory for the array of mesh points
created and returned during its operation. Use
scElement_Final to free the allocated memory.
RETURN: 0 Success
~0 Fail
144
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scLmesh_WriteToDB
145
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scMat_GetRotation
ACTION: Construct a rotation matrix given the angle from a specified vector
in world coordinates.
RETURN: 0 Success
~0 Fail
146
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scMat_Identity
RETURN: <None>
147
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scMat_Inverse
RETURN: <None>
148
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scMat_InverseTransform
RETURN: <None>
149
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scMat_InverseTranform2d
RETURN: <None>
150
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scMat_Multiply
RETURN: 0 Success
~0 Fail
151
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scMat_OrthoInverse
RETURN: <None>
152
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scMat_SetColumn
RETURN: <None>
153
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scMat_Transform
RETURN: <None>
154
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scMat_Transform2d
RETURN: <None>
155
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scMat_Transpose
RETURN: <None>
156
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scMem_Alloc
157
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scMem_CheckAlloc
158
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scMem_CheckAllocList
ARGUMENTS: <None>
159
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scMem_CountAllocList
ARGUMENTS: <None>
160
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scMem_Free
RETURN: <None>
161
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scMem_FreeAll
ACTION: Free all the memory allocated by the current DLL using
SURFCAM memory allocation functions (e.g.
scMem_AllocMem, scPoint_AllocMem,
scNcurve_AllocMem).
RETURN: <None>
ARGUMENTS: <None>
162
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scMem_Realloc
ACTION: Reallocates memory block size (the new memory block may be at
a different address from the original memory block).
163
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNcurve_AllocMem
164
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNcurve_ArcToNurb
RETURN: 0 Success
~0 Fail
165
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNcurve_Break
ACTION: Retrieves a NURB curve from the original NURB curve given start
and end parameters and a specified tolerance. The NURB curve
is redefined by this function. Note: If the start or end parameter
falls within the tolerance distance of any of the original curve’s
knots, the resulting endpoint will be defined at that knot.
RETURN: 0 Success
~0 Fail
166
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNcurve_ChainNurbs
ACTION: Converts a list of NURB curves into one curve. The resulting
curve may be reversed from the direction of the original curve list.
Note that this function allocates memory for a NURB curve.
RETURN: 0 Success
~0 Fail
167
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNcurve_Clamp
ACTION: Clamps the NURB curve. The NURB curve is clamped at each
interior knot, resulting in an equivalent NURB curve that is a
series of Bezier spans.
RETURN: 0 Success
~0 Fail
168
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNcurve_ClipParam1
RETURN: 0 Success
~0 Fail
169
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNcurve_ClipParam2
ACTION: Clips the specified parameter P2 to lie in the span where P1 lies.
The parameters P1 and P2 are given in terms of curve space
and correspond to distances along the given curve. In addition,
the function outputs two parameters RP1 and RP2 which are
clamped to either side of the nearest curve knot.
RETURN: 0 Success
~0 Fail
170
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNcurve_ConicToNurb
ACTION: Converts a conic entity into a NURB curve. The conic can be a
standard conic or a non-standard conic. This function allocates
memory for the resulting NURB curve. Use scElement_Final
to free the allocated block of memory.
RETURN: 0 Success
~0 Fail
171
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNcurve_ConvertToArcLine
RETURN: 0 Success
~0 Fail
172
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNcurve_ElementToNurb
RETURN: 0 Success
~0 Fail
173
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNcurve_EllipseToNurb
RETURN: 0 Success
~0 Fail
174
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNcurve_EllipseXYToNurb
RETURN: 0 Success
~0 Fail
175
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNcurve_FitNurb
PROTOTYPE: int
scNcurve_FitNurb(SC_NurbCurve ** NCurve,
double dblTolerance )
RETURN: 0 Success
~0 Fail
176
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNcurve_FromPointArray
PROTOTYPE: SC_NurbCurve *
scNcurve_FromPointArray( SC_Point * PointArray,
int iPoints)
ACTION: Builds a cubic NURB curve that interpolates the given set of
points. This function allocates memory for the resulting NURB
curve. Use scElement_Final to free the allocated block of
memory.
177
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNcurve_FromPointList
PROTOTYPE: SC_NurbCurve *
scNcurve_FromPointList(ll_handle * PointList )
178
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNcurve_GetPolyDisplayAttrib
PROTOTYPE: int
scNcurve_GetPolyDisplayAttrib(SC_NurbCurve * curve)
179
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNcurve_GetRationalAttrib
180
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNcurve_InterpPtsTans
ACTION: Creates a NURB curve from a list of points and the tangent
vectors of the curve along those points. This function allocates
memory for the resulting NURB curve. Use scElement_Final
to free the allocated block of memory.
RETURN: 0 Success
~0 Fail
181
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNcurve_JoinTwoNurbs
ACTION: Joins two NURB curves into a single NURB curve. The function
also is able to reverse the direction of the second NURB curve
when defining the point array of the joined NURB curve. This
function allocates memory for the resulting NURB curve. Use
scElement_Final to free the allocated block of memory.
RETURN: 0 Success
~0 Fail
182
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNcurve_ProjectLoop2Nsurf
RETURN: 0 Success
~0 Fail
183
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNcurve_ProjectToNsurf
RETURN: 0 Success
~0 Fail
184
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNcurve_ProjectUVToNsurf
RETURN: 0 Success
~0 Fail
185
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNcurve_RaiseOrder
RETURN: 0 Success
~0 Fail
186
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNcurve_RemoveKnots
RETURN: 0 Success
~0 Fail
INPUT
ARGUMENTS: SC_NurbCurve ** NCurve NURB curve
int iNum Number of duplicate knots to
retain
187
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNcurve_Reverse
RETURN: 0 Success
~0 Fail
188
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNcurve_SetPolyDisplayAttrib
PROTOTYPE: void
scNcurve_SetPolyDisplayAttrib(SC_NurbCurve * curve,
int iDisplay )
RETURN: <None>
189
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNcurve_SetRationalAttrib
PROTOTYPE: void
scNcurve_SetRationalAttrib(SC_NurbCurve * NCurve,
int iRational )
RETURN: <None>
190
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNcurve_WriteToDB
PROTOTYPE: HSC_Element
scNcurve_WriteToDB(HSC_DB hDB,
SC_NurbCurve * NCurve)
191
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_AllocMem
192
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_ConvertToPolygon
RETURN: 0 Success
~0 Fail
193
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_Eval
RETURN: 0 Success
~0 Fail
194
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_EvalCurvature
PROTOTYPE: double
scNsurf_EvalCurvature( SC_Element Surface,
UINT iDirection,
SC_Gpv_param_type * Param )
195
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_FitNurb
PROTOTYPE: int
scNsurf_FitNurb(SC_NurbSurface ** NSurface,
double dblTolerance )
RETURN: 0 Success
~0 Fail
196
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_FixDegeneration
PROTOTYPE: int
scNsurf_FixDegeneration(SC_NurbSurface *apNsurf,
double adDegCheckTol,
double adTrimBackSize )
RETURN: 0 Success
~0 Fail
197
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_GetArrowDisplayAttrib
PROTOTYPE: int
scNsurf_GetArrowDisplayAttrib(SC_NurbSurface *surf )
ACTION: Checks to see if the arrow for a selected NURB surface has been
set to display the associated surface arrow.
198
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_GetArrowPositionAttrib
PROTOTYPE: int
scNsurf_GetArrowPositionAttrib(SC_NurbSurface * Surf )
ACTION: Returns the corner at which the surface arrow for a selected
NURB surface has been set to display.
199
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_GetCutDirectionAttrib
PROTOTYPE: int
scNsurf_GetCutDirectionAttrib(SC_NurbSurface * Surf )
ACTION: Returns the direction of a cut (the major direction) for a selected
NURB surface.
200
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_GetIsoNurb
RETURN: The number of isometric display curves that define the NURB
surface
201
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_GetNormalDirectionAttrib
PROTOTYPE: int
scNsurf_GetNormalDirectionAttrib(SC_NurbSurface * Surf )
ACTION: Gets the surface normal vector attribute from a NURB surface
structure. The returned value indicates whether the NURB
surface normal is natural (u x v ) or reversed (v x u ).
202
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_GetNumberOfULinesAttrib
PROTOTYPE: int
scNsurf_GetNumberOfULinesAttrib(SC_NurbSurface * Surf )
203
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_GetNumberOfVLinesAttrib
PROTOTYPE: int
scNsurf_GetNumberOfVLinesAttrib(SC_NurbSurface * Surf )
204
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_GetPolyDisplayAttrib
PROTOTYPE: int
scNsurf_GetPolyDisplayAttrib(SC_NurbSurface * Surf )
205
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_GetSpan
RETURN: 0 Success
~0 Fail
206
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_GetRange
RETURN: 0 Success
~0 Fail
207
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
208
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_GetRationalAttrib
PROTOTYPE: int
scNsurf_GetRationalAttrib(SC_NurbSurface * NSurface)
209
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_IsDegeneratedClosed
PROTOTYPE: int
scNsurf_IsDegeneratedClosed(
SC_NurbSurface * Nsurface,
double *tolerance,
int *degenerated,
int *closed)
210
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_NurbGrid
RETURN: 0 Success
~0 Fail
211
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_NurbListAutoSort
RETURN: 0 Success
~0 Fail
212
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_Offset
RETURN: 0 Success
~0 Fail
213
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_ProjectPoint
RETURN: 0 Success
~0 Fail
214
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_ProjectPointParam
RETURN: 0 Success
~0 Fail
215
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_ProjectPointSide
RETURN: 0 Success
~0 Fail
216
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_RemoveKnots
RETURN: 0 Success
~0 Fail
217
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_Revolution
RETURN: 0 Success
~0 Fail
218
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_Ruled
RETURN: 0 Success
~0 Fail
219
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_Clamp
PROTOTYPE: int
scNsurf_Clamp(SC_NurbSurface ** NSurface, int dir)
RETURN: 0 Success
~0 Fail
220
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_SetArrowDisplayAttrib
PROTOTYPE: void
scNsurf_SetArrowDisplayAttrib(SC_NurbSurface * NSurface,
int iDisplay)
ACTION: Sets the arrow display attribute for a specified NURB surface to
be visible or invisible. To set the arrow to be visible, set iDisplay
to true; to hide the surface arrow, set iDisplay to false.
RETURN: <None>
221
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_SetArrowPositionAttrib
PROTOTYPE: void
scNsurf_SetArrowPositionAttrib(SC_NurbSurface * NSurf,
int iArrowPosition)
ACTION: Sets the corner at which the surface arrow for a selected NURB
surface will be set to display.
RETURN: <None>
222
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_SetCutDirectionAttrib
PROTOTYPE: void
scNsurf_SetCutDirectionAttrib(SC_NurbSurface * NSurface,
int iCutDir )
ACTION: Sets the direction of a cut (the major direction) for a selected
NURB surface.
RETURN: <None>
223
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_SetNormalDirectionAttrib
PROTOTYPE: int
scNsurf_SetNormalDirectionAttrib(SC_NurbSurface * NSurf,
int iDirection)
ACTION: Sets the surface normal vector attribute from a NURB surface
structure. The normal vector of the NURB surface normal can be
set to be natural (u x v ) or reversed (v x u ).
RETURN: 0 Success
~0 Fail
224
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_SetNumberOfULinesAttrib
PROTOTYPE: void
scNsurf_SetNumberOfULinesAttrib(SC_NurbSurface * Surf,
int iNumULines)
RETURN: <None>
225
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_SetNumberOfVLinesAttrib
PROTOTYPE: void
scNsurf_SetNumberOfVLinesAttrib(SC_NurbSurface * Surf,
int iNumVLines)
RETURN: <None>
226
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_SetPolyDisplayAttrib
PROTOTYPE: void
scNsurf_SetPolyDisplayAttrib(SC_NurbSurface * NSurf,
int iDisplay )
ACTION: Sets the control point mesh to be visible or hidden for a specified
NURB surface. By setting display to false, the mesh is hidden.
Setting display to true sets the mesh to be visible.
RETURN: <None>
227
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_SetRange
RETURN: 0 Success
~0 Fail
SC_Gs_param_range_type * range
Range of surface
element (u-v )
228
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scNsurf_SetRationalAttrib
PROTOTYPE: void
scNsurf_GetRationalAttrib(SC_NurbSurface * NSurface,
int iRational)
RETURN: <None>
229
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNsurf_WriteToDB
230
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scPlane_VectorPoint
ACTION: Constructs a plane from a vector and a point. Note that planes
cannot be written to the database.
RETURN: <None>
231
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scPline_AllocMem
232
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scPline_ElementToPline
RETURN: 0 Success
~0 Fail
233
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scPline_WriteToDB
234
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scPoint_AllocMem
ARGUMENTS: <None>
235
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scPoint_ArcEnd
RETURN: <None>
236
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scPoint_GetMinMax
RETURN: 0 Success
~0 Fail
237
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scPoint_OppositeSideOfLine
RETURN: FALSE The two points do not lie on opposite sides of the
specified line.
TRUE The two points do lie on opposite sides of the
specified line.
238
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scPoint_OppositeSideOfVector
RETURN: FALSE The two points do not lie on opposite sides of the
specified vector.
TRUE The two points do lie on opposite sides of the
specified vector.
239
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scPoint_PointVecParam
RETURN: <None>
240
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scPoint_ProjectToLine
ACTION: Projects a point onto a line. The resulting point would be the
normal projection (with respect to the line) of the original point.
RETURN: <None>
241
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scPoint_ProjectToPlane
RETURN: <None>
242
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scPoint_WriteToDB
RETURN: Element handle associated with the point written to the database
243
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scSafe_acos
244
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scSafe_atof
245
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scSafe_atoi
246
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scSafe_sprintf
RETURN: 0 Success
~0 Fail
247
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scSafe_sqrt
248
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scSafe_strcat
249
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scSafe_strcpy
250
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scStack_Final
RETURN: <None>
251
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scStack_Init
ARGUMENTS: <None>
252
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scStack_Peek
ACTION: Check the active element of the stack, also getting the size of the
element.
RETURN: 0 Success
~0 Fail
INPUT and
OUTPUT ARGUMENTS: int * iSize Pointer to the integer that will
receive the size of the element,
or NULL if the caller does not
wish to receive the element size.
253
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scStack_Pop
ACTION: Pop out the element at the top of the stack, also getting the size
of the element
RETURN: 0 Success
~0 Fail
INPUT and
OUTPUT ARGUMENTS: int * iSize Pointer to the integer that will
receive the size of the element,
or NULL if the caller does not
wish to receive the element size.
254
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scStack_Push
ACTION: Push an element to the top of the stack, also getting the size of
the element.
INPUT and
OUTPUT ARGUMENTS: int * iSize Pointer to the integer that will
receive the size of the element,
or NULL if the caller does not
wish to receive the element size.
255
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scVec_Add
RETURN: 0 Success
~0 Fail
256
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scFvec_Add
RETURN: 0 Success
~0 Fail
257
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scVec_Add2d
ACTION: Adds two vectors (with respect to the x and y axes only). The z
values are ignored.
RETURN: <None>
258
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scVec_AddScaledVecs
ACTION: The vector sum of two scaled vectors. The vectors are scaled
before they are added together.
RETURN: 0 Success
~0 Fail
259
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scVec_AngleMinusPiPi
260
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scVec_AngleZero2Pi
261
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scVec_AngleZeroPi
ACTION: Returns the angle between Vector1 and Vector2. The angle is
constrained to fall between 0 and π radians(180 degrees).
262
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scVec_AngleZeroPi2
ACTION: Returns the angle between two specified vectors. The returned
angle is constrained to fall between 0 and π/2 radians (90
degrees).
263
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scVec_BetweenVecVec
RETURN: FALSE Test vector does not lie between the two
specified vectors
TRUE Test vector does lie between the two specified
vectors
264
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scVec_BetweenVecVec2d
265
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scVec_Collinear
266
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scVec_CrossProduct
RETURN: 0 Success
~0 Fail
267
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scVec_DotProduct
268
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scVec_Magnitude
269
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scFvec_Magnitude
270
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scVec_Magnitude2d
271
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scVec_MagnitudeCrossProduct
PROTOTYPE: double
scVec_MagnitudeCrossProduct(SC_DirVector * Vector1,
SC_DirVector * Vector2)
272
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scVec_Normalize
RETURN: 0 Success
~0 Fail
273
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scFvec_Normalize
RETURN: 0 Success
~0 Fail
274
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scVec_Normalize2d
RETURN: 0 Success
~0 Fail
275
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scVec_PointPoint
RETURN: 0 Success
~0 Fail
276
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scFvec_FpointFpoint
RETURN: 0 Success
~0 Fail
277
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scVec_PointPoint2d
ACTION: Creates a vector from two other vectors with respect to the x and
y axes only.
RETURN: <None>
278
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scVec_ProjectToPlaneN
RETURN: 0 Success
~0 Fail
279
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scVec_ProjectToPlaneNThroughVec
PROTOTYPE: int
scVec_ProjectToPlaneNThroughVec(SC_DirVector * Vector,
SC_DirVector * Norm,
SC_DirVector * Proj )
RETURN: 0 Success
~0 Fail
280
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scVec_Scale
RETURN: 0 Success
~0 Fail
281
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scFvec_Scale
RETURN: 0 Success
~0 Fail
282
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scVec_Scale2d
ACTION: Scales a vector with respect to the x and y axes only according to
a double-precision number. The returned vector parameters
replace the original vector parameters.
RETURN: <None>
283
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scVec_Set_axis_vec
RETURN: none
284
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scVec_SinAngle
ACTION: Returns the sine of the angle between two direction vectors.
285
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scView_AllocMem
ACTION: Allocate memory for a view, defining the pointer to the address in
the computer’s memory.
ARGUMENTS: <None>
286
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scView_ArbitraryAxis
ACTION: Sets an arbitrary view given a single vector. This view sets the
vector defined by Normal as the normal vector for the view.
RETURN: <None>
287
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scView_Arc
ACTION: Returns the view with the same normal as that of a specified arc.
RETURN: 0 Success
~0 Fail
288
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scView_Compare
ACTION: Compares two specified views to one another. If the return value
is false, the two views are the same. If the return value is true,
the two views are different.
289
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scView_GetCview
RETURN: 0 Success
~0 Fail
290
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scView_GetView
RETURN: 0 Success
~0 Fail
291
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scView_InitStandardView
RETURN: 0 Success
~0 Fail
292
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scView_WorldToView
RETURN: <None>
293
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scView_WriteToDB
294
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scXForm_Element
RETURN: 0 Success
~0 Fail
OUTPUT ARGUMENTS:
295
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scXForm_TranslateRel
RETURN: 0 Success
~0 Fail
OUTPUT ARGUMENTS:
296
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scXForm_TranslateAbs
RETURN: 0 Success
~0 Fail
OUTPUT ARGUMENTS:
297
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scXForm_Rotate
RETURN: 0 Success
~0 Fail
OUTPUT ARGUMENTS:
298
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scXForm_Scale
RETURN: 0 Success
~0 Fail
OUTPUT ARGUMENTS:
299
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scXForm_ScaleXYZ
RETURN: 0 Success
~0 Fail
OUTPUT ARGUMENTS:
300
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scXForm_Mirror
RETURN: 0 Success
~0 Fail
OUTPUT ARGUMENTS:
301
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scXForm_TranslateRelUI
RETURN: 0 Success
~0 Fail
OUTPUT ARGUMENTS:
302
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scXForm_TranslateAbsUI
RETURN: 0 Success
~0 Fail
OUTPUT ARGUMENTS:
303
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scXForm_RotateUI
RETURN: 0 Success
~0 Fail
OUTPUT ARGUMENTS:
304
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scXForm_ScaleUI
RETURN: 0 Success
~0 Fail
OUTPUT ARGUMENTS:
305
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scXForm_ScaleXYZUI
RETURN: 0 Success
~0 Fail
OUTPUT ARGUMENTS:
306
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scXForm_MirrorUI
RETURN: 0 Success
~0 Fail
OUTPUT ARGUMENTS:
307
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scXForm_TranslateRelUISel
RETURN: void
308
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scXForm_TranslateAbsUISel
RETURN: void
309
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scXForm_RotateUISel
RETURN: void
310
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scXForm_ScaleUISel
RETURN: void
311
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scXForm_ScaleXYZUISel
RETURN: void
312
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scXForm_MirrorUISel
RETURN: void
313
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scXForm_ToViewUISel
RETURN: void
314
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
315
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
Chapter 6
Sample Code Using
the SURFCAM API
316
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
317
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
SC_Point scp;
SC_Point * pSCPoint;
...
hWndParent = scApp_GetWindowHandle();
switch(nTypeRead)
{
case POINT: /* POINT is defined as the ElementMap index for a point element */
{
/* Read element data into SC_Point format here */
...
break;
}
case LINE:
{
/* Read element data into SC_Line format here */
...
break;
}
case CURVE:
{
/* Read element data into SC_Ncurve format here */
...
break;
}
...
}
...
318
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
#include “expfunc.h”
#include “dllstruct.h”
...
hWndParent = scApp_GetWindowHandle();
319
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
The following sample code was written as part of a demonstration application showcasing the versatility of the
SURFCAM API. This program automatically creates extrusion mold surfaces given front, center, and rear profiles
of the extrusion surface. These profiles are selected by the user through a “Graphical User Interface” (GUI)
incorporating the Microsoft Foundation Classes (MFC) library of GUI objects. Note that the relevant information is
gathered in the GUI and processed by the SURFCAM API functions.
// Channel.cpp : Defines the initialization routines for the DLL.
//
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Define data structures
///////////////////////////////////////////////////////////////////////////////
// Local function declarations
320
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
/////////////////////////////////////////////////////////////////////////////
// Begin MFC-specific code
/////////////////////////////////////////////////////////////////////////////
// CChannelApp
BEGIN_MESSAGE_MAP(CChannelApp, CWinApp)
//{{AFX_MSG_MAP(CChannelApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChannelApp construction
CChannelApp::CChannelApp()
{
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CChannelApp object
CChannelApp theApp;
///////////////////////////////////////////////////////////////////////////////
// SurfcamDllEntryPoint
// This is the standard function called by SURFCAM when using a dll. Note
// that the function must have this standard declaration, even if the character
// strings are not utilized by the dll. The minimum purpose of this function
// is to get the pointer to the SURFCAM functions and assign it to the global
// variable ut_p_pSCFuncs.
//
__declspec(dllexport) int
SurfcamDllEntryPoint(
char *ini_file_name,
char *section_name,
char *file_name)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState()); // MFC-specifc
return(TRUE);
}
#if defined(__cplusplus)
}
#endif
///////////////////////////////////////////////////////////////////////////////
// DoChannel
// This is the main function for this program, allocating the data structure
// and calling the functions to manipulate that data structure.
321
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
//
static void
DoChannel()
{
UINT wCurrentLayer;
SC_Layer * pLayer; // SURFCAM specific
HWND hWndParent;
// This is the main data object, which is passed from function to function.
ChannelData m_Data;
// Initialize the main data object using a function setting all variables.
// Not only is this good programming practice, but this also prevents
// many errors during execution.
InitializeData(m_Data);
// Make SURFCAM the parent window when creating this dialog box
CDialogChannel Dlg(CWnd::FromHandle(hWndParent)); // MFC specific
if (Dlg.DoModal() == IDCANCEL) {
return;
}
m_Data.m_Profile[0].m_iColor = Dlg.m_iColor[0];
m_Data.m_Profile[1].m_iColor = Dlg.m_iColor[1];
m_Data.m_Profile[2].m_iColor = Dlg.m_iColor[2];
m_Data.m_iCenter = Dlg.m_iCenter;
// Make SURFCAM the parent window when creating this dialog box
CDialogSurface SurfaceDlg(CWnd::FromHandle(hWndParent));
if (SurfaceDlg.DoModal() == IDCANCEL) {
return;
}
// Read the data files. If there's an error, abort the program by returning.
if (ReadData(m_Data) == FAIL) {
return;
}
pLayer = scLayer_AllocMem();
iLayer = scLayer_FindFreeLayer();
scElement_SetLayerAttrib(pLayer, iLayer);
GetCenterPoints(m_Data);
322
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
DefineProfiles(m_Data);
DefineBoundaries(m_Data);
CreateSurfaces(m_Data);
// Free up all the allocated memory reserved for the elements. (No longer needed).
scMem_FreeAll();
if (m_Data.m_bAllocate) {
// Go back to original layer
scApp_SetCurrentLayer(wCurrentLayer);
}
}
///////////////////////////////////////////////////////////////////////////////
// InitializeData
// This function initializes the main data structure to ensure valid values.
// This also allocates memory for each list and retrieves the database handle.
//
static void
InitializeData(ChannelData &Data)
{
int i,j;
Data.m_Profile[i].m_hProfilePoints = scList_Init();
Data.m_Profile[i].m_iPoints = 0;
Data.m_Profile[i].m_iColor = 0;
Data.m_Profile[i].m_dblMaxY = -DBL_MAX;
Data.m_Profile[i].m_dblMinY = DBL_MAX;
Data.m_NSurf[i] = NULL;
Data.m_dblDistance = 0.0;
Data.m_iSurfaceColor = 0;
Data.m_bAlign = FALSE;
Data.m_bAllocate = FALSE;
Data.m_hDatabase = scDB_GetHandle();
}
///////////////////////////////////////////////////////////////////////////////
// ReadData
// This function reads in the points from the selected end profile files.
// The points are stored in the data structure as two lists of points.
//
static int
ReadData(ChannelData &Data)
{
int i;
CStdioFile Section[2]; // MFC specific
CString szBuffer; // MFC specific
CString szTemp; // MFC specific
SC_Point TempPoint = {0,0,0}; // SURFCAM specific
// Open file
Section[i].Open(Data.m_szFilename[i], CFile::modeRead | CFile::shareDenyWrite);
323
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
///////////////////////////////////////////////////////////////////////////////
// GetCenterPoints
// This function defines the user-selected center section from pre-defined
// arrays.
//
static void
GetCenterPoints(ChannelData &Data)
{
int iArraySize = 0;
int i = 0;
SC_Point TempPoint = {0,0,0};
else if (Data.m_iCenter == 2)
iArraySize = sizeof(PointList2)/sizeof(PointList2[0]);
else if (Data.m_iCenter == 3)
iArraySize = sizeof(PointList3)/sizeof(PointList3[0]);
// Since each point uses two elements, divide the total by two
for(i = 0; i < (iArraySize / 2); i++) {
TempPoint.x = Data.m_dblDistance;
if (Data.m_iCenter == 1) {
TempPoint.y = PointList1[i*2];
TempPoint.z = PointList1[i*2+1];
}
else if (Data.m_iCenter == 2) {
TempPoint.y = PointList2[i*2];
TempPoint.z = PointList2[i*2+1];
}
else if (Data.m_iCenter == 3) {
TempPoint.y = PointList3[i*2];
TempPoint.z = PointList3[i*2+1];
}
324
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
Data.m_Profile[1].m_iPoints = iArraySize / 2;
///////////////////////////////////////////////////////////////////////////////
// DefineProfiles
// This function converts the points in the point lists and creates the
// profiles. The profiles are converted to Nurb curves in order to create
// the Nurb surfaces later on.
//
static void
DefineProfiles(ChannelData &Data)
{
int i, j, k = 0;
double dblOffset = 0.0;
UINT wCurrentColor = 0;
SC_Point *pPoint = NULL; // SURFCAM specific
// Use scApp_GetCurrentColor to retrieve and save the index of the current color.
wCurrentColor = scApp_GetCurrentColor();
// Loop through each profile (there are two end profiles plus a center profile).
for (i = 0; i < 3; i++) {
// Assign the pPoint element pointer to the tail of the list, which happens
// to be the dummy variable which was the first to be entered into the list.
pPoint = (SC_Point *)(scList_GetTail(Data.m_Profile[i].m_hProfilePoints, NULL));
// Add points to array from list to define boundary curve control points
Data.m_Boundary[j][0].m_Points[i] = *(SC_Point *)(scList_GetPrev(pPoint, NULL));
Data.m_Boundary[j][0].m_Points[i].y = Data.m_Boundary[j][0].m_Points[i].y - dblOffset;
325
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
scNcurve_ElementToNurb(Data.m_Profile[i].m_PLine[j],
&Data.m_Profile[i].m_NCurve[j], 3);
///////////////////////////////////////////////////////////////////////////////
// DefineBoundaries
// This function converts the points in the point lists and creates the
// boundaries. The boundaries are created directly from the point lists.
//
static void
DefineBoundaries(ChannelData &Data)
{
int i,j = 0;
UINT wCurrentColor = 0;
wCurrentColor = scApp_GetCurrentColor();
scApp_SetCurrentColor(Data.m_iSurfaceColor);
326
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
///////////////////////////////////////////////////////////////////////////////
// CreateSurfaces
// This function creates the surfaces from the profiles and boundaries.
//
static void
CreateSurfaces(ChannelData &Data)
{
int i, j = 0;
UINT wCurrentColor = 0;
SC_NurbCurve * NCurveListU[2];
SC_NurbCurve * NCurveListV[3];
wCurrentColor = scApp_GetCurrentColor();
scApp_SetCurrentColor(Data.m_iSurfaceColor);
// Write the resulting surface to the database for storage and display.
scNsurf_WriteToDB(Data.m_hDatabase, Data.m_NSurf[i]);
}
scApp_SetCurrentColor(wCurrentColor);
}
///////////////////////////////////////////////////////////////////////////////
// FindYMinMax
// This function determines the maximum and minimum values of Y for each
// profile in order to align them correctly.
//
static void
FindYMinMax(ChannelData &Data, double dblY, int i)
{
Data.m_Profile[i].m_dblMaxY = max(Data.m_Profile[i].m_dblMaxY, dblY);
Data.m_Profile[i].m_dblMinY = min(Data.m_Profile[i].m_dblMinY, dblY);
}
327
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <os.h>
#include <types.h>
#include <const.h>
#include "mainwin.h"
#include <expfunc.h> /* SURFCAM header file */
#include "ReadElements.h"
#include "..\h\list_io.h"
#include "resource.h"
#include "version.h" /* SURFCAM header file */
/*------------------------------------------------------------------------------
/* Function: Cadl2DsnMain
/*
/* Action: Main function for CADL to DSN translator
/*
/* Type: void
/*
/* Input: char *ini_file_name Init file name
/* char *section_name Name of the section
/* char *FileName Name of the CADL file
/*
/* Output: int rc Return code
/*
/* Returns: <None>
/*
/* Called by: SURFCAM main program
/*
/* Calls: AFX_MANAGE_STATE
/* scApp_GetWindowHandle
/* lb_printf
/* read_cadl
/* result.Loadstring
/* FinalListBox
/* put_end_message
/* WaitForEnd
/*
/*--------------------------------------------------------------------------*/
extern "C" void
328
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
HWND hWndParent;
AFX_MANAGE_STATE(AfxGetStaticModuleState());
InitListBox(lb, CWnd::FromHandle(hWndParent));
CString Result;
/*------------------------------------------------------------------------------
/*
/* Function: ReadCadl
/*
/* Action: Reads in the elements from a CADL file and translates
/* the elements into SURFCAM elements
/*
/* Type: static int
/*
/* Input: char *FileName Name of CADL file
/*
/* Output: Database of SURFCAM elements in DSN format
/*
/* Return: 0 Success
/* ~0 Error
/*
/* Called by: Cadl2DsnMain
/*
/* Calls: InitViewTable
/* ReadArc
/* ReadLine
/* ReadPoint
/* ReadSpline
/* ReadView
/* ReadArray
/* ReadPolyline
/* ReadVLine
/* ReadVPoint
/* ReadPolygon
/* ReadVPolygon
/* ReadConic
/* scApp_GetCurrentLayer
/* scDB_GetHandle
/* scElement_Final
/*
/*
/*
329
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
if (pFile == NULL)
return(FAIL);
ViewTable = InitViewTable(MAX_VIEW_NUM);
if (!length[i])
continue;
bAdd = 0;
330
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
switch(i)
{
case ARC:
ReadArc(pBuffer, &hDB, &nSaveLayer, &CurrentView, &LastView, ViewTable,
&bAdd, ARCFLAG);
break;
case CIRCLE:
ReadArc(pBuffer, &hDB, &nSaveLayer, &CurrentView, &LastView, ViewTable,
&bAdd, CIRCLEFLAG);
break;
case LINE:
ReadLine(pBuffer, &hDB, &bAdd, &nSaveLayer);
break;
case POINT:
ReadPoint(pBuffer, &hDB, &bAdd, &nSaveLayer);
break;
case SPLINE:
ReadSpline(pBuffer, &hDB, &bAdd, &nSaveLayer, &ArrayDim1, &ArrayDim2,
&LastView, &CurrentView, ViewTable, &ViewMatrixArray);
break;
case VIEW:
ReadView(pBuffer, &hDB, ViewTable, &LastView);
break;
case ARRAY:
ReadArray(pBuffer, pFile, &ViewMatrixArray, &ArraySize, &ArrayDim1,
&ArrayDim2);
break;
case POLYLINE:
ReadPolyline(pBuffer, &hDB, &bAdd, &nSaveLayer, &ArrayDim1,
&ViewMatrixArray);
break;
case VLINE:
ReadVLine(pBuffer, &hDB, &bAdd, &nSaveLayer, &CurrentView, &LastView,
ViewTable);
break;
case VPOINT:
ReadVPoint(pBuffer, &hDB, &bAdd, &nSaveLayer, &CurrentView, &LastView,
ViewTable);
break;
case POLYGON:
ReadPolygon(pBuffer, &hDB, &bAdd, &nSaveLayer, &ArrayDim1, &CurrentView,
&LastView, ViewTable, &ArraySize, &ViewMatrixArray);
break;
case VPOLYGON:
ReadVPolygon(pBuffer, &hDB, &bAdd, &nSaveLayer, &ArrayDim1, &CurrentView,
&LastView, ViewTable, &ArraySize, &ViewMatrixArray);
break;
case CONIC:
331
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
default:
break;
} /* End switch */
} /* End while */
fclose(pFile);
return SUCCESS;
}
/*------------------------------------------------------------------------------
/* Function: InitViewTable
/*
/* Action: Initializes view table
/*
/* Type: unsigned short *
/*
/* Input: unsigned n Number of views
/*
/* Returns: Pointer to initizlized view table
/*
/* Called by: ReadCadl
/*
/*----------------------------------------------------------------------------*/
static unsigned short *
InitViewTable(unsigned n)
{
int i;
unsigned short *tab;
return(tab);
}
332
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
#ifndef __MAINWIN_H__
#define __MAINWIN_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif
333
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
#include "stdafx.h"
#include <types.h>
#include <const.h>
#include <math.h>
#include <expfunc.h> /* SURFCAM header file */
#include "CadlFunctions.h"
#include "ReadElements.h"
int
ReadArc(char *pBuffer, /* Character pointers */
HSC_DB *hDB, /* SURFCAM database handle */
unsigned int *nSaveLayer, /* Save layer */
SC_View *CurrentView, /* View being used currently */
SC_View *LastView, /* Last view used */
unsigned short *ViewTable, /* View conversion table */
int *bAdd, /* Added element flag */
int bCircle) /* Circle/Arc flag */
{
SC_Point Point; /* Points read in from CADL */
double dblAngle1; /* Arc start angle */
double dblAngle2; /* Arc end angle */
double dblRadius; /* Arc radius */
unsigned short nViewNum; /* View number */
unsigned int nColor; /* Input color from CADL */
unsigned int nLayer; /* Input layer from CADL */
334
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
switch(bCircle)
{
case ARCFLAG:
if (sscanf(pBuffer,"%lf,%lf,%lf,%lf,%lf,%lf,%hu,%u,%u",
&Point.x, &Point.y, &Point.z, &dblRadius, &dblAngle1, &dblAngle2,
&nViewNum, &nColor, &nLayer) < 7)
break;
/* Ensure that the start angle is less than the end angle */
if(dblAngle1 > dblAngle2)
dblAngle1 -= 360.0;
break;
case CIRCLEFLAG:
if(sscanf(pBuffer,"%lf,%lf,%lf,%lf,%hu,%u,%u",
&Point.x, &Point.y, &Point.z, &dblRadius, &nViewNum, &nColor,
&nLayer) < 5)
break;
dblAngle1 = 0.0;
dblAngle2 = _2pi;
break;
}
return SUCCESS;
}
/*------------------------------------------------------------------------------
/* Function: TranslateArc
/*
/* Action: Translates an arc or circle into an SC_Arc
/*
/* Type: void
/*
/* Input and
/* Output: HSC_DB *p_hDB SURFCAM database
/* SC_Arc *p_Arc Arc written to database
/*
/* Input: double *p_dblAngle1 Start angle (0 for circle)
/* double *p_dblAngle2 End angle (2 PI for circle)
/* double *p_dblRadius Radius of arc
/* SC_Point *p_Origin Origin coordinates
/* unsigned int *p_nColor CADL color for arc
/* unsigned int *p_nLayer CADL layer for arc
/* SC_View *p_View Current SURFCAM view
/* SC_View *p_LastView Last SURFCAM view
/* unsigned short *p_nView View number
/* unsigned short *p_nViewTable View table
/* int *p_iAdd Add flag (entity added)
/*
/* Returns: <None>
/*
/* Called by: ReadArc
/*
/*----------------------------------------------------------------------------*/
335
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
static void
TranslateArc(double *p_dblAngle1, double *p_dblAngle2, double *p_dblRadius,
SC_Point *p_Origin, unsigned int *p_nColor, unsigned int *p_nLayer,
SC_View *p_View, SC_View *p_LastView, unsigned short *p_nView,
unsigned short *p_nViewTable, int *p_iAdd, HSC_DB *p_hDB)
{
double x1, y1; /* Arc center position */
SC_Arc *p_Arc;
x1 = cos(*p_dblAngle1);
y1 = sin(*p_dblAngle1);
p_Arc->normal.x = p_View->view_mat[0][2];
p_Arc->normal.y = p_View->view_mat[1][2];
p_Arc->normal.z = p_View->view_mat[2][2];
*p_iAdd = 1;
}
int
ReadArray(char *pBuffer,
FILE *pFile,
double **ViewMatrixArray, /* Pointer to view matrix array */
long int *ArraySize, /* View matrix array size */
int *ArrayDim1,
int *ArrayDim2)
{
int TotalDim; /* Total dimensions */
int i;
double *dblValue;
char *pChar;
char *sBuffer;
*ArrayDim2 = 1;
sscanf(pBuffer, " %*[^[] [ %d ] [ %d", ArrayDim1, ArrayDim2);
TotalDim = (*ArrayDim1) * (*ArrayDim2);
if (*ViewMatrixArray == NULL)
(*ViewMatrixArray) = (double*)scMem_Alloc(sizeof(double)*TotalDim);
336
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
*ArraySize = TotalDim;
if (!*pBuffer)
{
if (!fgets(sBuffer, 139, pFile))
break;
pBuffer = sBuffer;
continue;
};
dblValue = (*ViewMatrixArray)+i;
*dblValue = strtod(pBuffer, &pChar);
pBuffer = pChar;
i++;
};
return SUCCESS;
}
int
ReadConic(char *pBuffer, HSC_DB *hDB, int * bAdd, unsigned int *nSaveLayer,
SC_View *LastView, SC_View *pCurrentView, unsigned short *ViewTable)
{
unsigned int nColor; /* Input color from CADL */
unsigned int nLayer; /* Input layer from CADL */
unsigned short nViewNum; /* View number */
int i, rc;
int nFlags = STD_CONIC;
double Matrix[4][4];
SC_Conic Conic;
SC_Conic NewConic;
SC_Point *Point;
SC_NurbCurve *Ncurve;
sscanf(pBuffer, "%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%d,%d,%d",
&Conic.a, &Conic.b, &Conic.c, &Conic.d, &Conic.e,
&Conic.f, &Conic.x1, &Conic.y1, &Conic.x2, &Conic.y2,
&Conic.zt, &nViewNum, &nColor, nLayer);
/* Transform conic into standard position and get the transformation matrix */
rc = scConic_TransformToStandard(&NewConic, Matrix, &Conic);
337
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
if (rc == SUCCESS)
{
/* Convert standard conic into nurb curve */
rc = scNcurve_ConicToNurb(&NewConic, nFlags, &Ncurve);
};
if (rc == SUCCESS)
*bAdd = 1;
return SUCCESS;
}
int
ReadLine(char *pBuffer, HSC_DB *hDB, int * bAdd, unsigned int *nSaveLayer)
{
SC_Point Endpoint1, Endpoint2;
SC_Line *pLine;
unsigned int nColor; /* Input color from CADL */
unsigned int nLayer; /* Input layer from CADL */
unsigned short nDummyView = 1; /* Dummy view */
if (sscanf(pBuffer,"%lf,%lf,%lf,%lf,%lf,%lf,%u,%u",
&Endpoint1.x, &Endpoint1.y, &Endpoint1.z,
&Endpoint2.x, &Endpoint2.y, &Endpoint2.z,
&nColor, &nLayer) < 6)
return FAIL;
return SUCCESS;
}
int
ReadPoint(char *pBuffer, HSC_DB *hDB, int *bAdd, unsigned int *nSaveLayer)
{
SC_Point Point;
SC_Point *PointPtr; /* Point pointer */
unsigned int nColor; /* Input color from CADL */
338
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
if (sscanf(pBuffer,"%lf,%lf,%lf,%u,%u",
&Point.x, &Point.y, &Point.z, &nColor, &nLayer) < 3)
return FAIL;
*PointPtr = Point;
return SUCCESS;
}
int
ReadPolygon(char *pBuffer, HSC_DB *hDB, int *bAdd, unsigned int *nSaveLayer,
int *ArrayDim1, SC_View *pCurrentView, SC_View * LastView,
unsigned short *ViewTable, long int *ArraySize,
double **ViewMatrixArray)
{
SC_Point Endpoint1, Endpoint2;
SC_Point Point; /* Input point pointer */
unsigned int nColor; /* Input color from CADL */
unsigned int nLayer; /* Input layer from CADL */
int nIndex; /* Index variable */
unsigned short nDummyView = 1; /* Dummy view */
GetCdlVm3dPoint(*ViewMatrixArray, 0, &Endpoint1);
GetCdlVm3dPoint(*ViewMatrixArray, nIndex-1, &Endpoint2);
*bAdd = 1;
scMem_Free(*ViewMatrixArray);
*ViewMatrixArray = NULL;
return SUCCESS;
}
int
ReadPolyline(char *pBuffer, HSC_DB *hDB, int * bAdd, unsigned int *nSaveLayer,
int *ArrayDim1, double **ViewMatrixArray)
{
339
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
if (nIndex*3 != *ArrayDim1)
return FAIL; /* Somthing has gone wrong */
*bAdd = 1;
scMem_Free(*ViewMatrixArray);
*ViewMatrixArray = NULL;
return SUCCESS;
}
int
ReadSpline(char *pBuffer, HSC_DB *hDB, int * bAdd, unsigned int *nSaveLayer,
int *ArrayDim1, int *ArrayDim2, SC_View *LastView,
SC_View *pCurrentView, unsigned short *ViewTable,
double **ViewMatrixArray)
{
unsigned int nColor; /* Input color from CADL */
unsigned int nLayer; /* Input layer from CADL */
unsigned short nViewNum = 1; /* View number */
char SplineType[6]; /* Spline type buffer */
int nIndex;
int nDim; /* Number of dimensions */
double dblDepth;
nDim = 2;
else
340
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
scMem_Free(*ViewMatrixArray);
*ViewMatrixArray = NULL;
return SUCCESS;
}
/*------------------------------------------------------------------------------
/* Function: ReadCadlSpline
/*
/* Action: Reads in a CADL spline and tranforms it into a NURB curve. This
/* is accomplished by converting each parametric cubic span of the
/* CADL spline into a Bezier curve. These Bezier curves are
/* appended together and the extraneous control points and knots
/* are removed. This algorithm allows the converted curves to
/* accurately represent curves with sharp corners (i.e. C1 discon-
/* tinuity).
/*
/* Type: static int
/*
/* Input and
/* Output: HSC_DB *p_hDB SURFCAM database
/*
/* Input: int nNumOfSpans Number of CADL pc spans
/* int nDimensions Dimensions (2D or 3D)
/* double nDepth Depth of spline
/* double *&PointArray Array of control points
/* SC_View *p_View Current SURFCAM view
/*
/* Returns: 0 Success
/* ~0 Fail
/*
/* Called by: ReadSpline
/*
/* Calls: GetCdlVmCoeffs
/* SetLayerColor
/* scElement_Final
/* scNcurve_AllocMem
/* scNcurve_RemoveKnots
/* scNcurve_WriteToDB
/*
/*----------------------------------------------------------------------------*/
static int
ReadCadlSpline(HSC_DB *hDB, int nNumOfSpans, int nDimensions,
double *dblDepth, double *& PointArray, SC_View * p_View,
unsigned int * nColor, unsigned int * nLayer)
{
int i, nIndex, nReps;
int idx = 0;
int idx_knots = 0;
double dblDistance = 0.0;
coeffs TempCoeff;
SC_Point Origin;
SC_NurbCurve *NurbCurve = NULL;
UINT nOrder;
UINT nNumOfPoints;
nOrder = 4;
nNumOfPoints = 3 * nNumOfSpans + 1;
341
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
/* Knots are NOT normalized. Knots are defined at the distances along the curve */
dblDistance += scDist_PointPoint(&Origin, &NurbCurve->p_SC_NPoint[idx].point);
for(i=0;i<nReps;i++) {
NurbCurve->p_knot[idx_knots++] = dblDistance;
}
}
return (1);
}
342
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
/*------------------------------------------------------------------------------
/* Function: GetCadlVmCoeffs
/*
/* Action: Retrieve the matrix coefficients (2D and 3D)
/*
/* Type: void
/*
/* Input: double*& ViewMatrixArray Array of coordinates
/* unsigned int i Number of elements in array
/* int ndim Number of coordinate sets
/* double depth Z coordinate values
/*
/* Output: struct coeffs *pBuffer
/*
/* Returns: <None>
/*
/* Called by: ReadCadlSpline
/*
/*----------------------------------------------------------------------------*/
static void
GetCdlVmCoeffs(double*& ViewMatrixArray,
unsigned int i,
int ndim,
double *depth,
struct coeffs *pBuffer)
{
int j, k;
i *= ndim * 4;
for (j = 0; j < ndim; j++) {
for (k = 0; k < 4; k++) {
pBuffer->c[j][k] = ViewMatrixArray[i];
i++;
}
}
if (ndim == 2) {
pBuffer->c[2][0] = pBuffer->c[2][1] = pBuffer->c[2][2] = 0.0;
pBuffer->c[2][3] = *depth;
}
return;
}
int
ReadView(char *pBuffer, HSC_DB *hDB, unsigned short *ViewTable, SC_View *LastView)
{
SC_View View;
SC_View ViewFound;
unsigned short nFreeView;
if(sscanf(pBuffer,"%u,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&View.view,
&View.view_mat[0][0], &View.view_mat[0][1], &View.view_mat[0][2],
&View.view_mat[1][0], &View.view_mat[1][1], &View.view_mat[1][2],
&View.view_mat[2][0], &View.view_mat[2][1], &View.view_mat[2][2]) != 10)
return FAIL;
if (ViewTable[View.view])
{ /* This View is already used */
343
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
return SUCCESS;
}
/*------------------------------------------------------------------------------
/* Function: FindFreeView
/*
/* Action: Finds first free view reference number
/*
/* Type: unsigned short
/*
/* Input: SC_Point *pin Input point
/* SC_View *v View
/*
/* Output: SC_Point *pout Output point
/*
/* Returns: 1 to MAX_VIEW_NUM Free view number
/* 0 Error code
/*
/* Called by: ReadView
/*
/*----------------------------------------------------------------------------*/
static unsigned short
FindFreeView(unsigned short min, unsigned short *tab)
{
unsigned short i;
int
ReadVLine(char *pBuffer, HSC_DB *hDB, int * bAdd, unsigned int *nSaveLayer,
SC_View *pCurrentView, SC_View * LastView, unsigned short *ViewTable)
{
SC_Point Endpoint1, Endpoint2;
SC_Line * pLine;
unsigned int nColor; /* Input color from CADL */
unsigned int nLayer; /* Input layer from CADL */
unsigned short nView; /* Dummy view from CADL */
344
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
if (sscanf(pBuffer,"%lf,%lf,%lf,%lf,%lf,%lf,%hu,%u,%u",
&Endpoint1.x, &Endpoint1.y, &Endpoint1.z,
&Endpoint2.x, &Endpoint2.y, &Endpoint2.z,
&nView, &nColor, &nLayer) < 7)
return FAIL;
*bAdd = 1;
return SUCCESS;
}
int
ReadVPoint(char *pBuffer, HSC_DB *hDB, int *bAdd, unsigned int *nSaveLayer,
SC_View *pCurrentView, SC_View * LastView, unsigned short *ViewTable)
{
SC_Point Point;
SC_Point * PointPtr; /* Input point pointer */
unsigned int nColor; /* Input color from CADL */
unsigned int nLayer; /* Input layer from CADL */
unsigned short nViewNum; /* View from CADL */
if (sscanf(pBuffer,"%lf,%lf,%lf,%hu,%u,%u",
&Point.x, &Point.y, &Point.z, &nViewNum, &nColor, &nLayer) < 4)
return FAIL;
*bAdd = 1;
return SUCCESS;
}
345
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
int
ReadVPolygon(char *pBuffer, HSC_DB *hDB, int *bAdd, unsigned int *nSaveLayer,
int *ArrayDim1, SC_View *pCurrentView, SC_View * LastView,
unsigned short *ViewTable, long int *ArraySize,
double **ViewMatrixArray)
{
SC_Point Point;
SC_Point Endpoint1, Endpoint2;
unsigned int nColor; /* Input color from CADL */
unsigned int nLayer; /* Input layer from CADL */
unsigned short nView; /* Dummy view from CADL */
int nIndex;
int nPoints;
int i;
double dblDepth;
/* Check if it is closed */
GetCdlVm2dPoint(*ViewMatrixArray, 0, &Endpoint1);
GetCdlVm2dPoint(*ViewMatrixArray, nIndex-1, &Endpoint2);
if (scDist_PointPoint(&Endpoint1, &Endpoint2) < _fchain_tol)
nPoints = nIndex;
else
nPoints = nIndex + 1;
if (nPoints != nIndex) {
GetCdlVm3dPoint(*ViewMatrixArray, 0, &Point);
SetCdlVm3dPoint(*ViewMatrixArray, nPoints - 1, &Point, ArraySize);
}
*bAdd = 1;
scMem_Free(*ViewMatrixArray);
ViewMatrixArray = NULL;
return SUCCESS;
}
346
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
#ifndef __READELEMENTS_H__
#define __READELEMENTS_H__
int ReadConic(char *pBuffer, HSC_DB *hDB, int * bAdd, unsigned int *nSaveLayer,
SC_View *LastView, SC_View *pCurrentView, unsigned short *ViewTable);
int ReadLine(char *pBuffer, HSC_DB *hDB, int * bAdd, unsigned int *nSaveLayer);
int ReadPoint(char *pBuffer, HSC_DB *hDB, int *bAdd, unsigned int *nSaveLayer);
int ReadPolygon(char *pBuffer, HSC_DB *hDB, int *bAdd, unsigned int *nSaveLayer,
int *ArrayDim1, SC_View *pCurrentView, SC_View * LastView,
unsigned short *ViewTable, long int *ArraySize,
double **ViewMatrixArray);
int ReadPolyline(char *pBuffer, HSC_DB *hDB, int * bAdd, unsigned int *nSaveLayer,
int *ArrayDim1, double **ViewMatrixArray);
int ReadSpline(char *pBuffer, HSC_DB *hDB, int * bAdd, unsigned int *nSaveLayer,
int *ArrayDim1, int *ArrayDim2, SC_View *LastView,
SC_View *pCurrentView, unsigned short *ViewTable,
double **ViewMatrixArray);
int ReadView(char *pBuffer, HSC_DB *hDB, unsigned short *ViewTable, SC_View *LastView);
int ReadVLine(char *pBuffer, HSC_DB *hDB, int * bAdd, unsigned int *nSaveLayer,
SC_View *pCurrentView, SC_View * LastView, unsigned short *ViewTable);
int ReadVPoint(char *pBuffer, HSC_DB *hDB, int * bAdd, unsigned int *nSaveLayer,
SC_View *pCurrentView, SC_View * LastView, unsigned short *ViewTable);
int ReadVPolygon(char *pBuffer, HSC_DB *hDB, int *bAdd, unsigned int *nSaveLayer,
int *ArrayDim1, SC_View *pCurrentView, SC_View * LastView,
unsigned short *ViewTable, long int*ArraySize,
double **ViewMatrixArray);
347
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
#define STD_CONIC 1
#define ARCFLAG 0
#define CIRCLEFLAG 1
#define _fchain_tol 2e-4 /* Chaining operation tolerance */
#endif
348
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
#include "stdafx.h"
#include "expfunc.h"
#include <types.h>
#include "CadlFunctions.h"
/*------------------------------------------------------------------------------
/* Function: CheckCadl
/*
/* Action: Checks the validity of the CADL file and sets the layer
/*
/* Type: int
/*
/* Input: HSC_DB *hDb Database handle
/* unsigned int *color Input color from CADL
/* unsigned int *nLayer Input layer from CADL
/* unsigned short *nViewNum View number from CADL
/* unsigned int *CurrentLayer Current layer of SURFCAM
/*
/* Returns: 1 Success
/* 0 Too many views
/*
/*
/* Calls: CdlLayer
/*
/*----------------------------------------------------------------------------*/
int
CheckCadl(
HSC_DB *hDB,
unsigned int *nColor, /* Input color from CADL */
unsigned int *nLayer, /* Input layer from CADL */
unsigned short *nViewNum, /* View number from CADL */
unsigned int *CurrentLayer) /* Current layer of SURFCAM */
{
int Colormap[] = {0, 10, 12, 6, 14, 11, 13, 8, 9, 1, 2, 3, 4, 5, 7, 15};
/* Black, Green, Red, Brown, Yellow, Cyan, Magenta,
Dark Gray, Blue, Light Blue, Light Green,
Light Cyan, Light Red, Light Magenta, Light Gray, White */
if (*nLayer == 0)
*nLayer = *CurrentLayer;
CdlLayer(hDB, nLayer);
349
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
/*------------------------------------------------------------------------------
/* Function: CdlLayer
/*
/* Action: Transforms coordinates using transformation matrix
/*
/* Type: void
/*
/* Input: HSC_DB *hDB Database handle
/* unsigned int *nLayer Input layer from CADL
/*
/* Returns: <None>
/*
/* Called by: CheckCadl
/*
/* Calls: scApp_LayerAlloc
/* AddLayer
/*
/*----------------------------------------------------------------------------*/
static void
CdlLayer(HSC_DB *hDB, unsigned int *nLayer)
{
char sBuffer[30];
*nLayer = nLayerNum;
return;
}
/*------------------------------------------------------------------------------
/* Function: AddLayer
/*
/* Action: Adds a layer to the SURFCAM database
/*
/* Type: void
/*
/* Input: unsigned int nLayer Specified layer
/* char *layer_name Layer name
/*
/* Output: HSC_DB hDB Database handle
/*
/* Returns: <None>
/*
/* Called by: CdlLayer
/*
/* Calls: scLayer_AllocMem
/* scElement_SetLayerAttrib
/* scLayer_WriteToDB
/* scElement_Final
/*
/*----------------------------------------------------------------------------*/
static void
AddLayer(HSC_DB *hDB,
unsigned int nLayer,
char *sLayerName)
{
/* Allocate memory for layer */
SC_Layer * CurrentLayer = scLayer_AllocMem();
350
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
return;
}
/*------------------------------------------------------------------------------
/* Function: GetCadlView
/*
/* Action: Transforms coordinates using transformation matrix
/*
/* Type: int
/*
/* Input: unsigned short *nViewNum View number
/* SC_View *LastView Last view
/* unsigned short *ViewTable Pointer to view table
/*
/* Output: SC_View *pView Pointer to view
/*
/* Returns: 0 Success
/* ~0 Error code
/*
/*----------------------------------------------------------------------------*/
int
GetCadlView(SC_View *pView,
unsigned short *nViewNum,
SC_View *LastView,
unsigned short *ViewTable)
{
int rc = SUCCESS;
SC_View CurrentView;
*pView = *LastView;
return(1);
}
351
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
/*------------------------------------------------------------------------------
/* Function: CdlTransformViewWorld
/*
/* Action: Transforms coordinates using transformation matrix
/*
/* Type: int
/*
/* Input: SC_Point *Input Input point
/* SC_View *View View
/*
/* Output: SC_Point *Output Output point
/*
/* Returns: 0 Success
/* ~0 Error code
/*
/*----------------------------------------------------------------------------*/
int
CdlTransformViewWorld(SC_Point *Output,
SC_Point *Input,
SC_View *View)
{
SC_Point Temp = *Input; /* copy the point */
return SUCCESS;
}
/*------------------------------------------------------------------------------
/* Function: SetLayerColor
/*
/* Action: Sets the SURFCAM layer and the SURFCAM color of an element
/*
/* Type: void
/*
/* Input and
/* Output: SC_Element Element SURFCAM element
/*
/* Input: uint nColor SURFCAM color
/* uint nLayer SURFCAM layer
/*
/* Returns: <None>
/*
/*----------------------------------------------------------------------------*/
void
SetLayerColor(SC_Element Element, unsigned int * nColor, unsigned int * nLayer)
{
/* Sets the SURFCAM color for an element */
scElement_SetColorAttrib(Element, *nColor);
352
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
/*------------------------------------------------------------------------------
/* Function: GetCadlVm3dPoint
/*
/* Action: Retrieves a three-dimensional point from the coordinate array
/*
/* Type: void
/*
/* Input: double *ViewMatrixArray Array of coordinates
/* unsigned int i Number of points
/*
/* Output: SC_Point *Point Output point
/*
/* Returns: <None>
/*
/* Called by: read_cadl
/*
/*----------------------------------------------------------------------------*/
void
GetCdlVm3dPoint(double *ViewMatrixArray,
unsigned int i,
SC_Point *Point)
{
Point->x = ViewMatrixArray[i*3];
Point->y = ViewMatrixArray[i*3+1];
Point->z = ViewMatrixArray[i*3+2];
}
/*------------------------------------------------------------------------------
/* Function: GetCdlVm2dPoint
/*
/* Action: Retrieves a two-dimensional point from the coordinate array
/*
/* Type: void
/*
/* Input: double *ViewMatrixArray Array of coordinates
/* unsigned int i Number of points
/*
/* Output: SC_Point *Point Output point
/*
/* Returns: <None>
/*
/*----------------------------------------------------------------------------*/
void
GetCdlVm2dPoint(double *ViewMatrixArray,
unsigned int i,
SC_Point *Point)
{
Point->x = ViewMatrixArray[i*2];
Point->y = ViewMatrixArray[i*2+1];
Point->z = 0.0;
return;
}
/*------------------------------------------------------------------------------
/* Function: SetCdlVm3dPoint
/*
/* Action: Sets a three-dimensional point in the coordinate array
/*
/* Type: void
/*
/* Input: SC_Point *p Output point
/* unsigned int i Number of points
/*
/* Output: double *ViewMatrixArray Array of coordinates
/*
/* Returns: <None>
/*
/*----------------------------------------------------------------------------*/
353
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
void
SetCdlVm3dPoint(double *ViewMatrixArray,
unsigned int i,
SC_Point *Point,
long int *ArraySize)
{
if (*ArraySize < (int)(3*i+3))
{
*ArraySize = 3*i+3;
ViewMatrixArray = (double*)scMem_Realloc(ViewMatrixArray,
sizeof(double)*(*ArraySize));
};
ViewMatrixArray[i*3] = Point->x;
ViewMatrixArray[i*3+1] = Point->y;
ViewMatrixArray[i*3+2] = Point->z;
return;
}
/*------------------------------------------------------------------------------
/* Function: ReadCadlPolyline
/*
/* Action: Reads in a polyline from the CADL file
/*
/* Type: int
/*
/* Input: unsigned n Number of points
/* double*& ViewMatrixArray Array of coordinates
/* unsigned int * nColor Input color
/* unsigned int * nLayer Input layer
/* HSC_DB hDB Database handle
/*
/* Returns: 0 Success
/* ~0 Error code
/*
/* Calls: scPLine_AllocMem
/* scPLine_WriteToDB
/* scElement_Final
/* scMem_Free
/*
/*----------------------------------------------------------------------------*/
int
ReadCadlPolyline(HSC_DB * hDB,
unsigned n,
double * ViewMatrixArray,
unsigned int * nColor,
unsigned int * nLayer)
{
SC_Point Point;
unsigned i;
(PLine->p_SC_Point)[i] = Point;
};
return SUCCESS;
}
354
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
#ifndef __CADLFUNCTIONS_H__
#define __CADLFUNCTIONS_H__
#endif
355
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
Part II
356
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
357
Chapter 7 Introduction to the Listbox Dialog SURFCAM 2005 • API Documentation
Chapter 7
Introduction to the
SURFCAM Listbox
dialog API
The translators that ship with SURFCAM 2005 use a common listbox dialog to
communicate with the user during the translation process. The ability to utilize
this listbox dialog in custom applications is available through the SURFCAM
listbox dialog API, described in this documentation. Note that this listbox dialog
is derived from Microsoft’s Foundation Class library (MFC) Version 4.2, so any
development environment using the SURFCAM listbox dialog must support this
library.
The second component is the middle listbox, which comprises the primary output
area of the dialog. The contents of the listbox may be continually updated during
the translation process.
The third component of the dialog is the row of buttons at the bottom of the
dialog. These buttons allow the user to save the contents of the listboxes to a file,
print them, or close the window. During the translation process, the translation
may be canceled as well.
358
SURFCAM 2005 • API Documentation Chapter 7 Introduction to the Listbox Dialog
The dialog is a child window, and must therefore have a parent window. The
listbox dialog is associated with a parent window in the initialization process.
The InitListBox function initializes and displays the dialog to the screen.
359
Chapter 7 Introduction to the Listbox Dialog SURFCAM 2005 • API Documentation
There is a second, more specialized function that writes text to the primary output
listbox. The put_end_message function takes a beginning string, an end string,
and a “success” flag. If the “success” flag is true, then put_end_message writes
the beginning string, the string “Successful”, and then the end string to the main
output listbox. If the “success” flag indicates failure, then put_end_message
writes the beginning string, the string “Unsuccessful”, and then the end string to
the main output listbox.
360
SURFCAM 2005 • API Documentation Chapter 8 Listbox Dialog Function Descriptions
Chapter 8
Listbox Dialog API
Function Descriptions
361
Chapter 8 Listbox Dialog Function Descriptions SURFCAM 2005 • API Documentation
FinalListBox
ACTION: Destroys the listbox and frees the memory associated with the
listbox.
RETURN: <None>
362
SURFCAM 2005 • API Documentation Chapter 8 Listbox Dialog Function Descriptions
GetAbortStatus
ACTION: Returns the abort status of the listbox dialog, checking to see if
the user has pressed the Cancel button.
363
Chapter 8 Listbox Dialog Function Descriptions SURFCAM 2005 • API Documentation
InitListBox
ACTION: Initializes the listbox dialog, associating the dialog with an existing
parent window. The listbox is initialized with only the Cancel
button enabled.
RETURN: <None>
364
SURFCAM 2005 • API Documentation Chapter 8 Listbox Dialog Function Descriptions
lb_printf
RETURN: <None>
365
Chapter 8 Listbox Dialog Function Descriptions SURFCAM 2005 • API Documentation
put_end_message
RETURNS: <None>
366
SURFCAM 2005 • API Documentation Chapter 8 Listbox Dialog Function Descriptions
SetListBoxButtons
ACTION: Toggles the state of the listbox buttons. The three buttons Save,
Print, and Close are enabled and the Cancel button is disabled
when bState is TRUE. The three buttons Save, Print, and Close
are disabled and the Cancel button is enabled when bState is
FALSE.
RETURN: <None>
367
Chapter 8 Listbox Dialog Function Descriptions SURFCAM 2005 • API Documentation
WaitForEnd
ACTION: Displays dialog modally until the user selects the Close button.
The Cancel button is the only button disabled.
RETURNS: <None>
368
SURFCAM 2005 • API Documentation Chapter 8 Listbox Dialog Function Descriptions
Part III
369
Chapter 8 Listbox Dialog Function Descriptions SURFCAM 2005 • API Documentation
370
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
371
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
372
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
373
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
374
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
The purpose of the SURFCAM Tool Library DLL (TOOLLIB.DLL) is to provide a user replaceable module and
application programmable interface (API) to choose, load and optionally manage the SURFCAM tool and material
database. This document is intended as a reference for programmers who would be responsible for writing a
replacement for the tool library DLL. It also is intended as a reference for 3rd party applications that may need to
interface with the tool and material library and use the DLL.
The initial implementation of the SURFCAM Tool Library is written in C++ using the Microsoft Foundation
Class Library using ODBC classes to connect to the tool and material databases. The API consists of a C typed
structure that contains tool information which is able to be used by SURFCAM, and C functions which allow the
operator to select from a list of tools or load a specified tool from the library. Since these functions use a C calling
convention, and structure definitions are provided in C style header files, this module is most easily replaced with or
used by another written in C/C++. You are free to choose any other language or development tool to replace the tool
library DLL, but then interfacing correctly with SURFCAM may be more difficult, and support for any problems you
encounter may not be able to be provided.
The layout of this document is first to describe the tool data structures. Then the API functions for each type of
tool is presented. Finally, a few additional functions to complete the API are presented.
375
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
The following symbols appear in TOOLLIBS.H, each is followed by a description of its purpose.
// Tool Types
#define TL_TYPE_MILL 0 // Mill Tools
#define TL_TYPE_DRILL 1 // Drill Tools
#define TL_TYPE_LATHE 2 // Lathe Tools
#define TL_TYPE_LDRILL 3 // Lathe Drill Tools
#define TL_TYPE_DIGITIZE 4 // Digitizer Tools
#define TL_TYPE_EDM 5 // EDM Tools
#define TL_NUM_TYPES 6 // number of tool types
These symbols are for the various Tool Types supported in SURFCAM. The tool data structure tl_cutter_struct
member “type” should contain one of these values, depending upon the type of tool choosed or loaded from the
database. This is usually determined from which API function is called.
376
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
// tl_cutter_struct.cutter_flags
#define TL_FLAGS_GROOVE 1 // Groove
These symbols are for the tool data structure tl_cutter_struct member cutter_flags.
377
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
TOOLLIBS.H Structures
char filename The name of the file which contains the tool drawing.
int spin TRUE if the tool is to spin while displayed. FALSE if the tool is not to spin.
double ctipr The tool Tip Radius. Also, this may be called the tool Corner Radius.
double ctotr The tool Total Radius. This should be larger than the tip radius. For edm tools, this is the radius of
the wire.
double cdifr The calculated difference between the total radius and the tip radius.
double ctipoff The calculated tip offset, which is equal to the sum of the tip radius and the amount of material
to leave (distance from the surface).
double shank_radius The radius of the shank of the tool for mill, drill, or digitizer tools. For edm tools this
member holds the initial power setting.
double flute_height The height of the tool flutes. For edm tools this member holds the power setting.
double taper_angle The angle between the edge of the tool and the axis of rotation.
378
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
double scallop_height The scallop height or increment value. Interpretation depends upon the value of the member
scallop above.
In general, data which may not be used for a specific tool type can be safely initialized to zero.
379
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
int dummy Kept to maintain compatibility with old data structure, this used to be the turret number.
380
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
int type The tool type. This is to be filled in with one of the predefined tool type symbol/values provided
above. It should match the type requested by the API function called.
int ref_number The tool reference number. This is used to lookup the tool by number in the load functions.
char tool_desc The textual description of the tool. This is used currently in the tool list box for the user to select
from the list of available tools.
381
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
int num_drawings Number of tool drawing files. Usually two -one for the tool, one for the holder.
tl_tool_dsn_type drawings Name and spin for the tool drawing file. At most 5 of these.
int ref_num The material reference number. This is used to lookup the tool by number in the load functions.
char desc The material description. This is used in the Get material dialog box.
double sfm The material surface speed. This is selected from the material table depending upon the currently
selected tool material.
double chplfactor The material chip load factor. This is also selected from the material table depending upon the
currently selected tool material.
382
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
Declaration:
extern “C” long ToolLib_nGetMillTool(long nToolRef, tl_cutter_type *tl_cutter);
Parameters:
long nToolRef The reference number of the tool to display as the current selection. This is usually the last
tool selected, or at start is configured from SURFCAM.INI.
tl_cutter_type *tl_cutter A pointer to the cutter data structure which is to be filled in upon returning the
value of TRUE from this function.
Return Values:
TRUE mill tool is chosen and cutter information is provided.
FALSE no tool selected, or error occured.
Comments:
SURFCAM provides the address of an existing cutter structure to be filled in when calling this function. It
does not need to allocate the structure or free it if an error occurs. This should set the tool type to
TL_TYPE_MILL and fill in the general tool information and the cutter mill union.
Declaration:
extern “C” long ToolLib_nLoadMillTool(long nToolRef, tl_cutter_type *tl_cutter);
Parameters:
long nToolRef The tool reference number of the requested mill tool.
tl_cutter_type *tl_cutter A pointer to the cutter data structure which is to be filled in upon returning the
value of TRUE from this function.
Return Values:
TRUE mill tool cutter information is provided.
FALSE no cutter information found for the requested tool, or error occured.
Comments:
SURFCAM provides the address of an existing cutter structure to be filled in when calling this function. It
does not need to allocate the structure or free it if an error occurs. This should set the tool type to
TL_TYPE_MILL and fill in the general tool information and the cutter mill union.
383
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
Declaration:
extern “C” long ToolLib_nGetDrillTool(long nToolRef, tl_cutter_type *tl_cutter);
Parameters:
long nToolRef The reference number of the tool to display as the current selection. This is usually the last
tool selected, or at start is configured from SURFCAM.INI.
tl_cutter_type *tl_cutter A pointer to the cutter data structure which is to be filled in upon returning the
value of TRUE from this function.
Return Values:
TRUE drill tool is chosen and cutter information is provided.
FALSE no tool selected, or error occured.
Comments:
SURFCAM provides the address of an existing cutter structure to be filled in when calling this function. It
does not need to allocate the structure or free it if an error occurs. This should set the tool type to
TL_TYPE_DRILL and fill in the general tool information and the cutter drill union.
Declaration:
extern “C” long ToolLib_nLoadDrillTool(long nToolRef, tl_cutter_type *tl_cutter);
Parameters:
long nToolRef The tool reference number of the requested drill tool.
tl_cutter_type *tl_cutter A pointer to the cutter data structure which is to be filled in upon returning the
value of TRUE from this function.
Return Values:
TRUE drill tool cutter information is provided.
FALSE no cutter information found for the requested tool, or error occured.
Comments:
SURFCAM provides the address of an existing cutter structure to be filled in when calling this function. It
does not need to allocate the structure or free it if an error occurs. This should set the tool type to
TL_TYPE_DRILL and fill in the general tool information and the cutter drill union.
384
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
Declaration:
extern “C” long ToolLib_nGetLatheTool(long nToolRef, tl_cutter_type *tl_cutter);
Parameters:
long nToolRef The reference number of the tool to display as the current selection. This is usually the last
tool selected, or at start is configured from SURFCAM.INI.
tl_cutter_type *tl_cutter A pointer to the cutter data structure which is to be filled in upon returning the
value of TRUE from this function.
Return Values:
TRUE lathe tool is chosen and cutter information is provided.
FALSE no tool selected, or error occured.
Comments:
SURFCAM provides the address of an existing cutter structure to be filled in when calling this function. It
does not need to allocate the structure or free it if an error occurs. This should set the tool type to
TL_TYPE_LATHE and fill in the general tool information and the cutter lathe union.
Declaration:
extern “C” long ToolLib_nLoadLatheTool(long nToolRef, tl_cutter_type *tl_cutter);
Parameters:
long nToolRef The tool reference number of the requested lathe tool.
tl_cutter_type *tl_cutter A pointer to the cutter data structure which is to be filled in upon returning the
value of TRUE from this function.
Return Values:
TRUE lathe tool cutter information is provided.
FALSE no cutter information found for the requested tool, or error occured.
Comments:
SURFCAM provides the address of an existing cutter structure to be filled in when calling this function. It
does not need to allocate the structure or free it if an error occurs. This should set the tool type to
TL_TYPE_LATHE and fill in the general tool information and the cutter lathe union.
385
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
Declaration:
extern “C” long ToolLib_nGetLDrillTool(long nToolRef, tl_cutter_type *tl_cutter);
Parameters:
long nToolRef The reference number of the tool to display as the current selection. This is usually the last
tool selected, or at start is configured from SURFCAM.INI.
tl_cutter_type *tl_cutter A pointer to the cutter data structure which is to be filled in upon returning the
value of TRUE from this function.
Return Values:
TRUE lathe drill tool is chosen and cutter information is provided.
FALSE no tool selected, or error occured.
Comments:
SURFCAM provides the address of an existing cutter structure to be filled in when calling this function. It
does not need to allocate the structure or free it if an error occurs. This should set the tool type to
TL_TYPE_LDRILL and fill in the general tool information and the cutter drill union.
Declaration:
extern “C” long ToolLib_nLoadLDrillTool(long nToolRef, tl_cutter_type *tl_cutter);
Parameters:
long nToolRef The tool reference number of the requested lathe drill tool.
tl_cutter_type *tl_cutter A pointer to the cutter data structure which is to be filled in upon returning the
value of TRUE from this function.
Return Values:
TRUE lathe drill tool cutter information is provided.
FALSE no cutter information found for the requested tool, or error occured.
Comments:
SURFCAM provides the address of an existing cutter structure to be filled in when calling this function. It
does not need to allocate the structure or free it if an error occurs. This should set the tool type to
TL_TYPE_LDRILL and fill in the general tool information and the cutter drill union.
386
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
Declaration:
extern “C” long ToolLib_nGetDgtzTool(long nToolRef, tl_cutter_type *tl_cutter);
Parameters:
long nToolRef The reference number of the tool to display as the current selection. This is usually the last
tool selected, or at start is configured from SURFCAM. INI.
tl_cutter_type *tl_cutter A pointer to the cutter data structure which is to be filled in upon returning the
value of TRUE from this function.
Return Values:
TRUE digitizer is chosen and cutter information is provided.
FALSE no tool selected, or error occured.
Comments:
SURFCAM provides the address of an existing cutter structure to be filled in when calling this function. It
does not need to allocate the structure or free it if an error occurs. This should set the tool type to
TL_TYPE_DIGITIZE and fill in the general tool information and the cutter mill union.
Declaration:
extern “C” long ToolLib_nLoadDgtzTool(long nToolRef, tl_cutter_type *tl_cutter);
Parameters:
long nToolRef The reference number of the tool to display as the current selection. This is usually the last
tool selected, or at start is configured from SURFCAM.INI.
long nToolRef The tool reference number of the requested digitizer.
tl_cutter_type *tl_cutter A pointer to the cutter data structure which is to be filled in upon returning the
value of TRUE from this function.
Return Values:
TRUE digitizer information is provided.
FALSE no information found for the requested tool, or error occured.
Comments:
SURFCAM provides the address of an existing cutter structure to be filled in when calling this function. It
does not need to allocate the structure or free it if an error occurs. This should set the tool type to
TL_TYPE_DIGITIZE and fill in the general tool information and the cutter mill union.
387
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
Declaration:
extern “C” long ToolLib_nGetEdmTool(long nToolRef, tl_cutter_type *tl_cutter);
Parameters:
long nToolRef The reference number of the tool to display as the current selection. This is usually the last
tool selected, or at start is configured from SURFCAM.INI.
tl_cutter_type *tl_cutter A pointer to the cutter data structure which is to be filled in upon returning the
value of TRUE from this function.
Return Values:
TRUE edm tool is chosen and cutter information is provided.
FALSE no tool selected, or error occured.
Comments:
SURFCAM provides the address of an existing cutter structure to be filled in when calling this function. It
does not need to allocate the structure or free it if an error occurs. This should set the tool type to
TL_TYPE_EDM and fill in the general tool information and the cutter edm union.
Declaration:
extern “C” long ToolLib_nLoadEdmTool(long nToolRef, tl_cutter_type *tl_cutter);
Parameters:
long nToolRef The tool reference number of the requested edm tool.
tl_cutter_type *tl_cutter A pointer to the cutter data structure which is to be filled in upon returning the
value of TRUE from this function.
Return Values:
TRUE edm tool cutter information is provided.
FALSE no cutter information found for the requested tool, or error occured.
Comments:
SURFCAM provides the address of an existing cutter structure to be filled in when calling this function. It
does not need to allocate the structure or free it if an error occurs. This should set the tool type to
TL_TYPE_EDM and fill in the general tool information and the cutter edm union.
388
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
Declaration:
extern “C” long ToolLib_nGetTool(long nToolType, long nToolRef, tl_cutter_type *tl_cutter);
Parameters:
long nToolType The type of tool to be selected.
long nToolRef The reference number of the tool to display as the current selection. This is usually the last
tool selected, or at start is configured from SURFCAM.INI.
tl_cutter_type *tl_cutter A pointer to the cutter data structure which is to be filled in upon returning the
value of TRUE from this function.
Return Values:
TRUE tool is chosen and cutter information is provided.
FALSE no tool selected, or error occured.
Comments:
SURFCAM provides the address of an existing cutter structure to be filled in when calling this function. It
does not need to allocate the structure or free it if an error occurs. This should set the tool type to
nToolType and fill in the general tool information and the appropriate cutter union data.
Declaration:
extern “C” long ToolLib_nLoadTool(long nToolType, long nToolRef, tl_cutter_type *tl_cutter);
Parameters:
long nToolType The type of tool to be selected.
long nToolRef The tool reference number of the requested tool.
tl_cutter_type *tl_cutter A pointer to the cutter data structure which is to be filled in upon returning the
value of TRUE from this function.
Return Values:
TRUE tool cutter information is provided.
FALSE no cutter information found for the requested tool, or error occured.
Comments:
SURFCAM provides the address of an existing cutter structure to be filled in when calling this function. It
does not need to allocate the structure or free it if an error occurs. This should set the tool type to
nToolType and fill in the general tool information and the appropriate cutter union data.
389
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
Declaration:
extern long ToolLib_nGetMaterial(long nType, long nMaterialRef, tl_material_type *tl_material);
Parameters:
long nType This is the tool material type for the currently selected tool. This is used to select the
appropriate SFM and CLF from the selected material.
long nMaterialRefThe reference number of the material to display as the current selection. This is usually
the last material selected, or at start is configured from SURFCAM.INI.
tl_material_type *tl_material A Pointer to the material data structure to be filled in upon returning the
value of TRUE from this function.
Return Values:
TRUE material information is provided.
FALSE no material selected, user canceled, or error occured.
Comments:
SURFCAM provides the address of an existing material structure to be filled in when calling this function.
It does not need to allocate the structure or free it if an error occurs. This should fill in the material
information for the specified tool material type.
Declaration:
extern long ToolLib_nLoadMaterial(long nType, long nMaterialRef, tl_material_type *tl_material);
Parameters:
long nType This is the tool material type for the currently selected tool. This is used to selecte the
appropriate SFM and CLF from the requested material.
long nMaterialRefThis is the reference number for the material requested.
tl_material_type *tl_material A Pointer to the material data structure to be filled in upon returning the
value of TRUE from this function.
Return Values:
TRUE material information is provided.
FALSE no material information found for the requested material, or error occured.
Comments:
SURFCAM provides the address of an existing material structure to be filled in when calling this function.
It does not need to allocate the structure or free it if an error occurs. This should fill in the material
information for the specified tool material type.
390
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
Declaration:
extern “C” long ToolLib_nGetToolUnits(void);
Return Values:
The function returns one of the following values of the symbols declared in ToolAPI.h:
TOOLLIB_UNITS_US
TOOLLIB_UNITS_METRIC
Declaration:
extern “C” long ToolLib_nSetToolUnits(long nUnits);
Parameters:
long nUnits The new unit type requested. This should be one of the values for the unit symbols defined in
ToolAPI.h.
Return Values:
TRUE if units type changed successfully.
FALSE units not changed (invalid unit type specified).
Comments:
SURFCAM calls ToolLib_nSetToolUnits() when the user changes units in the options menu. In the current
implementation, the database contains US and Metric tools, and only tools of the requested unit type are
displayed for selection by the user. An alternative method might be converting the parameters to the current
units for the selected tool when the cutter structure is filled in and returned from the Get or Load functions.
391
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
Sample Code
// ToolLib.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "ToolLib.h"
#include "ToolAPI.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CToolLibApp
BEGIN_MESSAGE_MAP(CToolLibApp, CWinApp)
//{{AFX_MSG_MAP(CToolLibApp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CToolLibApp construction
CToolLibApp::CToolLibApp()
{
m_nToolUnits =TOOLLIB_UNITS_US;
} // CToolLibApp
/////////////////////////////////////////////////////////////////////////////
// The one and only CToolLibApp object
CToolLibApp theApp;
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nGetMillTool(long nToolRef, tl_cutter_type *tl_cutter)
{
// TODO: User Selects Tool
return(FALSE); // Failure
} // ToolLib_nGetMillTool
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nLoadMillTool(long nToolRef, tl_cutter_type *tl_cutter)
{
// TODO: Load Referenced Tool -No User Interaction.
return(FALSE); // Failure
} // ToolLib_nLoadMillTool
392
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nGetDrillTool(long nToolRef, tl_cutter_type *tl_cutter)
{
// TODO: User Selects Tool
return(FALSE); // Failure
} // ToolLib_nGetDrillTool
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nLoadDrillTool(long nToolRef, tl_cutter_type *tl_cutter)
{
// TODO: Load Referenced Tool -No User Interaction.
return(FALSE); // Failure
} // ToolLib_nLoadDrillTool
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nGetLatheTool(long nToolRef, tl_cutter_type *tl_cutter)
{
// TODO: User Selects Tool
return(FALSE); // Failure
} // ToolLib_nGetLatheTool
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nLoadLatheTool(long nToolRef, tl_cutter_type *tl_cutter)
{
// TODO: Load Referenced Tool -No User Interaction.
return(FALSE); // Failure
} // ToolLib_nLoadLatheTool
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nGetLDrillTool(long nToolRef, tl_cutter_type *tl_cutter)
{
// TODO: User Selects Tool
return(FALSE); // Failure
} // ToolLib_nGetLDrillTool
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nLoadLDrillTool(long nToolRef, tl_cutter_type *tl_cutter)
{
// TODO: Load Referenced Tool -No User Interaction.
return(FALSE); // Failure
} // ToolLib_nLoadLDrillTool
393
Chapter 6 Sample Code SURFCAM 2005 • API Documentation
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nGetDgtzTool(long nToolRef, tl_cutter_type *tl_cutter)
{
// TODO: User Selects Tool
return(FALSE); // Failure
} // ToolLib_nGetDgtzTool
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nLoadDgtzTool(long nToolRef, tl_cutter_type *tl_cutter)
{
// TODO: Load Referenced Tool -No User Interaction.
return(FALSE); // Failure
} // ToolLib_nLoadDgtzTool
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nGetEdmTool(long nToolRef, tl_cutter_type *tl_cutter)
{
// TODO: User Selects Tool
return(FALSE); // Failure
} // ToolLib_nGetEdmTool
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nLoadEdmTool(long nToolRef, tl_cutter_type *tl_cutter)
{
// TODO: Load Referenced Tool -No User Interaction.
return(FALSE); // Failure
} // ToolLib_nLoadEdmTool
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nGetTool(long nToolType, long nToolRef, tl_cutter_type *tl_cutter)
{
// TODO: Use or replace this -Its used as helper to call one of the above.
long nRes =FALSE; // Nothing Gotten
switch (nToolType)
{
case TL_TYPE_MILL:
nRes =ToolLib_nGetMillTool(nToolRef, tl_cutter); break;
case TL_TYPE_DRILL:
nRes =ToolLib_nGetDrillTool(nToolRef, tl_cutter); break;
case TL_TYPE_LATHE:
nRes =ToolLib_nGetLatheTool(nToolRef, tl_cutter); break;
case TL_TYPE_LDRILL:
nRes =ToolLib_nGetLDrillTool(nToolRef, tl_cutter); break;
case TL_TYPE_DIGITIZE:
nRes =ToolLib_nGetDgtzTool(nToolRef, tl_cutter); break;
case TL_TYPE_EDM:
nRes =ToolLib_nGetEdmTool(nToolRef, tl_cutter); break;
default: // Something Errory
TRACE0("ToolLib Error: Bad Tool Type Requested!\n");
break;
} // switch on nToolType
return(nRes);
} // ToolLib_nGetTool
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nLoadTool(long nToolType, long nToolRef, tl_cutter_type *tl_cutter)
{
// TODO: Use or replace this -Its used as helper to call one of the above.
long nRes =FALSE; // Nothing Loaded
switch (nToolType)
{
case TL_TYPE_MILL:
nRes =ToolLib_nLoadMillTool(nToolRef, tl_cutter); break;
case TL_TYPE_DRILL:
nRes =ToolLib_nLoadDrillTool(nToolRef, tl_cutter); break;
394
SURFCAM 2005 • API Documentation Chapter 6 Sample Code
case TL_TYPE_LATHE:
nRes =ToolLib_nLoadLatheTool(nToolRef, tl_cutter); break;
case TL_TYPE_LDRILL:
nRes =ToolLib_nLoadLDrillTool(nToolRef, tl_cutter); break;
case TL_TYPE_DIGITIZE:
nRes =ToolLib_nLoadDgtzTool(nToolRef, tl_cutter); break;
case TL_TYPE_EDM:
nRes =ToolLib_nLoadEdmTool(nToolRef, tl_cutter); break;
default: // Something Errory
TRACE0("ToolLib Error: Bad Tool Type Requested!\n");
break;
} // switch on nToolType
return(nRes);
} // ToolLib_nLoadTool
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nGetMaterial(long nType, long nMaterialRef, tl_material_type
*tl_material)
{
return(FALSE); // Failure
} // ToolLib_nGetMaterial
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nLoadMaterial(long nType, long nMaterialRef, tl_material_type
*tl_material)
{
return(FALSE); // Failure
} // ToolLib_nLoadMaterial
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nGetToolUnits(void)
{
// Simple Access to current units type
return(theApp.m_nToolUnits);
} // ToolLib_nGetToolUnits
/////////////////////////////////////////////////////////////////////////////
extern "C" long ToolLib_nSetToolUnits(long nUnits)
{
// Check for valid Units....
switch(nUnits)
{
case TOOLLIB_UNITS_US: // US Tool -Units Inches
theApp.m_nToolUnits =TOOLLIB_UNITS_US;
break;
case TOOLLIB_UNITS_METRIC: // Metric Tool -Units MiliMeters
theApp.m_nToolUnits =TOOLLIB_UNITS_METRIC;
break;
default: // Something Errory...
TRACE0("Unknown Units Type In ToolLib_nSetToolUnits.\n");
return(FALSE); // Failure
} // switch on nUnits
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
395
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
Part IV
3
9
6
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
397
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
Chapter 9
The SURFCAM
Toolpath API
TOOLPATHS IN SURFCAM
398
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
SURFCAM names INC files according to the order in which they are created.
The conventional INC file is named “INC***.inc”, where the *** is a three letter
suffix. The first INC file created would be called “INCAAA.inc”, the second
would be called “INCAAB.inc”, and so on.
399
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
The ICD file uses a standard Microsoft COM (Component Object Model) storage
interface known as IStorage. Within the IStorage interface are IStream objects.
These IStream objects are the INC files, and the NCPost API functions to create,
read, and write the INC files are actually wrappers for standard IStream member
functions.
INC RECORDS
IINC files are composed of a series of INC records. Each INC record corresponds
to either toolpath parameter information or a command, and is composed of three
parts. The first part of the INC record gives the type, the second part of the record
states the size of the record data, and the third part of the INC record gives the
actual data (if any). The only exception to this is the INC header, which must be
the first record in the INC file. The INC header has no record size or data type.
Each INC file contains the information for a single toolpath, using the same tool
throughout the toolpath. Operations requiring multiple tools will require separate
INC files. Every INC file has a specific structure described on the next page.
400
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
INC Header
Address Information
Operation
Cutter Information
401
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
There are 63 different INC records used in SURFCAM toolpaths. The code that
defines them is found in incstrct.h, and these records are summarized in the table
below.
402
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
Every INC file must begin with the structure inct_header. This header gives basic
information about the INC file, such as the version of the INC file and the author.
The structure is explained in the table below.
403
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
404
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
405
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
406
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
407
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
408
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
WRITING A DLL
Using the functions and data structures described below, the programmer can
create a DLL which can then be utilized from within SURFCAM. This DLL is
incorporated into SURFCAM by making a slight modification to the
SURFCAM.ini file. Within the SURFCAM.ini file, there is a section entitled
[SystemOptional], which contains this code:
UserApplications=2
UserApp1=D:\SURFCAM\Surf2005\UserApp1.dll
UserApp2=D:\SURFCAM\Surf2005\UserApp2.dll
The line “UserApplications=” refers to the number of user applications that you
want to activate. You can give your DLL any name you choose, substituting the
name of your DLL for “UserApp1.dll”, “UserApp2.dll”, etc. You can add more
than two applications, or have less than two applications as desired.
After modifying the SURFCAM.ini file, you need to make a change in a file
called MNU.def. This file is found in the path of your default SURFCAM
directory\Surf2005\Def. Copy this file to your default SURFCAM directory\Def
(the directory that contains the program surfrc.exe). After removing the read-
only attribute from this file, open the file and proceed to the section: “mainmenu
"PlugIns" 7”.
Here you will find the menu listings for the SURFCAM PlugIns menu. You
replace the name "UserApp&1" or "UserApp&2", etc., with the name of your
application as you want it to appear in the menu, and save the file. Next, from the
DOS command prompt, you run the program Surfrc.exe from that same directory
using the syntax:
surfrc –c MNU.def
This creates a new copy of SURFCAM.mnu, which contains your new application
name as part of the PlugIns menu. Substitute your new SURFCAM.mnu file into
your Surf2005 directory. To access this from within SURFCAM, hold down the
Control key and the letter “B”.
When writing your program, be sure to include the header files "expfunc.h" and
"incstrct.h". These files contain the necessary function and structure prototypes to
access the SURFCAM toolpath API.
409
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
410
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
411
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
Chapter 10
The Toolpath API
Function Descriptions
412
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
413
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scNCOp_CreateOperation
OUTPUT ARGUMENTS: The character string sIncFileName will contain the full path of the
newly created NC Operations Manager project item, including the
name that is assigned to the newly created operation. The string
will be no longer than MAX_PATH.
414
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
scNCOp_CreateOperationToo
OUTPUT ARGUMENTS: The character string sIncFileName will contain the full path of the
newly created NC Operations Manager project item, including the
name that is assigned to the newly created operation.
INPUT ARGUMENTS: The character string sComment1 for the first operation comment.
415
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scNCOp_SetCurrentDesc
416
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
scNCOp_ CommitOperation
417
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scNCOp_ CommitBeforeLastOperation
418
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
scNCOp_ReleaseOperation
ACTION: This function releases all memory associated with the newly
created NC Operations Manager project item. This function
should be called if an error condition is detected in any phase of
the scNCOp_CreateOperation or scNCOp_CommitOperation
processes, or if there is an error while performing other file
manipulation processes.
RETURN: Zero
419
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scNCOp_GetItemPacketHandle
PROTOTYPE: void *
scNCOp_GetItemPacketHandle(const char * sFileName)
ACTION: Returns the packet handle of the given INC file stored in the ICD
compound document.
420
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
scNCOp_OpenNCProjectItem
PROTOTYPE: long
scNCOp_OpenNCProjectItem (const char * sFileName)
ACTION: Displays the cut control page associated with an INC file in the
compound document.
421
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scNCOp_SelectNCProjectItem
PROTOTYPE: long
scNCOp_SelectNCProjectItem(const char * sFileName
long nReserved1,
long nReserved2)
ACTION: Displays a dialog with the operations tree, allowing the user to
select an operation using a graphical interface. The function fills
in the name of the INC file associated with the operation.
422
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
scICDAPI_Open
INPUT ARGUMENTS: const char *filename - Pointer to the name of the file.
const char *mode – The type of access desired. Choose from the
following:
423
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scICDAPI_Eof
ACTION: Checks to see if the end of the file has been reached.
RETURN: Returns -1 if the end of file has been reached, otherwise zero.
424
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
scICDAPI_Getc
425
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scICDAPI_Putc
INPUT ARGUMENTS: int ch – The character to be written to the stream (as an integer).
426
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
scICDAPI_Read
RETURN: The number of items that were read, or zero if nothing is read or
end of file.
INPUT ARGUMENTS: void* buffer – Address of storage location for the data.
427
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scICDAPI_Write
428
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
scICDAPI_Seek
ACTION: Moves the pointer to the chosen location within the file.
int origin – The position of origin of the file pointer. Choose one
of the following constants:
SEEK_SET – The beginning of the file
SEEK_CUR – The current location of the file pointer
SEEK_END – The end of the file
429
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scICDAPI_Tell
430
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
scICDAPI_Close
RETURN: None
431
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scICDAPI_Erase
RETURN: None
INPUT ARGUMENTS: const char * sFileName The name of INC file to erase
432
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
scICDAPI_SetSize
ACTION: Sets the length of the INC file (in bytes). This is useful if the use
removes or shortens INC records in the INC file.
433
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scICDAPI_Clone
ACTION: Clones the file pointer to an existing stream. This allows the user
to read and write information at different positions in the same
INC file.
434
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
scNCOp_GetOpSectionName
ACTION: Gets the Section Name for a given INC Operation Name.
435
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scNCOp_AddSetupSection
436
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
scICDAPI_Query
437
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scGetSURFCAMAPIVersion
ACTION: Will return the Surfcam API version. For Surfcam 2005, it is 100.
438
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
scGetSURFCAMMajorVersion
ACTION: Will return the Surfcam major version. For Surfcam 2005, it is
2005
439
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scGetSURFCAMMinorVersion
ACTION: Will return the Surfcam minor version. For Surfcam 2005 service
pack 1, it is zero.
440
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
scGetSURFCAMBuildVersion
441
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scGetSURFCAMBuildString
ACTION: Will return the full Surfcam build version and build number.
442
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
scUpdateOperationNoUI
443
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scRegenerateOperationNoUI
444
SURFCAM 2005 • API Documentation Chapter 10 Toolpath API Function Descriptions
scUpdateAllOperationsNoUI
445
Chapter 10 Toolpath API Function Descriptions SURFCAM 2005 • API Documentation
scRegenerateAllOperationsNoUI
446
SURFCAM 2005 • API Documentation Chapter 11 Toolpath API Sample Code
Chapter 11
Sample Code Using
the Toolpath API
4
4
7
Chapter 11 Toolpath API Sample Code SURFCAM 2005 • API Documentation
448
SURFCAM 2005 • API Documentation Chapter 11 Toolpath API Sample Code
The sample file UserApp.cpp demonstrates a brief example of how an INC file is created and written. Here the
program uses the API to create the INC file in two parts. First, the operation is created within the framework of the
NCPost API. Second, the INC file is created with an association to the operation just created in NCPost.
The program then writes informational INC records to provide the basic parameters for the toolpath. First, the
address header is written to give information about the author. Then the world coordinate system is recorded to give
the basic orientation of the toolpath. The operation type is necessary to indicate what kind of cutting operation is
described (milling, lathe, wire EDM, etc.) Multiaxis support is not required for the sample, so it is toggled off.
Finally, the cutter info and tool change information is written to the INC file to describe the tool and cutting
parameters.
After these parameters are given, the actual toolpath generation begins. Setting the feed rate to rapid, the program
then enters commands to move the tool to specific coordinates. By setting different feed rates and coordinates, the
program can produce any desired toolpath. Lines, arcs, and NURB curves can be programmed in three, four, and
five axes by using the appropriate INC records.
#include "stdafx.h"
#include "UserApp.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CUserAppApp
449
Chapter 11 Toolpath API Sample Code SURFCAM 2005 • API Documentation
BEGIN_MESSAGE_MAP(CUserAppApp, CWinApp)
//{{AFX_MSG_MAP(CUserAppApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUserAppApp construction
CUserAppApp::CUserAppApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CUserAppApp object
CUserAppApp theApp;
/**************************************************************************/
/* Above code generated by Microsoft Visual C++. Sample code starts here */
/**************************************************************************/
/////////////////////////////////////////////////////////////////////////////
// Global objects
// All SURFCAM INC files begin with an address header, which gives the author's
// address information. Create one to begin the INC file we are going to create.
inct_address AuthorInfo =
{
"Josh", // The author's name
"Josh's Machine Shop", // Address line 1
"5703 Corsa Avenue", // Address line 2
"Westlake Village", // City
"CA", // State
"USA" // Country
"91362" // Zip code
};
// Every operation requires a defined tool. Here we will define a sample tool:
// a 1/2" four fluted ceramic bullnose endmill. Every tool is defined by the
// SURFCAM structure inct_cutterx.
inct_cutterx HalfInchBullnose =
{
0, // Library type (mill = 0)
3, // Library reference number (arbitrarily chose 3)
"1/2 inch bullnose", // Cutter description
5, // Library tool material (ceramic = 5)
2, // Library tool class (bullnose = 2)
TRUE, // Programmed to the tip if true, to the center if false
4, // Number of flutes
0, // Unused
0, // Unused
0, // Unused
0.25, // Tip radius
0.25, // Total radius
0.0, // Difference between total radius and tip radius
0.25, // Tip radius + distance away from finish
0.05, // Shank radius
0.0, // Tool tip angle (defined for drills)
0.0, // Tool taper angle
450
SURFCAM 2005 • API Documentation Chapter 11 Toolpath API Sample Code
// The "speeds and feeds" of the operation also need to be defined. The
// structure inct_tcx contains the material information, the speeds and feed
// rates, and other relevant cutting data. These are final values and must be
// calculated accurately according to the material and tool associated with the
// operation.
inct_tcx SampleToolChange =
{
0, // Material library reference number
"Sample Material", // Material description
0, // Unit mode (English = 0)
0, // Program number
0, // Sequence number
0, // Sequence increment
1, // Tool number
1, // Diameter offset
1, // Length offset
0, // Work offset
0, // Turret number
1000, // Spindle speed
0, // Spindle speed - constant surface speed
0, // Feed/plunge rate units (units per minute = 0)
0, // Coolant (none = 0)
0, // Rotary axis (none = 0)
0, // Unused
0, // Unused
0, // Unused
0.0, // X Calibration Length
0.0, // Z Calibration Length
1.0, // Z Rapid Plane
0.0, // Initial power (EDM specific)
0.0, // Power (EDM specific)
0.0, // Spark gap (EDM specific)
0, // Wire feed (EDM specific)
0.0, // Taper angle
0.0, // Unused
0.0, // Unused
0.0 // Unused
};
/////////////////////////////////////////////////////////////////////////////
// bWriteIncHeader
//
// This function writes the header information. A header record is unique in
// that there is no INC type associated with the record, hence this dedicated
// function (all other INC records in this sample are written using
// the function bWriteIncRecord().
static BOOL
bWriteIncHeader(void* pICDStream)
{
ULONG nCount; // Number of bytes to write
ULONG nActualWritten; // Number of bytes written
inct_header SampleHeader; // Header to write
451
Chapter 11 Toolpath API Sample Code SURFCAM 2005 • API Documentation
nCount = sizeof(inct_header);
if (nActualWritten != nCount)
return FALSE;
/////////////////////////////////////////////////////////////////////////////
// bWriteIncRecord
//
// This function writes a single INC record, given the type and data of the
// record to be written. This is a great function that can be copied directly
// for use in user programs.
static BOOL
bWriteIncRecord(
int nType, // ii Type of INC record
int nSize, // ii Size of INC data
void* pData, // ii Data to be written
void* pICDStream) // io ICD stream to write to
{
BYTE Buffer; // Write byte buffer
ULONG nActualWritten; // Number of bytes written
// Assign the INC record type to the buffer, and write the buffer.
Buffer = (BYTE) nType;
nActualWritten = scICDAPI_Write(&Buffer, sizeof(Buffer), 1, pICDStream);
if (nActualWritten != 1)
return(FALSE);
// Assign the INC record size to the buffer, and write the buffer.
Buffer = (BYTE) nSize/2;
nActualWritten =scICDAPI_Write(&Buffer, sizeof(Buffer), 1, pICDStream);
if (nActualWritten != 1)
return(FALSE);
if (pData == NULL)
return(FALSE);
return(TRUE);
} // bWriteIncRecord
/////////////////////////////////////////////////////////////////////////////
//
// UserApp_nCallback
//
// All SURFCAM user applications must define UserApp_nCallback. SURFCAM
// searches for this function in the DLL and calls this function. SURFCAM
// passes the pointer to the API functions through the argument.
452
SURFCAM 2005 • API Documentation Chapter 11 Toolpath API Sample Code
{
AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Required Visual C++ macro
long nRes = 0;
char sIncFileName[MAX_PATH];
char sIncFileDesc[MAX_PATH];
scNCOp_SetCurrentDesc(sIncFileDesc);
// Check for failure to open the ICD stream (indicated by returning NULL).
if (pICDStream == NULL)
{
AfxMessageBox("Sorry, Open Stream Failed!");
return -1;
}
453
Chapter 11 Toolpath API Sample Code SURFCAM 2005 • API Documentation
WorldCoords.mat[0][0] = 1.0;
WorldCoords.mat[1][1] = 1.0;
WorldCoords.mat[2][2] = 1.0;
line.x = 0.0f;
line.y = 0.0f;
line.z = 1.0f;
// Write the initial rapid move to move the tool one inch above the origin.
bRes = bWriteIncRecord(INC_RAPID, sizeof(inct_line), &line,
pICDStream);
line.z = 0.1f;
// Write a rapid move to move the tool 0.1 inch above the origin (to the
// start of the plunge move).
bRes = bWriteIncRecord(INC_RAPID, sizeof(inct_line), &line,
pICDStream);
line.z = 0.0f;
454
SURFCAM 2005 • API Documentation Chapter 11 Toolpath API Sample Code
line.x = 1.0f;
// Write a linear feed move to move the tool one inch along X.
bRes = bWriteIncRecord(INC_LINE, sizeof(inct_line), &line,
pICDStream);
line.z = 1.0f;
// Write the final rapid move to move the tool to the clearance plane.
bRes = bWriteIncRecord(INC_RAPID, sizeof(inct_line), &line,
pICDStream);
// Close stream.
scICDAPI_Close(pICDStream);
///////////////////////////////////////////////////////////////////////////
455
Chapter 11 Toolpath API Sample Code SURFCAM 2005 • API Documentation
The sample file UserAppRead.cpp illustrates a general method of reading an INC file. In order to read an INC file,
you must know the name of the file stream. Once the desired file stream is opened, the INC records may be read.
The first element in an INC file is the header record, which gives basic information about the author of the operation
and the version of the INC file. Because INC records may differ from version to version of SURFCAM, it is always
a good idea to check the signature member with the predefined INC_SIGNATURE of the API code being utilized.
After the header has been validated, the program enters a loop to read the INC records. Each INC record is a three-
part object, with a data type preceding the data size and actual data. The loop reads in the type of the INC record
first, then fills in the appropriate data structure depending on the record type. The loop continues until the end of the
INC file is reached.
#include "stdafx.h"
#include "UserAppRead.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CUserAppReadApp
BEGIN_MESSAGE_MAP(CUserAppReadApp, CWinApp)
//{{AFX_MSG_MAP(CUserAppReadApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
456
SURFCAM 2005 • API Documentation Chapter 11 Toolpath API Sample Code
/////////////////////////////////////////////////////////////////////////////
// CUserAppReadApp construction
CUserAppReadApp::CUserAppReadApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CUserAppReadApp object
CUserAppReadApp theApp;
/**************************************************************************/
/* Above code generated by Microsoft Visual C++. Sample code starts here */
/**************************************************************************/
/////////////////////////////////////////////////////////////////////////////
//
// UserApp_nCallback
//
// All SURFCAM user applications must define UserApp_nCallback. SURFCAM
// searches for this function in the DLL and calls this function. SURFCAM
// passes the pointer to the API functions through the argument.
char sIncFileName[MAX_PATH];
// ATTENTION: In order to open an INC file within the document, you must
// know the name of the file exactly. INC files are usually named
// "INCxxx.INC", with the xxx representing three letters.
strcpy(sIncFileName, "INCAAA.INC");
// Check for failure to open the ICD stream (indicated by returning NULL).
if (pICDStream == NULL)
{
AfxMessageBox("Sorry, Open Stream Failed!");
return -1;
}
457
Chapter 11 Toolpath API Sample Code SURFCAM 2005 • API Documentation
// Loop through the file reading code until no more records to be read.
while (nRecordsRead != 0)
{
// Read INC type of record.
nRecordsRead = scICDAPI_Read(&ch, 1, 1, pICDStream);
if (nRecordsRead != 0)
{
// INC record type successfully read.
nCode = ch;
if (nRecordsRead != 1)
return -1;
ch = (BYTE) nCode;
OutFile.Write(&ch, 1);
ch =(BYTE) (nSize/2);
OutFile.Write(&ch, 1);
OutFile.Write(&Address, nSize);
break;
} // INC_ADDRESS
case INC_CUTTER_INFO_EX:
{
inct_cutterx Cutter;
ASSERT(nSize == sizeof(inct_cutterx));
nRecordsRead = scICDAPI_Read(&Cutter, nSize, 1, pICDStream);
if (nRecordsRead != 1)
return -1;
ch =(BYTE) nCode;
OutFile.Write(&ch, 1);
ch =(BYTE) (nSize/2);
OutFile.Write(&ch, 1);
OutFile.Write(&Cutter, nSize);
458
SURFCAM 2005 • API Documentation Chapter 11 Toolpath API Sample Code
break;
} // INC_CUTTER_INFO_EX
case INC_RAPID:
case INC_PLUNGE:
case INC_LINE:
{
inct_line Line;
ASSERT(nSize == sizeof(inct_line));
nRecordsRead = scICDAPI_Read(&Line, nSize, 1, pICDStream);
if (nRecordsRead != 1)
return -1;
ch =(BYTE) nCode;
OutFile.Write(&ch, 1);
ch =(BYTE) (nSize/2);
OutFile.Write(&ch, 1);
OutFile.Write(&Line, nSize);
break;
} // INC_RAPID, INC_PLUNGE, INC_LINE
case INC_CUT_MODE:
{
inct_cut_mode nCutMode;
if (nRecordsRead != 1)
return -1;
ch =(BYTE) nCode;
OutFile.Write(&ch, 1);
ch =(BYTE) (nSize/2);
OutFile.Write(&ch, 1);
OutFile.Write(&nCutMode, nSize);
break;
} // INC_CUT_MODE
case INC_TOOL_CHANGE_EX:
{
inct_tcx ToolChange;
ASSERT(nSize == sizeof(inct_tcx));
if (nRecordsRead != 1)
return -1;
ch =(BYTE) nCode;
OutFile.Write(&ch, 1);
ch =(BYTE) (nSize/2);
OutFile.Write(&ch, 1);
OutFile.Write(&ToolChange, nSize);
break;
} // INC_TOOL_CHANGE_EX
default:
{
// If the INC record has data (not all records do), then read
// the data.
if (nSize != 0)
{
nRecordsRead = scICDAPI_Read(&Buffer, nSize, 1, pICDStream);
459
Chapter 11 Toolpath API Sample Code SURFCAM 2005 • API Documentation
if (nRecordsRead != 1)
return -1;
}
ch =(BYTE) nCode;
OutFile.Write(&ch, 1);
ch =(BYTE) (nSize/2);
OutFile.Write(&ch, 1);
if (nSize != 0)
OutFile.Write(Buffer, nSize);
break;
} // default
}
}
}
return 0;
}
460