home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1998 November
/
pcwk_11_98a.iso
/
Wtestowe
/
SOFTSRC
/
vtrial15.exe
/
DATA.1
/
Vangular.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1997-02-10
|
4KB
|
158 lines
/*
Sample Vdraft C++ code - Vangular.cpp
(C) Copyright 1997 by SoftSource. All rights reserved.
Scott Sherman 2-97
This code demonstrates how to...
1) add an item to Vdraft's pulldown menu and respond when it's chosen
2) have the user select objects and respond when they're done
3) work with the selection set
4) start the user drawing something and pick several points for them
It prompts the user to select 2 lines,
then starts a 4 point angular dimension using the endpoints of the lines.
*/
#include "stdafx.h"
#include "Vdraft.h"
static IVdraft vdraft;
CString status1("Select first line for angular dimension"),
status2("Select second line for angular dimension");
class cSelectLine : public cSelectEvent
{
public:
cSelectLine(IVdraft& vdraft, vtAddOnID id, CString& status)
: cSelectEvent(vdraft,id), m_doc(vdraft.GetActiveDocument())
{
// prompt them to select a line & ask to be notified when they're done
CString name("Select Line");
ISelectionEvents select(m_doc.GetSelectionEvents());
select.SetName(name);
select.SetStatusbar(status);
select.RequestSingleSelect(id,cVariant(this));
}
protected:
// check to see if the user picked a line
BOOL didUserPickLine()
{
ISelection selection(m_doc.GetSelection());
if (selection.GetCount() < this->pickNumber())
return FALSE; // nothing picked - try again
// check if the selected entity is a line
IEntity entity(selection.GetItem(cVariant(this->pickNumber())));
if (entity.GetType() != veET_Line)
return FALSE; // they didn't pick a line - try again
return TRUE;
}
// if they picked something other than a line, we want to undo their pick
void undoSelect()
{
ICommands commands(m_doc.GetCommands());
commands.Undo(cVariant());
}
virtual int pickNumber() = 0;
IDocument m_doc;
};
class cSelect2 : public cSelectLine
{
public:
cSelect2(IVdraft& vdraft, vtAddOnID id) : cSelectLine(vdraft,id,status2)
{
}
virtual void Done()
{
if (didUserPickLine())
{
// get the lines they just picked
ISelection selection(m_doc.GetSelection());
ILine line1(selection.GetItem(cVariant(1))),
line2(selection.GetItem(cVariant(2)));
selection.RemoveAll(); // deselect the lines
// get endpoints of lines
IVector start1(line1.GetWhere1()),
end1(line1.GetWhere2()),
start2(line2.GetWhere1()),
end2(line2.GetWhere2());
// start them drawing a 4 point angular dimension
IEntities entities(m_doc.GetEntities());
entities.Draw4PointAngularDim(cVariant());
// feed in the line endpoints as point picks
IPickEvents pick(m_doc.GetPickEvents());
pick.TriggerPick(start1);
pick.TriggerPick(end1);
pick.TriggerPick(start2);
pick.TriggerPick(end2);
}
else
{ // they didn't pick a line - try again
undoSelect();
new cSelect2(getVdraft(),getAddOnID()); // got 1st line - get 2nd line
}
}
protected:
virtual int pickNumber() { return 2; }
};
class cSelect1 : public cSelectLine
{
public:
cSelect1(IVdraft& vdraft, vtAddOnID id) : cSelectLine(vdraft,id,status1)
{
}
virtual void Done()
{
if (didUserPickLine())
// got 1st line - get 2nd line
new cSelect2(getVdraft(),getAddOnID());
else
{ // they didn't pick a line - try again
undoSelect();
new cSelect1(getVdraft(),getAddOnID());
}
}
protected:
virtual int pickNumber() { return 1; }
};
veReturn vfCommand(vtAddOnID id, long eventid)
{
if (eventid != 1)
return veR_OK;
IDocument doc(vdraft.GetActiveDocument());
// deselect everything - we want the 2 entities they're about to select
ISelection set(doc.GetSelection());
set.RemoveAll();
// prompt them for the 1st line
new cSelect1(vdraft,id);
return veR_OK;
}
// add a menu item to Vdraft
veReturn vfLoad(vtAddOnID id)
{
if (!vdraft.CreateDispatch("Vdraft.Application", NULL))
return veR_Unload;
CString item("&Dimension 2 Lines"),
status("Draw an angular dimension using two lines");
IApplicationEvents events(vdraft.GetEvents());
events.AddToolsCommand(id,1,item,status);
CString keys("n");
events.AddKeyboardCommand(id,1,keys);
return veR_OK;
}