home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip: Shareware for Win 95
/
Chip-Shareware-Win95.bin
/
grafika
/
cad
/
_setup.1
/
AUTOEX1.CPP
< prev
next >
Wrap
Text File
|
1996-11-18
|
18KB
|
530 lines
//----------------------------------------------------------------------------
// Example OLE Automation Controller for GammaCAD PRO
//
// Gamma Software
// August 1996
//
//
// This example uses the Borland C++ Object Components library version 5.
// The implementation for other compilers will be different. See your
// compilers documentation on creating OLE automation controllers. The
// GCADP.HXX file lists the automated classes and functions in GammaCAD.
//
//----------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include "gcadp.cxx"
#include "snap.h"
#include "ptype.h"
#include "numfmt.h"
#include "elemtype.h"
// loop thru current element selection in GammaCAD
void GetCurrSelection(GcadOleView& cmd)
{
long id = cmd.CurrSelGetFirst(); // get first element in selection
while(id)
{
id = cmd.CurrSelGetNext(); // get next element
}
}
// prompt user to select a drawing element in GammaCAD
bool GetElement(const char *prompt,GcadOleView& cmd,unsigned long *elemId)
{
cmd.SelectOne(); // put GammaCAD in select one mode
if(prompt) // set the prompt line
cmd.SetPrompt(prompt);
MSG msg;
while(!cmd.IsPgmSelDone()) // loop until user makes selection
{
if (::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
*elemId = cmd.IsPgmSelDone(); // get id of selected element
if(*elemId <= 0)
exit(0); // user has selected another command
return true;
}
// prompt user to select a point in GammaCAD
bool GetPoint(const char *prompt,GcadOleView& cmd,double *x,double *y)
{
cmd.GetPoint(); // put GammaCAD in point input mode
if(prompt) // set the prompt line
cmd.SetPrompt(prompt);
MSG msg;
while(!cmd.IsPointSelDone(x,y)) // loop until a point is input
{
if (::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
// get point entered
int status = cmd.IsPointSelDone(x,y);
if(status <= 0)
exit(0); // user has selected another command
return true;
}
// select all elements in drawing
bool SelectAll(GcadOleView& cmd)
{
unsigned long elemId = cmd.DwgGetFirst();
while(elemId)
{
cmd.AddToSel(elemId);
elemId = cmd.DwgGetNext();
}
}
int PASCAL
WinMain(HINSTANCE /*hInst*/, HINSTANCE/*prev*/, char far* /*cmdLine*/, int/*show*/)
{
char buf[256]; // text buffer
unsigned long elemId; // drawing element id
try {
TOleAllocator oleMem(0); // required to initialize OLE memory allocation
bool bound = false; // Bind to currently running server
TGcadApp gcad;
char *pszServerProgID = "GammaCAD.Application.3";
CLSID clsid;
HRESULT hr = CLSIDFromProgID(OleStr(pszServerProgID),&clsid);
if(hr==S_OK)
{
LPUNKNOWN lpUnk = 0;
if(GetActiveObject(clsid,0,&lpUnk)==S_OK)
{
LPDISPATCH lpDisp = 0;
if(lpUnk->QueryInterface(IID_IDispatch,(LPVOID FAR*)&lpDisp)==S_OK)
{
lpUnk->Release();
gcad.Bind(lpDisp);
bound = true;
}
else
lpUnk->Release();
}
}
if(!bound) // Bind to new server
gcad.Bind(pszServerProgID);
gcad.SetVisible(true);
// App file commands
::MessageBox(0, gcad.GetName(), "Name", MB_OK);
::MessageBox(0, gcad.GetFullName(), "Path", MB_OK);
gcad.NewDocument();
gcad.OpenDocument("test.gc1");
::MessageBox(0, "Open file", "Open", MB_OK);
gcad.SaveDocumentAs("actest1.gc1");
gcad.SaveDocument();
gcad.LoadSymbolLib("trees");
GcadOleView cmd; // get the view class
gcad.GetView(cmd);
TAutoString layer = cmd.GetFirstLayer();
while((const char *)layer)
{
::MessageBox(0,layer,"LAYER",MB_OK);
layer = cmd.GetNextLayer();
}
// device window
long lxmin,lymin,lxmax,lymax;
cmd.GetDeviceWindow(&lxmin,&lymin,&lxmax,&lymax);
sprintf(buf,"min(%ld,%ld) max(%ld,%ld)",lxmin,lymin,lxmax,lymax);
::MessageBox(0,buf,"Device Window",MB_OK);
// world window
double wxmin,wymin,wxmax,wymax;
cmd.GetWorldWindow(&wxmin,&wymin,&wxmax,&wymax);
sprintf(buf,"min(%lf,%lf) max(%lf,%lf)",wxmin,wymin,wxmax,wymax);
::MessageBox(0,buf,"World Window",MB_OK);
// View file commands
cmd.SetPlotScale(2.,1);
cmd.SetPlotOrigin(2.,3.);
cmd.DxfIn("test1.dxf");
SelectAll(cmd); // erase and set view window
cmd.DelSel();
cmd.ZoomWin(-0.1,-0.1,8.6,11.1);
// draw commands
cmd.CreateLine(1.,1.,3.,1.);
cmd.CreateArc(2.,1.,3.,1.,1.,1.);
cmd.CreateCircle(2.,3.,1.);
cmd.CreatePoint(2.,7.);
cmd.CreateText(1.,8.,"Test String");
cmd.CreateEllipse(2.,5.,2.,5.5,1.,5.);
cmd.CopyBmp(0.,0.,8.,10.);
cmd.CreateSymbol(1.,8.,"..\\symbols\\tree1.sym",0.,1.,1.);
cmd.CreateLeader(5.1,7.1,7.,8.,"Click here");
cmd.CreateLinearDim(4.,2.,7.,2.,4.,3.,3.,0.,"3.0");
cmd.StartPline(4.,4.,1);
cmd.AddPlineVertex(6.,4.);
cmd.AddPlineVertex(6.,5.);
cmd.EndPline();
long elemPline = cmd.GetLastElem();
cmd.CreateFill(elemPline);
cmd.CreateRect(4.,8.,5.,7.);
if(GetElement("Select element to fill",cmd,&elemId))
cmd.CreateFill(elemId);
cmd.CreateBmp("..\\symbols\\tree1.bmp",10.,10.,9.,9.,0);
// get element parm's
LineElem line;
ArcElem arc;
CircleElem circle;
PointElem point;
TextElem text;
InsertElem insert;
PlineElem pline;
FillElem fill;
BmpElem bmp;
double x1,y1,x2,y2;
long color;
double size;
double sang,eang,rad;
bool flag;
elemId = cmd.DwgGetFirst();
for(int cnt=0;cnt<5;++cnt)
{
if(!elemId)
break;
ostrstream os(buf,sizeof(buf));
int type = cmd.GetElemType(elemId);
switch(type)
{
case TYPE_LINE:
cmd.GetLineElem(line,elemId);
line.GetFirstPoint(&x1,&y1);
line.GetSecondPoint(&x2,&y2);
color = line.GetColor();
type = line.GetType();
size = line.GetWidth();
os << x1 << endl << y1 << endl << x2 << endl << y2 << endl << color << endl << type << endl << size << endl << ends;
::MessageBox(0,buf,"Line",MB_OK);
break;
case TYPE_ARC:
cmd.GetArcElem(arc,elemId);
arc.GetCenterPoint(&x1,&y1);
sang = arc.GetStartAngle();
eang = arc.GetEndAngle();
rad = arc.GetRadius();
color = arc.GetColor();
type = arc.GetType();
size = arc.GetWidth();
os << x1 << endl << y1 << endl << sang << endl << eang << endl << rad << endl << color << endl << type << endl << size << endl << ends;
::MessageBox(0,buf,"Arc",MB_OK);
break;
case TYPE_CIRCLE:
cmd.GetCircleElem(circle,elemId);
circle.GetCenterPoint(&x1,&y1);
rad = circle.GetRadius();
color = circle.GetColor();
type = circle.GetType();
size = circle.GetWidth();
os << x1 << endl << y1 << endl << rad << endl << color << endl << type << endl << size << endl << ends;
::MessageBox(0,buf,"Circle",MB_OK);
break;
case TYPE_POINT:
cmd.GetPointElem(point,elemId);
point.GetPoint(&x1,&y1);
color = point.GetColor();
type = point.GetType();
size = point.GetSize();
os << x1 << endl << y1 << endl << color << endl << type << endl << size << endl << ends;
::MessageBox(0,buf,"Point",MB_OK);
break;
case TYPE_TEXT:
cmd.GetTextElem(text,elemId);
text.GetAlignPoint(&x1,&y1);
color = text.GetColor();
size = text.GetHeight();
sang = text.GetAngle();
eang = text.GetOrient();
rad = text.GetWidth();
type = text.GetJust();
os << x1 << endl << y1 << endl << color << endl << size << endl << sang << endl << eang << endl << rad << endl << type << endl << text.GetString() << endl << ends;
::MessageBox(0,buf,"Text",MB_OK);
break;
case TYPE_INSERT:
cmd.GetInsertElem(insert,elemId);
insert.GetInsertPoint(&x1,&y1);
sang = insert.GetRotation();
insert.GetScale(&x1,&y1);
os << insert.GetName() << endl << sang << endl << x1 << endl << y1 << endl << ends;
::MessageBox(0,buf,"Insert",MB_OK);
break;
case TYPE_PLINE:
cmd.GetPlineElem(pline,elemId);
color = pline.GetColor();
type = pline.GetType();
size = pline.GetWidth();
flag = pline.GetClosed();
os << color << endl << type << endl << size << endl << flag << endl << ends;
::MessageBox(0,buf,"Pline",MB_OK);
pline.GetFirstVertex(&x1,&y1);
do {
os.seekp(0,ostream::beg);
os << x1 << endl << y1 << endl << ends;
::MessageBox(0,buf,"Pline",MB_OK);
} while(pline.GetNextVertex(&x1,&y1));
break;
case TYPE_FILL:
cmd.GetFillElem(fill,elemId);
color = fill.GetColor();
type = fill.GetType();
os << color << endl << type << endl << ends;
::MessageBox(0,buf,"Fill",MB_OK);
fill.GetFirstVertex(&x1,&y1);
do {
os.seekp(0,ostream::beg);
os << x1 << endl << y1 << endl << ends;
::MessageBox(0,buf,"Fill",MB_OK);
} while(fill.GetNextVertex(&x1,&y1));
break;
case TYPE_BMP:
cmd.GetBmpElem(bmp,elemId);
bmp.GetFirstPoint(&x1,&y1);
bmp.GetSecondPoint(&x2,&y2);
flag = bmp.GetScale();
os << x1 << endl << y1 << endl << x2 << endl << y2 << endl << flag << endl << ends;
::MessageBox(0,buf,"Bitmap",MB_OK);
break;
default:
break;
}
elemId = cmd.DwgGetNext();
}
cmd.ClearPgmSel();
// position input
double x,y;
if(GetPoint("Enter a point",cmd,&x,&y))
{
sprintf(buf,"(%lf,%lf)",x,y);
::MessageBox(0, buf, "Input", MB_OK);
}
// edit commands
SelectAll(cmd);
cmd.DelSel();
cmd.CreateLine(1.,1.,2.,1.);
cmd.CreateLine(2.,1.,2.,2.);
cmd.CreateLine(2.,2.,1.,2.);
cmd.CreateLine(1.,2.,1.,1.);
cmd.Undo();
SelectAll(cmd);
::MessageBox(0, "All elements selected", "Edit", MB_OK);
cmd.RemoveFromSel(cmd.DwgGetFirst());
::MessageBox(0, "One element removed", "Edit", MB_OK);
cmd.ClearSel();
::MessageBox(0, "Selection cleared", "Edit", MB_OK);
elemId = cmd.DwgGetFirst();
while(elemId)
{
cmd.AddToSel(elemId);
elemId = cmd.DwgGetNext();
}
elemId = cmd.CurrSelGetFirst();
while(elemId)
{
sprintf(buf,"element %ld",elemId);
::MessageBox(0, buf, "Edit", MB_OK);
elemId = cmd.CurrSelGetNext();
}
cmd.MoveSel(1.,1.,2.,2.);
::MessageBox(0, "Selection moved", "Edit", MB_OK);
cmd.CopySel(1.,1.,3.,2.);
::MessageBox(0, "Selection copied", "Edit", MB_OK);
cmd.RotateSel(5.,5.,20.);
::MessageBox(0, "Selection rotated", "Edit", MB_OK);
cmd.ScaleSel(5.,5.,0.5,1.);
::MessageBox(0, "Selection scaled", "Edit", MB_OK);
cmd.MirrorSel(0.,2.,5.,2.,1);
::MessageBox(0, "Selection mirrored", "Edit", MB_OK);
cmd.AdjustSel(0.,0.,1.,1.,1.,1.,2.,2.);
::MessageBox(0, "Selection adjusted", "Edit", MB_OK);
cmd.DelSel();
::MessageBox(0, "Selection deleted", "Edit", MB_OK);
cmd.CreateLine(1.,1.,2.,1.);
elemId = cmd.GetLastElem();
cmd.AddToSel(elemId);
cmd.ChangeLineColor(255L);
cmd.ChangeLineType(PS_DOT);
cmd.ChangeLineWidth(0.3);
cmd.ClearSel();
::MessageBox(0, "Line properties changed", "Edit", MB_OK);
cmd.CreatePoint(1.,2.);
elemId = cmd.GetLastElem();
cmd.AddToSel(elemId);
cmd.ChangePointColor(255L);
cmd.ChangePointType(PT_BOX);
cmd.ChangePointSize(0.3);
cmd.ClearSel();
::MessageBox(0, "Point properties changed", "Edit", MB_OK);
cmd.CreateText(1.,3.,"Test String");
elemId = cmd.GetLastElem();
cmd.AddToSel(elemId);
cmd.ChangeTextFont("Arial",FW_BOLD,255L,1,1,1);
::MessageBox(0, "Text font changed", "Edit", MB_OK);
cmd.ChangeTextHgt(0.3);
cmd.ChangeTextWidth(2.);
cmd.ChangeTextAngle(20.);
cmd.ChangeTextOrient(180.);
cmd.ChangeTextJust(TA_RIGHT | TA_BOTTOM);
::MessageBox(0, "Text properties changed", "Edit", MB_OK);
cmd.CreateRect(1.,4.,2.,5.);
elemId = cmd.GetLastElem();
cmd.CreateFill(elemId);
elemId = cmd.GetLastElem();
cmd.AddToSel(elemId);
cmd.ChangeFillColor(255L);
cmd.ChangeFillType(HS_DIAGCROSS);
cmd.ClearSel();
::MessageBox(0, "Fill properties changed", "Edit", MB_OK);
cmd.AddLayer("layer1");
cmd.ChangeLayer("layer1");
SelectAll(cmd);
cmd.DelSel();
cmd.CreateLine(1.,1.,3.,1.);
long elem = cmd.GetLastElem();
cmd.BreakEnd(elem,3.,1.,2.5,1.);
::MessageBox(0, "break end", "Edit", MB_OK);
cmd.BreakMiddle(elem,1.5,1.,2.,1.);
::MessageBox(0, "break middle", "Edit", MB_OK);
cmd.CreateLine(1.2,3.,1.2,2.);
long elem2 = cmd.GetLastElem();
cmd.Extend(elem,elem2,1.2,2.);
::MessageBox(0, "extend", "Edit", MB_OK);
cmd.SetFilletParms((int)'r',.2);
cmd.Fillet(elem,elem2,1.2,1.,1.2,1.);
::MessageBox(0, "fillet", "Edit", MB_OK);
cmd.StartPline(7.,7.,1);
cmd.AddPlineVertex(6.,6.);
cmd.AddPlineVertex(7.,6.);
cmd.EndPline();
elemId = cmd.GetLastElem();
cmd.OpenClosePline(elemId);
::MessageBox(0, "closed pline", "Edit", MB_OK);
cmd.Offset(elemId,0.2);
::MessageBox(0, "offset pline", "Edit", MB_OK);
cmd.Explode(elemId);
::MessageBox(0, "exploded pline", "Edit", MB_OK);
cmd.CreateText(3.,3.,"String one");
cmd.ChangeText(cmd.GetLastElem(),"String two");
::MessageBox(0, "text changed", "Edit", MB_OK);
cmd.RedefSym("..\\symbols\\tree1.sym");
// view commands
cmd.ZoomWin(1.,1.,3.,3.);
::MessageBox(0, "zoom window", "View", MB_OK);
cmd.ZoomExt();
::MessageBox(0, "zoom extents", "View", MB_OK);
cmd.ZoomPrev();
::MessageBox(0, "zoom previous", "View", MB_OK);
cmd.ZoomFactor(.5);
::MessageBox(0, "zoom factor", "View", MB_OK);
cmd.ZoomPage();
::MessageBox(0, "zoom page", "View", MB_OK);
cmd.ZoomPrev();
cmd.ZoomPageExt();
::MessageBox(0, "zoom page&ext", "View", MB_OK);
cmd.Pan(3.,1.);
::MessageBox(0, "pan", "View", MB_OK);
cmd.Redraw();
::MessageBox(0, "redraw", "View", MB_OK);
// snap modes
cmd.SetSnapMode(CM_SNAPGRID);
::MessageBox(0, "snap grid", "Snap", MB_OK);
cmd.SetSnapMode(CM_SNAPMIDPT);
::MessageBox(0, "snap midpt", "Snap", MB_OK);
cmd.SetSnapMode(CM_SNAPEND);
::MessageBox(0, "snap end", "Snap", MB_OK);
cmd.SetSnapMode(CM_SNAPCENTER);
::MessageBox(0, "snap center", "Snap", MB_OK);
cmd.SetSnapMode(CM_SNAPPOINT);
::MessageBox(0, "snap point", "Snap", MB_OK);
cmd.SetSnapMode(CM_SNAPNEAREST);
::MessageBox(0, "snap nearest", "Snap", MB_OK);
cmd.SetSnapMode(CM_SNAPINTX);
::MessageBox(0, "snap intx", "Snap", MB_OK);
cmd.SetSnapMode(CM_SNAPTANGENT);
::MessageBox(0, "snap tan", "Snap", MB_OK);
cmd.SetSnapMode(CM_SNAPPERP);
::MessageBox(0, "snap perp", "Snap", MB_OK);
cmd.SetSnapMode(CM_SNAPNONE);
::MessageBox(0, "snap none", "Snap", MB_OK);
// properties
cmd.SetLineColor(255L);
cmd.SetLineType(PS_DOT);
cmd.SetLineWidth(0.3);
cmd.SetPointColor(255L);
cmd.SetPointType(PT_BOX);
cmd.SetPointSize(0.3);
cmd.SetTextFont("Arial",1.,FW_BOLD,255L,1,1,1);
cmd.SetTextHgt(0.3);
cmd.SetTextWidth(2.);
cmd.SetTextAngle(20.);
cmd.SetTextOrient(180.);
cmd.SetTextJust(TA_RIGHT | TA_BOTTOM);
cmd.SetFillColor(255L);
cmd.SetFillType(HS_DIAGCROSS);
cmd.SetDimArrowScale(2.);
cmd.SetDimOffset(1.);
cmd.AddLayer("layer1");
cmd.SetLayerLock("layer1",1);
cmd.SetLayerPrint("layer1",0);
cmd.SetLayerOn("layer1",0);
cmd.AddLayer("test");
cmd.SetCurrentLayer("test");
::MessageBox(0, "properties set", "Properties", MB_OK);
cmd.RenameLayer("test","layer2");
::MessageBox(0, "layer renamed", "Properties", MB_OK);
cmd.SetCurrentLayer("layer1");
::MessageBox(0, "layer changed", "Properties", MB_OK);
cmd.SetBasePt(1.,1.);
cmd.SetGridParms(1.,1.,.2,.2,1);
cmd.SetNumFmt(NF_ARCH,0,8,'.');
::MessageBox(0, "architectural units", "Properties", MB_OK);
cmd.SetNumFmt(NF_SCI,3,8,',');
::MessageBox(0, "scientific units", "Properties", MB_OK);
cmd.SetNumFmt(NF_DEC,4,8,'x');
::MessageBox(0, "decimal units", "Properties", MB_OK);
cmd.SetDispPage(0);
cmd.SetDispDxf(0);
double xmin,ymin,xmax,ymax;
cmd.GetExtents(&xmin,&ymin,&xmax,&ymax);
sprintf(buf,"(%lf,%lf)(%lf,%lf)",xmin,ymin,xmax,ymax);
::MessageBox(0, buf, "Extents", MB_OK);
// end of test
gcad.Quit();
::CoFreeUnusedLibraries();
}
catch (TXBase& x) {
::MessageBox(0, x.why().c_str(), "OLE Exception", MB_OK);
}
return 0;
}