Prod.: Engine, ver.: 6011, ID: 60000371, Wish : Exclude , Intersect and Xor combine operations between polylines

Wish : Exclude , Intersect and Xor combine operations between polylines

Article60000371
TypeWish
ProductEngine
Version6011
Date Added1/5/2008
FixedYes [3/4/2008]
Submitted byGeoff Murrey
Keywords

Subject

Exclude , Intersect and Xor combine operations between polylines

Summary

Exclude , Intersect  and Xor combine operations between polylines

Solution

In version 6012 a new method was added in vdPolyline object:

///Specifies how different clipping curves can be combined.
public enum CombineMode
{
      /// The input curve is excluded from this curve.
      Exclude = 0,
      /// Two clipping curves are combined by taking their intersection.
      Intersect = 1,
      /// Two clipping curves are combined by taking only the areas enclosed by one or the other curve, but not both.
      Xor = 2,
      /// Two clipping curves are combined by taking the union of both.
      Union = 3,
}
/// Create a combination between this polyline object and a vdCurve object.
/// <param name="curve">A vdCurve object with which the combination will be done.</param>
/// <param name="combineMode">The compination operation.</param>
/// <returns>A collection of vdCurves as a result of the combination.</returns>
public vdCurves Combine(vdCurve curve, CombineMode combineMode

Example:

gPoint pt;
vdFigure fig;
vdPolyline pl;
vdCurve curve;
VectorDraw.Actions.
StatusCode sc = VectorDraw.Actions.StatusCode.Other;

//Select the source polyline.
vdFramedControl.BaseControl.ActiveDocument.Prompt("select source pline object");
sc = vdFramedControl.BaseControl.ActiveDocument.ActionUtility.getUserEntity(
out fig, out pt);
vdFramedControl.BaseControl.ActiveDocument.Prompt(
null);
if (sc != VectorDraw.Actions.StatusCode.Success) return;
pl = fig
as vdPolyline;
if (pl == null) return;

//Select the Destination polyline.
vdFramedControl.BaseControl.ActiveDocument.Prompt("select destivation figure object");
sc = vdFramedControl.BaseControl.ActiveDocument.ActionUtility.getUserEntity(
out fig, out pt);
vdFramedControl.BaseControl.ActiveDocument.Prompt(
null);
if (sc != VectorDraw.Actions.StatusCode.Success) return;
curve = fig
as vdCurve;
if (curve == null) return;
//Ask the user which combine method he wants to perform.
vdFramedControl.BaseControl.ActiveDocument.ActionUtility.SetAcceptedStringValues(new string[] { "Exclude;e;E", "Intersect;i;I", "Xor;x;X", "Union;u;U" }, "Exclude");
vdFramedControl.BaseControl.ActiveDocument.Prompt(
"Compine mode <Exclude>/Intersect/Xor/Union:");
string compinestr = vdFramedControl.BaseControl.ActiveDocument.ActionUtility.getUserString();
vdFramedControl.BaseControl.ActiveDocument.Prompt(
null);
if (compinestr == null) return;
vdPolyline.CombineMode Usercombine = vdPolyline.CombineMode.Exclude;
switch (compinestr)
{
case "Exclude":
    Usercombine =
vdPolyline.CombineMode.Exclude;
    break;
case "Intersect":
    Usercombine =
vdPolyline.CombineMode.Intersect;
    break;
case "Xor":
    Usercombine =
vdPolyline.CombineMode.Xor;
    break;
case "Union":
    Usercombine =
vdPolyline.CombineMode.Union;
    break;
default:
    break;
}

//Combine the given polylines.
vdCurves curves = pl.Combine(curve, Usercombine);

//Add the curves to the document and give them a fill mode solid to see the difference better.
vdFramedControl.BaseControl.ActiveDocument.UndoHistory.StoreUndoGroup(true);
foreach (vdCurve var in curves)
{
var.SetUnRegisterDocument(vdFramedControl.BaseControl.ActiveDocument);
var.setDocumentDefaults();
IvdHatchFigure hfig = var as IvdHatchFigure;
if (hfig == null) continue;
hfig.HatchProperties =
new vdHatchProperties(VectorDraw.Professional.Constants.VdConstFill.VdFillModeSolid);
vdFramedControl.BaseControl.ActiveDocument.ActiveLayOut.Entities.AddItem(var);
var.Invalidate();
}
vdFramedControl.BaseControl.ActiveDocument.UndoHistory.StoreUndoGroup(
false);