home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1998 November
/
pcwk_11_98a.iso
/
Wtestowe
/
SOFTSRC
/
vtrial15.exe
/
DATA.1
/
VdrawX.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1997-02-08
|
3KB
|
88 lines
/*
Sample Vdraft C++ code
(C) Copyright 1997 by SoftSource. All rights reserved.
Scott Sherman 2-97
This example demonstrates the basics of writing a Vdraft Plug-in.
If this dll is placed in Vdraft\Programs it will automatically
be loaded when Vdraft first starts.
All plug-ins must at least export vfLoad. This function is called
by Vdraft when the plug-in is first loaded.
In this example, vfLoad adds a menu item to Vdraft's Tools menu.
When the user selects it, vfCommand is called. This plug-in then
starts the user drawing a line and requests to be notified upon completion.
When the user finishes drawing, vfDrawEvent is called. This plug-in
then retrieves the new line and creates another line based on it
to draw an X on the drawing.
Note: DrawX.def lists all the exported functions so Vdraft can call them.
*/
#include "stdafx.h"
#include "Vdraft.h"
// the Vdraft application object we use for communications to Vdraft
static IVdraft vdraft;
#define MYMENUITEM 1
// all plug-ins must export vfLoad
veReturn vfLoad(vtAddOnID id)
{
if (!vdraft.CreateDispatch("Vdraft.Application", NULL))
return veR_Unload;
// add "My Menu Item" to Vdraft's Tools menu
CString item("My Menu Item"),
status("A simple Vdraft add-on");
IApplicationEvents events(vdraft.GetEvents());
events.AddToolsCommand(id,MYMENUITEM,item,status);
return veR_OK;
}
// vfCommand is called when our menu items are chosen by the user
veReturn vfCommand(vtAddOnID id, long eventid)
{
if (eventid != MYMENUITEM)
return veR_OK;
IDocument doc(vdraft.GetActiveDocument());
// have them draw a line
IEntities entities(doc.GetEntities());
entities.DrawLine();
// ask to be notified when they're done
IPickEvents pick(doc.GetPickEvents());
pick.RequestDraw(id,cVariant());
return veR_OK;
}
// vfDrawEvent is called when the user picks a point, finishes or cancels drawing.
// Vdraft starts calling it when the plug-in requests these events using RequestDraw.
// Once the user finishes or cancels drawing, this function is no longer called.
veReturn vfDrawEvent(vtAddOnID id, veDrawEvent event, double* point, short picknumber, long info)
{
if (event != veDE_Done)
return veR_OK;
IDocument doc(vdraft.GetActiveDocument());
IEntities entities(doc.GetEntities());
// get the line they just drew - it will be the last entity
ILine line(entities.GetLast());
// get the endpoints of the line
IVector end1(line.GetWhere1()),
end2(line.GetWhere2());
// create a new line
ILine newline(entities.AddLine());
// get the endpoints of the new line
IVector newend1(newline.GetWhere1()),
newend2(newline.GetWhere2());
// use the 1st line to position the 2nd line so we form an X
newend1.Set3D(end1.GetX(), end2.GetY(), end1.GetZ());
newend2.Set3D(end2.GetX(), end1.GetY(), end2.GetZ());
return veR_OK;
}